Add support for in-memory database
[gnadelite.git] / src / db-sqlite.ads
blob7cdc1d8d5bcae30a69104f0d05c684dc79fd6b8a
1 ------------------------------------------------------------------------------
2 -- GnadeLite --
3 -- --
4 -- Copyright (C) 2006 --
5 -- Pascal Obry - Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 with GNU.DB.SQLite3;
24 package DB.SQLite is
26 DB_Error : exception renames DB.DB_Error;
28 type Handle is new DB.Handle with private;
30 In_Memory_Database : constant String := ":memory:";
31 -- When the database name is ":memory:", a private in-memory
32 -- database is created for the connection. This in-memory
33 -- database will vanish when the database connection is closed.
35 overriding procedure Connect
36 (DB : in out Handle;
37 Name : in String;
38 User : in String := "";
39 Password : in String := "");
40 -- Open the database named Name
42 overriding procedure Close (DB : in out Handle);
43 -- Close the current database
45 -- Transaction
47 overriding procedure Begin_Transaction (DB : in Handle);
48 -- Start a new transaction, do not support embedded transactions
50 overriding procedure Commit (DB : in Handle);
51 -- Commit the current transaction
53 overriding procedure Rollback (DB : in Handle);
54 -- Rollback the current transaction
56 -- Statement
58 type Iterator is new DB.Iterator with private;
60 overriding procedure Prepare_Select
61 (DB : in Handle;
62 Iter : in out Standard.DB.Iterator'Class;
63 SQL : in String);
64 -- Prepare a select statement (SQL must be a select command)
66 overriding procedure Get_Line
67 (Iter : in out Iterator;
68 Result : out String_Vectors.Vector);
69 -- Returns the current row and move to the next one
71 overriding function More (Iter : in Iterator) return Boolean;
72 -- Returns True if there is more data (row) to fetch
74 overriding procedure End_Select (Iter : in out Iterator);
76 overriding procedure Execute (DB : in Handle; SQL : in String);
77 -- Execute SQL request into DB
79 overriding function Last_Insert_Rowid (DB : in Handle) return String;
80 -- Returns the Id of the last inserted row id
82 private
84 type Handle is new DB.Handle with record
85 H : GNU.DB.SQLite3.Handle;
86 end record;
88 type Iterator is new DB.Iterator with record
89 H : Handle;
90 S : aliased GNU.DB.SQLite3.Statement;
91 Col : Natural;
92 More : Boolean;
93 end record;
95 end DB.SQLite;