Page 1 of 1

How to find all table name in my database ?

Posted: 17.09.2008, 20:16
by dav999
Hello,

In start of my app i want find all table name in my database, i use this code but i can't use the result :

Code: Select all

sql_query.SQL.Clear;
sql_query.sql.Add('SELECT name, sql FROM sqlite_master WHERE type=''table'' ORDER BY name;');
sql_query.ExecSQL;

ShowMessage('Name = ' + sql_query.Fields.Fields[0].Text);
with this code i have a error sql_query "list index out of bounce"

can anyone help me ?

Ubuntu 8.04 + lazarus 0.9.24 + FPC 2.2.0 + zeoslib 6.6.3 + sqlite3 3.6.2

Thanks
David

Posted: 17.09.2008, 20:32
by mdaems
Basic solution : use sql_query.Open.

But somebody else might have done the job before : If you just need the table names there are some TZConnection utility procedures :

Code: Select all

    procedure GetTableNames(const Pattern: string; List: TStrings);overload;
    procedure GetTableNames(const tablePattern,schemaPattern: string; List: TStrings);overload;
    procedure GetTableNames(const tablePattern,schemaPattern: string; Types: TStringDynArray; List: TStrings);overload;

To get everything : just feed an empty string (or '%') to the pattern parameters.

Mark

Posted: 17.09.2008, 21:51
by dav999
yeh, a simple response, i love this :)

thanks
David

Ansewer

Posted: 28.09.2009, 12:05
by bangfauzan
also u can use GetTableNames() function in ZConnection component