Smarter way to run queries?
Posted: 31.05.2009, 00:14
Hello
I'm reading "The Firebird Book" and am trying to build a very basic Delphi application to connect to a Firebird server.
I was wondering: Is there a smarter, easier way to run queries like this?
Thank you.
I'm reading "The Firebird Book" and am trying to build a very basic Delphi application to connect to a Firebird server.
I was wondering: Is there a smarter, easier way to run queries like this?
Code: Select all
With ZQuery1 do begin
Connection := ZConnection1;
Sql.Clear;
//How to check if a table already exists?
Sql.Text := 'CREATE TABLE mytable (id SMALLINT NOT NULL, name VARCHAR(20), primary key (id))';
ExecSql;
Sql.Text := 'CREATE GENERATOR gen_t1_id';
ExecSql;
Sql.Text := 'SET GENERATOR gen_t1_id TO 0';
ExecSql;
Sql.Text := 'set term !!';
ExecSql;
Sql.Text := 'CREATE TRIGGER T1_BI FOR mytable ACTIVE BEFORE INSERT POSITION 0 AS BEGIN if (NEW.id is NULL) then NEW.id = GEN_ID(GEN_T1_ID, 1); END!!';
ExecSql;
Sql.Text := 'set term !!';
ExecSql;
Sql.Clear;
Sql.Add('INSERT INTO mytable (name) VALUES (:Val1)');
Params.ParamByName('Val1').AsString := 'John Doe';
ExecSql;
Sql.Clear;
Sql.Add('SELECT * FROM mytable');
//BAD for SELECT
//ExecSql;
Open;
end;