Add a reference counter in DB.SQLite.Handle
[gnadelite.git] / src / db-sqlite.ads
blob4809708db12a045d140221eb9c8b19bc4012107b
1 ------------------------------------------------------------------------------
2 -- GnadeLite --
3 -- --
4 -- Copyright (C) 2006-2008 --
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 private with sqlite3_h;
23 private with Interfaces.C;
25 package DB.SQLite is
27 DB_Error : exception renames DB.DB_Error;
29 type Handle is new DB.Handle with private;
31 In_Memory_Database : constant String := ":memory:";
32 -- When the database name is ":memory:", a private in-memory
33 -- database is created for the connection. This in-memory
34 -- database will vanish when the database connection is closed.
36 overriding procedure Connect
37 (DB : in out Handle;
38 Name : in String;
39 User : in String := "";
40 Password : in String := "");
41 -- Open the database named Name
43 overriding procedure Close (DB : in out Handle);
44 -- Close the current database
46 -- Transaction
48 overriding procedure Begin_Transaction (DB : in Handle);
49 -- Start a new transaction, do not support embedded transactions
51 overriding procedure Commit (DB : in Handle);
52 -- Commit the current transaction
54 overriding procedure Rollback (DB : in Handle);
55 -- Rollback the current transaction
57 -- Statement
59 type Iterator is new DB.Iterator with private;
61 overriding procedure Prepare_Select
62 (DB : in Handle;
63 Iter : in out Standard.DB.Iterator'Class;
64 SQL : in String);
65 -- Prepare a select statement (SQL must be a select command)
67 overriding procedure Get_Line
68 (Iter : in out Iterator;
69 Result : out String_Vectors.Vector);
70 -- Returns the current row and move to the next one
72 overriding function More (Iter : in Iterator) return Boolean;
73 -- Returns True if there is more data (row) to fetch
75 overriding procedure End_Select (Iter : in out Iterator);
77 overriding procedure Execute (DB : in Handle; SQL : in String);
78 -- Execute SQL request into DB. Raise DB_Error in case of failure.
80 overriding function Last_Insert_Rowid (DB : in Handle) return String;
81 -- Returns the Id of the last inserted row id
83 private
85 type Handle is new DB.Handle with record
86 H : aliased sqlite3_h.Handle_Access;
87 Ref_Count : Natural := 0;
88 end record;
90 type Iterator is new DB.Iterator with record
91 H : Handle;
92 S : aliased sqlite3_h.Statement_Access := null;
93 Col : Interfaces.C.int;
94 More : Boolean;
95 end record;
97 end DB.SQLite;