-
Notifications
You must be signed in to change notification settings - Fork 3
/
apq-common.ads
338 lines (334 loc) · 9.79 KB
/
apq-common.ads
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
-- --
-- package APQ.Common Copyright (c) Dmitry A. Kazakov --
-- Interface Luebeck --
-- Winter, 2004 --
-- --
-- Last revision : 15:03 28 Mar 2009 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Persistent.Data_Bank; use Persistent.Data_Bank;
package APQ.Common is
pragma Elaborate_Body (APQ.Common);
type Root_Connection_Ptr is access Root_Connection_Type'Class;
type Root_Query_Ptr is access Root_Query_Type'Class;
--
-- APQ_Data_Base -- Data base low-level interface object
--
type APQ_Data_Base is
new Ada.Finalization.Limited_Controlled with
record
Connection : Root_Connection_Ptr;
Query : Root_Query_Ptr;
Shared : Sharing_Type := Fully;
end record;
--
-- Append_Quoted -- Adds a quoted string to the query
--
-- Data_Base - To the data base
-- Text - The text
-- After - Suffix to add after the text
--
procedure Append_Quoted
( Data_Base : in out APQ_Data_Base;
Text : String;
After : String := ""
);
--
-- Close_DB_Trace -- Close trace file
--
-- Data_Base - To the data base
--
-- Nothing happens if tracing is inactive.
--
procedure Close_DB_Trace (Data_Base : in out APQ_Data_Base);
--
-- Commit -- Changes
--
-- Data_Base - To the data base
--
-- Exceptions :
--
-- Data_Error - A data base error
-- Use_Error - Wrong access mode
--
procedure Commit (Data_Base : in out APQ_Data_Base);
--
-- Connect -- To a data base
--
-- Data_Base - The object
-- Server_Type - Type of the server to connect to
-- Data_Base_Name - To connect to
-- User_Name - To connect as
-- Password - Of the user
-- Host_Name - Of the server running the data base engine
-- Port_Number - The TCP/IP port listened by the server
--
-- Exceptions :
--
-- Use_Error - Password or other data might be wrong
-- Data_Error - Data base error
--
procedure Connect
( Data_Base : in out APQ_Data_Base;
Server_Type : Database_Type;
Data_Base_Name : String;
User_Name : String;
Password : String;
Host_Name : String := "localhost";
Port_Number : Natural := 0
);
--
-- Drop -- Delete a table
--
-- Data_Base - The data base
-- Table_Name - To delete
--
-- Nothing happens if the table does not exist.
--
-- Exceptions :
--
-- Data_Error - A data base error
-- Use_Error - Wrong access mode
--
-- Effects :
--
-- Seize_Write is called to perform the operation
--
procedure Drop
( Data_Base : in out APQ_Data_Base;
Table_Name : String
);
--
-- Execute -- A prepared command
--
-- Data_Base - The data base
--
-- Exceptions :
--
-- Data_Error - A data base error
-- Use_Error - Wrong access mode
--
procedure Execute (Data_Base : APQ_Data_Base);
--
-- Finalize -- Destructor
--
-- Data_Base - The object to finalize
--
procedure Finalize (Data_Base : in out APQ_Data_Base);
--
-- Get_ID -- Get the ID of newly inserted row
--
-- Data_Base - The Data_Base
-- Table_Name - The table into which the row was inserted
-- Column_Name - The column that identifies the row (primary key)
--
-- This function is called immediately after issuing INSERT command to
-- obtain the identifier of the row. The result can be used in SELECT
-- with the name of the table column identifying the row. Note, for
-- postreSQL it is not the OID, but serial.
--
-- Returns :
--
-- The ID
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function Get_ID
( Data_Base : APQ_Data_Base;
Table_Name : String;
Column_Name : String
) return Row_ID_Type;
--
-- ID_Type -- The name of the type used to identify a row
--
-- Data_Base - To the data base for which the type is queried
--
-- The type is an autoincremented or globally unique type used as a
-- primary table key. Its referential counterpart is returned by
-- Ref_Type.
--
-- Returns :
--
-- The type name (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function ID_Type (Data_Base : APQ_Data_Base) return String;
--
-- Integer_Type -- The name of the type used for integers
--
-- Data_Base - The data base for which the type is queried
--
-- Returns :
--
-- The type name (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function Integer_Type (Data_Base : APQ_Data_Base) return String;
--
-- New_ID -- The name of ID generator to used in INSERT
--
-- Data_Base - The Data_Base
--
-- Returns :
--
-- The name of (usually "new_id")
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function New_ID (Data_Base : APQ_Data_Base) return String;
--
-- Open_DB_Trace -- Open trace file and start tracing
--
-- Data_Base - The data base
-- File_Name - To open
-- Mode - The tracing mode
--
procedure Open_DB_Trace
( Data_Base : APQ_Data_Base;
File_Name : String;
Mode : Trace_Mode_Type := Trace_APQ
);
--
-- Ref_Type -- The name of the type used to reference a row
--
-- Data_Base - The data base for which the type is queried
--
-- See ID_Type.
--
-- Returns :
--
-- The type name (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function Ref_Type (Data_Base : APQ_Data_Base) return String;
--
-- Roll_Back -- Changes
--
-- Data_Base - The data base
--
-- Exceptions :
--
-- Data_Error - A data base error
-- Use_Error - Wrong access mode
--
procedure Roll_Back (Data_Base : in out APQ_Data_Base);
--
-- Seize_Read/Write -- Start transaction
--
-- Data_Base - The data base
--
-- Exceptions :
--
-- Data_Error - A data base error
-- Use_Error - Wrong access mode
--
procedure Seize_Read (Data_Base : in out APQ_Data_Base);
procedure Seize_Write (Data_Base : in out APQ_Data_Base);
--
-- String_Type -- The name of the type used for variable length strings
--
-- Data_Base - To the data base for which the type is queried
--
-- Returns :
--
-- The type name (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function String_Type (Data_Base : APQ_Data_Base) return String;
--
-- Table_Exists -- The command
--
-- Data_Base - The data base
-- Table_Name - The table name
--
-- Returns :
--
-- True if the table exists
--
function Table_Exists
( Data_Base : APQ_Data_Base;
Table_Name : String
) return Boolean;
--
-- Timestamp_Now -- Pseudo-value now
--
-- Data_Base - The data base for which the value is queried
--
-- Returns :
--
-- Now (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function Timestamp_Now (Data_Base : APQ_Data_Base)
return String;
--
-- Timestamp_Type -- The name of the type used for timestamps
--
-- Data_Base - The data base for which the type is queried
--
-- Returns :
--
-- The type name (to be used in SQL requests)
--
-- Exceptions :
--
-- Use_Error - The type is not supported by the data base
--
function Timestamp_Type (Data_Base : APQ_Data_Base)
return String;
--
-- Value -- Of a result column
--
-- Data_Base - The data base for which the type is queried
-- Column - The column number
--
-- Returns :
--
-- The value
--
-- Exceptions :
--
-- Data_Error - A data base error
--
function Value
( Data_Base : APQ_Data_Base;
Column : Column_Index_Type
) return String;
end APQ.Common;