Page 1 of 1

Create sqlite db in program code

Posted: Tue 12 Feb 2013 12:12
by jota
Hi, i´m using UniDAC 4.3.8

How i can create and configure a new sqlite database by typing the code in delphi?

A little example or explanation, please.

Thanks in advance

Re: Create sqlite db in program code

Posted: Tue 12 Feb 2013 14:00
by AlexP
Hello,

To create a DB, it is just enough to specify the full path and the name of the created file in the UniConnection.Database property - the database will be created at connection. Note that the ForceCreateDatabase option (False by default) responsible for database creation was added in UniDAC 4.5.9, i.e., since UniDAC 4.5.9, to create a new database, this option must be set to True. To set parameters of the created database, you can use PRAGMA Statements ( http://www.sqlite.org/pragma.html ). There is a small sample below:

Code: Select all

var
  UniConnection: TUniConnection;
begin
  UniConnection := TUniConnection.Create(nil);
  UniConnection.ProviderName := 'SQLite';
  UniConnection.Database := 'd:\NewTetsDB.db3';
  UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'True'; // In UniDAC 4.5.9 and higher
  UniConnection.Connect;
  UniConnection.ExecSQL('PRAGMA auto_vacuum = 1');