wiki:SQL/SQLite3

SQL Database Access - SQLite3

SQLite3 driver module allows to use embedded SQLite engine. It supports SQLite version 3.6 and later.

Driver Name

The name of the SQLite3 driver to be passed to SQL.Databases.Create subprogram is "SQLITE3".

Driver's Options

Driver supports only one option called filename to specify path to database file.

Driver features

SQLite3 driver allows to obtain number of last inserted row through LAST_INSERT_ROWID pseudo-paramter of SQL_Query object. This is especially useful to obtain value of automatically incremented primary key for new inserted record.

declare
   Query : SQL.Queries.SQL_Query := Database.Query;

begin
   Query.Prepare
    (League.Strings.To_Universal_String
      ("CREATE TABLE test"
         & " (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
         & " value CHARACTER VARYING NOT NULL)"));
   Query.Execute;

   Query.Prepare
    (League.Strings.To_Universal_String
      ("INSERT INTO test (value) VALUES ('dummy')"));
   Query.Execute;

   Ada.Wide_Wide_Text_IO.Put_Line
    (League.Holders.Universal_Integer'Wide_Wide_Image
      (League.Holders.Element
        (Query.Bound_Value
          (League.Strings.To_Universal_String ("LAST_INSERT_ROWID")))));
end;

Build instructions

SQLite3 module is built automatically when SQLite3 package is installed. Automatic configuration facility use pkg-config tools to check whether package is installed and to obtain required switches. When automatic configuration is unable to detect SQLite3 libraries and linker switches, it is possible to specify path to libraries in the command line of configure (or configure.exe on Windows) program with --with-sqlite3-libdir switch, for example:

configure --with-sqlite3-libdir=/usr/local/sqlite3/lib
Last modified 8 years ago Last modified on May 2, 2013, 4:02:07 PM
Note: See TracWiki for help on using the wiki.