Remove unneeded with statements
[gnadelite.git] / src / db-sqlite.ads
blobe46e1c7ddb35b7e5bcfbe2eed32d635680516151
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
42 pragma Precondition (Name /= "");
44 overriding procedure Close (DB : in out Handle);
45 -- Close the current database
47 -- Transaction
49 overriding procedure Begin_Transaction (DB : in Handle);
50 -- Start a new transaction, do not support embedded transactions
52 overriding procedure Commit (DB : in Handle);
53 -- Commit the current transaction
55 overriding procedure Rollback (DB : in Handle);
56 -- Rollback the current transaction
58 -- Statement
60 type Iterator is new DB.Iterator with private;
62 overriding procedure Prepare_Select
63 (DB : in Handle;
64 Iter : in out Standard.DB.Iterator'Class;
65 SQL : in String);
66 -- Prepare a select statement (SQL must be a select command)
67 pragma Precondition (SQL /= "");
69 overriding procedure Get_Line
70 (Iter : in out Iterator;
71 Result : out String_Vectors.Vector);
72 -- Returns the current row and move to the next one
74 overriding function More (Iter : in Iterator) return Boolean;
75 -- Returns True if there is more data (row) to fetch
77 overriding procedure End_Select (Iter : in out Iterator);
79 overriding procedure Execute (DB : in Handle; SQL : in String);
80 -- Execute SQL request into DB. Raise DB_Error in case of failure.
81 pragma Precondition (SQL /= "");
83 overriding function Last_Insert_Rowid (DB : in Handle) return String;
84 -- Returns the Id of the last inserted row id
86 overriding procedure Set_Max_Tries
87 (DB : in out Handle;
88 Count : in Positive;
89 Retry_Delay : Duration);
90 -- Number of retry when SQLite returns SQLITE_BUSY error
92 private
94 type Handle is new DB.Handle with record
95 H : aliased sqlite3_h.Handle_Access;
96 Ref_Count : Natural := 0;
97 Max_Tries : Positive := 5;
98 Retry_Delay : Duration := 0.01;
99 end record;
101 type Iterator is new DB.Iterator with record
102 H : Handle;
103 S : aliased sqlite3_h.Statement_Access := null;
104 Col : Interfaces.C.int;
105 More : Boolean;
106 end record;
108 end DB.SQLite;