[fpc-pascal] Is there a way to create a Firebird embedded database programmatically?
Tony Whyman
tony.whyman at mccallumwhyman.com
Wed Aug 3 09:48:25 CEST 2011
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.
On 03/08/11 06:39, Reinier Olislagers wrote:
> When using the Firebird embedded database, it's nice to be able to
> create the database using only FreePascal/Lazarus.
>
> Is there a way to do this, e.g. using the SQLScript component, using
> something like this:
> const
> DatabaseFile = 'DATABASE1.FDB';
> var
> CreateScript: TSQLScript;
> ScriptText: TStringList;
> begin
> //Connection to Firebird database
> IBConnection1.HostName := ''; //must be empty for embedded Firebird;
> must be filled for client/server Firebird
> IBConnection1.DatabaseName := DatabaseFile; //Filename of Firebird
> database
> IBConnection1.Username := 'SYSDBA';
> IBConnection1.Password := 'masterkey'; //default password for SYSDBA
> IBConnection1.Charset := 'UTF8'; //Send and receive string data in
> UTF8 encoding
> IBConnection1.Dialect := 3; //Nobody uses 1 or 2 anymore.
> if (FileExists(DatabaseFile)=false) then
> begin
> CreateScript := TSQLScript.Create(nil);
> ScriptText:=TStringList.Create;
> try
> CreateScript.OnException:=@ExceptionHandler;
> IBConnection1.DatabaseName:='';
> CreateScript.DataBase:=IBConnection1;
> CreateScript.Transaction:=SQLTransaction1;
> IBConnection1.Open;
> SQLTransaction1.StartTransaction;
>
> ScriptText.Text:='CREATE DATABASE ''database1.fdb'' page_size
> 16384 user ''SYSDBA'' password ''masterkey'' default character set UTF8;';
> CreateScript.Script:=ScriptText;
> CreateScript.ExecuteScript;
> SQLTransaction1.Commit;
>
> SQLTransaction1.StartTransaction;
> ScriptText.Text:='CREATE TABLE Table1 (id VARCHAR(255), name
> VARCHAR(255));';
> CreateScript.Script:=ScriptText;
> CreateScript.ExecuteScript;
> SQLTransaction1.Commit;
>
> IBConnection1.Close;
> finally
> ScriptText.Free;
> CreateScript.Free;
> end;
> end;
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list