How to find all table name in my database ?

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
dav999
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 29.08.2008, 07:58

How to find all table name in my database ?

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
dav999
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 29.08.2008, 07:58

Post by dav999 »

yeh, a simple response, i love this :)

thanks
David
bangfauzan
Senior Boarder
Senior Boarder
Posts: 50
Joined: 31.08.2006, 10:41
Contact:

Ansewer

Post by bangfauzan »

also u can use GetTableNames() function in ZConnection component
Post Reply