Actually, my preference for creating a database in a deployed
application is to first create it on my local system using isql with
input from a  script and then to save it using gbak in a portable
format. The TIBRestoreService is then used to create the database from
the backup archive when your program fails to detect a local database copy.

The advantages of this approach are that:

- you only ever have one file to distribute

- backup/restore is very robust and quick

- you can readily add Blob data to your archive and distribute it as
part of the archive

- the initial database is consistent across all deployments

Scripts tend to be more useful when issuing patches to existing
databases. In this case, simply calling isql from your program and
pointing it at a patch script can be much easier than embedding SQL
execution in your program.

On 03/08/11 10:18, Reinier Olislagers wrote:
> 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;
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to