Check if Table exists

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Check if Table exists

Post by bart57 »

Hi,

How can I easily check if a Table exists ? (No Select and No TZTable.open + exception) ?


thx
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

TZConnection have a GetTableNames function, which returns the name of all tables.. try it :)
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

At least two ways:

Execute a query "Show Tables like "teblename%" and see if there's your table.

Use ZSQLMetadata component to do it.
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

Thank you,

it works fine :-)
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

Hi Zippo,

how does it work with ZSQLMetadata, have you an example please?


thx
Terence
Zeos Dev Team
Zeos Dev Team
Posts: 141
Joined: 22.09.2005, 14:11
Location: Stuttgart
Contact:

Post by Terence »

Var List:TStringList;
List:= TStringList.Create;
Connection.GetTableNames('tablename%',string; List);
......
List.Free;
fabian
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

I know how it works with GetTableNames but I ask how it works with ZSQLMetadata
Terence
Zeos Dev Team
Zeos Dev Team
Posts: 141
Joined: 22.09.2005, 14:11
Location: Stuttgart
Contact:

Post by Terence »

GetTableNames is implemented in/as ZSqlMetaData
fabian
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

thx but GetTableNames give me all the tables back !
I just want the tables from one shema !
Terence
Zeos Dev Team
Zeos Dev Team
Posts: 141
Joined: 22.09.2005, 14:11
Location: Stuttgart
Contact:

Post by Terence »

That is there is a filter param for that method, check
Connection.GetTableNames('shema%',List);
fabian
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

thx,

I have a problem: the name of my shema is BISS, I try

zConnection1.GetTableNames('BISS%',List);

but it doesn't work :-(
Terence
Zeos Dev Team
Zeos Dev Team
Posts: 141
Joined: 22.09.2005, 14:11
Location: Stuttgart
Contact:

Post by Terence »

Then apply my patch on Testing branch,compile zeos and call
ZConnection.GetTableNames('BISS','',List);
afterwards.

If it works for you, i will commit.
fabian
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

thx a lot Terence ,

It works great with your modified Procedure! :)
Terence
Zeos Dev Team
Zeos Dev Team
Posts: 141
Joined: 22.09.2005, 14:11
Location: Stuttgart
Contact:

Post by Terence »

which databse did you use - i need the info just for commit statment.
fabian
bart57
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 18.07.2006, 14:40

Post by bart57 »

I use Oracle 10g
Post Reply