----- Original Message -----
From: <comesailing@...>
To: <IBObjects@yahoogroups.com>
Sent: Friday, August 03, 2001 2:18 PM
Subject: [IBO] Tables and their existance
> Silly question.
> What is the best way (in a program using ib_connection) of finding
> whether a table exists and if so whether it is empty ?
> I do it by trying to read a record and if the table does not exist or
> is empty then of course there is an error. But this is clumsy, I
> would rather do a test of each.
You can use this code:
function TableExists(IBConnection:TIB_Connection; TableName:String):boolean;
var Q:TIB_Query;
begin
Result:=False;
if not Assigned(IBConnection) then raise Exception.Create('IB connection
are not assigned!');
Q:=TIB_Query.Create(nil);
try
Q.IB_Connection:=IBConnection;
with Q do
begin
close; sql.clear;
sql.add('select * from RDB$RELATIONS where
RDB$RELATION_NAME=?TableName');
Prepare;
ParamValues['TableName']:=TableName;
Open;
Result:=not IsEmpty;
close;
end;
finally
Q.Free;
end;
end;