[fpc-pascal] Is there a way to create a Firebird embedded database programmatically?
Reinier Olislagers
reinierolislagers at gmail.com
Wed Aug 3 11:18:58 CEST 2011
On 3-8-2011 9:48, Tony Whyman wrote:
> Reiner,
>
> You can certainly do this with IBX for Lazarus
> (http://www.mwasoftware.co.uk). You will also find there some guidelines
> on using the Firebird embedded library under both Windows and Linux that
> are more general than just IBX.
>
> If you want to stick with SQLDB then there is a global variable
> UseEmbeddedFirebird that you need to set to force use of the embedded
> library.
>
Thanks for the suggestion, Tony. I did download and install IBX, but
then I found bug report
http://bugs.freepascal.org/view.php?id=13340
with sample code for regular sqldb.
Adapted this code*:
(*Note: if you don't specify UseEmbeddedFirebird, you can rename
fbembed.dll to fbclient.dll and get the same results - I'd wish somebody
would implement the provided fix in issue
http://bugs.freepascal.org/view.php?id=17664)
//requires ibase60dyn in uses:
UseEmbeddedFirebird:=true;
IBConnection1.HostName := '';
IBConnection1.DatabaseName := DatabaseFile; //
IBConnection1.Username := 'SYSDBA';
IBConnection1.Password := 'masterkey';
IBConnection1.Charset := 'UTF8';
IBConnection1.Dialect := 3;
DBParams:=TStringList.Create;
try
DBParams.Add('PAGE_SIZE=16384');
IBConnection1.Params := DBParams;
finally
DBParams.Free;
end;
if (FileExists(DatabaseFile)=false) then
begin
SQLTransaction1.Active:=false;
IBConnection1.Transaction:=SQLTransaction1;
IBConnection1.CreateDB; //Create the database file.
IBConnection1.Open;
SQLTransaction1.StartTransaction;
IBConnection1.ExecuteDirect('CREATE TABLE Table1 (id VARCHAR(255),
name VARCHAR(255));');
SQLTransaction1.Commit;
IBConnection1.Close;
end;
//Finally switch on connection
IBConnection1.Connected := True;
IBConnection1.KeepConnection := True;
More information about the fpc-pascal
mailing list