summaryrefslogtreecommitdiff
path: root/src/sqlite3.ads
blob: df49e2cd08d81ff5653a79140053796e0db3c31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166


with

    Ada.Strings.Unbounded;

private with

    Ada.Finalization;


package SQLite3 is


    type SQLite3_DB is tagged limited private;
    type SQLite3_Statement is tagged limited private;

    type Open_Flag is mod 2**32;
    type Prepare_Flag is mod 2**32;
    type Status_Code is new Long_Integer;

    subtype SQL_Parameter_Index is Integer range 1 .. Integer'Last;
    subtype SQL_Column_Index is Integer;


    OPEN_READONLY      : constant Open_Flag := 1;
    OPEN_READWRITE     : constant Open_Flag := 2;
    OPEN_CREATE        : constant Open_Flag := 4;
    OPEN_DELETEONCLOSE : constant Open_Flag := 8;
    OPEN_EXCLUSIVE     : constant Open_Flag := 16;
    OPEN_AUTOPROXY     : constant Open_Flag := 32;
    OPEN_URI           : constant Open_Flag := 64;
    OPEN_MEMORY        : constant Open_Flag := 128;
    OPEN_MAIN_DB       : constant Open_Flag := 256;
    OPEN_TEMP_DB       : constant Open_Flag := 512;
    OPEN_TRANSIENT_DB  : constant Open_Flag := 1024;
    OPEN_MAIN_JOURNAL  : constant Open_Flag := 2048;
    OPEN_TEMP_JOURNAL  : constant Open_Flag := 4096;
    OPEN_SUBJOURNAL    : constant Open_Flag := 8192;
    OPEN_SUPER_JOURNAL : constant Open_Flag := 16384;
    OPEN_NOMUTEX       : constant Open_Flag := 32768;
    OPEN_FULLMUTEX     : constant Open_Flag := 65536;
    OPEN_SHAREDCACHE   : constant Open_Flag := 131072;
    OPEN_PRIVATECACHE  : constant Open_Flag := 262144;
    OPEN_WAL           : constant Open_Flag := 524288;
    OPEN_NOFOLLOW      : constant Open_Flag := 16777216;

    PREPARE_PERSISTENT : constant Prepare_Flag := 1;
    PREPARE_NORMALIZE  : constant Prepare_Flag := 2;
    PREPARE_NO_VTAB    : constant Prepare_Flag := 4;

    SQLITE_OK    : constant Status_Code := 0;
    SQLITE_ROW   : constant Status_Code := 100;
    SQLITE_DONE  : constant Status_Code := 101;

    SQLITE_TRANSIENT : constant := -1;


    procedure Open
           (Handle   :    out SQLite3_DB;
            Filename : in     String);

    procedure Open
           (Handle   :    out SQLite3_DB;
            Filename : in     String;
            Flags    : in     Open_Flag);

    procedure Close
           (Handle : in out SQLite3_DB);


    procedure Prepare
           (Handle     : in     SQLite3_DB;
            SQL        : in     String;
            SQL_Handle :    out SQLite3_Statement'Class);

    procedure Prepare
           (Handle     : in     SQLite3_DB;
            SQL        : in     String;
            Flags      : in     Prepare_Flag;
            SQL_Handle :    out SQLite3_Statement'Class);

    procedure Step
           (SQL_Handle : in out SQLite3_Statement);

    function Status
           (SQL_Handle : in SQLite3_Statement)
        return Status_Code;

    procedure Finish
           (SQL_Handle : in out SQLite3_Statement);

    procedure Reset
           (SQL_Handle : in out SQLite3_Statement);

    procedure Bind
           (SQL_Handle : in out SQLite3_Statement;
            Index      : in     SQL_Parameter_Index;
            Value      : in     Integer);

    procedure Bind
           (SQL_Handle : in out SQLite3_Statement;
            Index      : in     SQL_Parameter_Index;
            Value      : in     Long_Integer);

    procedure Bind
           (SQL_Handle : in out SQLite3_Statement;
            Index      : in     SQL_Parameter_Index;
            Value      : in     Ada.Strings.Unbounded.Unbounded_String);

    function Column
           (SQL_Handle : in SQLite3_Statement;
            Index      : in SQL_Column_Index)
        return Integer;

    function Column
           (SQL_Handle : in SQLite3_Statement;
            Index      : in SQL_Column_Index)
        return Ada.Strings.Unbounded.Unbounded_String;


private


    --  There are actually many more errors than this
    SQLITE_ERROR : constant Status_Code := 1;

    function Error_Message
           (Handle : in SQLite3_DB)
        return String;

    function Error_String
           (Status : in Status_Code)
        return String;


    type DB_Private is null record;
    type DB_Private_Access is access all DB_Private;

    type SQLite3_DB is new Ada.Finalization.Limited_Controlled with record
        Ptr  : aliased DB_Private_Access;
        Prep : Boolean := False;
    end record;

    overriding
    procedure Finalize
           (This : in out SQLite3_DB);


    type Statement_Private is null record;
    type Statement_Private_Access is access all Statement_Private;

    type SQLite3_Statement is new Ada.Finalization.Limited_Controlled with record
        Ptr    : aliased Statement_Private_Access;
        Status : Status_Code := SQLITE_OK;
        Prep   : Boolean := False;
    end record;

    overriding
    procedure Finalize
           (This : in out SQLite3_Statement);


end SQLite3;