1 ------------------------------------------------------------------------------
4 -- Copyright (C) 2006-2008 --
5 -- Pascal Obry - Olivier Ramonat --
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. --
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. --
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
;
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
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
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
60 type Iterator
is new DB
.Iterator
with private;
62 overriding
procedure Prepare_Select
64 Iter
: in out Standard
.DB
.Iterator
'Class;
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
89 Retry_Delay
: Duration);
90 -- Number of retry when SQLite returns SQLITE_BUSY error
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;
101 type Iterator
is new DB
.Iterator
with record
103 S
: aliased sqlite3_h
.Statement_Access
:= null;
104 Col
: Interfaces
.C
.int
;