Subject Re: [firebird-support] Re: How to update table structure with SQL?
Author Dennis McFall
At 09:12 AM 6/23/2009, Doug Chamberlin wrote:
>Emil Totev wrote:
> > Firebird has the "CREATE OR ALTER" syntax for changes to tables
> that might be missing.
> > You can also get information about the existing fields from the
> system tables and act accordingly.
>
>As Emil has mentioned, Firebird has a way to detect whether a table
>exists - just query the system tables using standard SQL. These can also
>be used to detect existing fields in tables.


Not that you need me to tell you how to do this, but this is the code I use:


...........
SQL.Clear;
SQL.Add( 'SELECT 1 FROM RDB$DATABASE WHERE EXISTS(SELECT
RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$RELATION_NAME=''SOMETABLE') ');
First;
if Fields[0].AsInteger = 1 then begin
iDummy:=1;
end else with qMisc do begin
SQL.Clear;
SQL.Add('CREATE TABLE SOMETABLE(ST_OID INTEGER,
STPAYMENT_OID INTEGER, STSESSION VARCHAR(50), STSTATUS INTEGER)');
ExecSQL;
end;
...........

./dm