Warning, /sdk/codevis/thirdparty/soci/languages/ada/soci.ads is written in an unsupported language. File is not indexed.
0001 -- 0002 -- Thin wrapper for the simple interface of the SOCI database access library. 0003 -- 0004 -- Copyright (C) 2008-2011 Maciej Sobczak 0005 -- Distributed under the Boost Software License, Version 1.0. 0006 -- (See accompanying file LICENSE_1_0.txt or copy at 0007 -- http://www.boost.org/LICENSE_1_0.txt) 0008 0009 with Ada.Calendar; 0010 with Interfaces.C; 0011 0012 private with System; 0013 private with Ada.Finalization; 0014 0015 package SOCI is 0016 0017 -- 0018 -- General exception related to database and library usage. 0019 -- 0020 0021 Database_Error : exception; 0022 0023 -- 0024 -- Session. 0025 -- 0026 0027 type Session is tagged limited private; 0028 0029 not overriding 0030 function Make_Session (Connection_String : in String) return Session; 0031 0032 not overriding 0033 procedure Open (This : in out Session; Connection_String : in String); 0034 0035 not overriding 0036 procedure Close (This : in out Session); 0037 0038 not overriding 0039 function Is_Open (This : in Session) return Boolean; 0040 0041 -- Transaction management. 0042 0043 not overriding 0044 procedure Start (This : in Session); 0045 0046 not overriding 0047 procedure Commit (This : in Session); 0048 0049 not overriding 0050 procedure Rollback (This : in Session); 0051 0052 -- Immediate query execution. 0053 not overriding 0054 procedure Execute (This : in Session; Query : in String); 0055 0056 -- 0057 -- Connection pool management. 0058 -- 0059 0060 type Connection_Pool (Size : Positive) is tagged limited private; 0061 0062 not overriding 0063 procedure Open 0064 (This : in out Connection_Pool; 0065 Position : in Positive; 0066 Connection_String : in String); 0067 0068 not overriding 0069 procedure Close (This : in out Connection_Pool; Position : in Positive); 0070 0071 not overriding 0072 procedure Lease (This : in out Connection_Pool; S : in out Session'Class); 0073 0074 -- 0075 -- Statement. 0076 -- 0077 0078 type Statement (<>) is tagged limited private; 0079 0080 type Data_State is (Data_Null, Data_Not_Null); 0081 0082 type Into_Position is private; 0083 0084 type Vector_Index is new Natural; 0085 0086 not overriding 0087 function Make_Statement (Sess : in Session'Class) return Statement; 0088 0089 -- Statement preparation and execution. 0090 0091 not overriding 0092 procedure Prepare (This : in Statement; Query : in String); 0093 0094 not overriding 0095 procedure Execute 0096 (This : in Statement; 0097 With_Data_Exchange : in Boolean := False); 0098 0099 not overriding 0100 function Execute 0101 (This : in Statement; 0102 With_Data_Exchange : in Boolean := False) return Boolean; 0103 0104 not overriding 0105 function Fetch (This : in Statement) return Boolean; 0106 0107 not overriding 0108 function Got_Data (This : in Statement) return Boolean; 0109 0110 -- 0111 -- Data items handling. 0112 -- 0113 0114 -- Database-specific types. 0115 -- These types are most likely identical to standard Integer, 0116 -- Long_Long_Integer and Long_Float, but are defined distinctly 0117 -- to avoid interfacing problems with other compilers. 0118 0119 type DB_Integer is new Interfaces.C.int; 0120 type DB_Long_Long_Integer is new Interfaces.Integer_64; 0121 type DB_Long_Float is new Interfaces.C.double; 0122 0123 -- Creation of single into elements. 0124 0125 not overriding 0126 function Into_String (This : in Statement) return Into_Position; 0127 0128 not overriding 0129 function Into_Integer (This : in Statement) return Into_Position; 0130 0131 not overriding 0132 function Into_Long_Long_Integer (This : in Statement) return Into_Position; 0133 0134 not overriding 0135 function Into_Long_Float (This : in Statement) return Into_Position; 0136 0137 not overriding 0138 function Into_Time (This : in Statement) return Into_Position; 0139 0140 -- Creation of vector into elements. 0141 0142 not overriding 0143 function Into_Vector_String (This : in Statement) return Into_Position; 0144 0145 not overriding 0146 function Into_Vector_Integer (This : in Statement) return Into_Position; 0147 0148 not overriding 0149 function Into_Vector_Long_Long_Integer (This : in Statement) return Into_Position; 0150 0151 not overriding 0152 function Into_Vector_Long_Float (This : in Statement) return Into_Position; 0153 0154 not overriding 0155 function Into_Vector_Time (This : in Statement) return Into_Position; 0156 0157 -- Inspection of single into elements. 0158 0159 not overriding 0160 function Get_Into_State 0161 (This : in Statement; 0162 Position : in Into_Position) 0163 return Data_State; 0164 0165 not overriding 0166 function Get_Into_String 0167 (This : in Statement; 0168 Position : in Into_Position) 0169 return String; 0170 0171 not overriding 0172 function Get_Into_Integer 0173 (This : in Statement; 0174 Position : in Into_Position) 0175 return DB_Integer; 0176 0177 not overriding 0178 function Get_Into_Long_Long_Integer 0179 (This : in Statement; 0180 Position : in Into_Position) 0181 return DB_Long_Long_Integer; 0182 0183 not overriding 0184 function Get_Into_Long_Float 0185 (This : in Statement; 0186 Position : in Into_Position) 0187 return DB_Long_Float; 0188 0189 not overriding 0190 function Get_Into_Time 0191 (This : in Statement; 0192 Position : in Into_Position) 0193 return Ada.Calendar.Time; 0194 0195 -- Inspection of vector into elements. 0196 0197 not overriding 0198 function Get_Into_Vectors_Size (This : in Statement) return Natural; 0199 0200 not overriding 0201 function Into_Vectors_First_Index (This : in Statement) return Vector_Index; 0202 0203 not overriding 0204 function Into_Vectors_Last_Index (This : in Statement) return Vector_Index; 0205 0206 not overriding 0207 procedure Into_Vectors_Resize (This : in Statement; New_Size : in Natural); 0208 0209 not overriding 0210 function Get_Into_Vector_State 0211 (This : in Statement; 0212 Position : in Into_Position; 0213 Index : in Vector_Index) 0214 return Data_State; 0215 0216 not overriding 0217 function Get_Into_Vector_String 0218 (This : in Statement; 0219 Position : in Into_Position; 0220 Index : in Vector_Index) 0221 return String; 0222 0223 not overriding 0224 function Get_Into_Vector_Integer 0225 (This : in Statement; 0226 Position : in Into_Position; 0227 Index : in Vector_Index) 0228 return DB_Integer; 0229 0230 not overriding 0231 function Get_Into_Vector_Long_Long_Integer 0232 (This : in Statement; 0233 Position : in Into_Position; 0234 Index : in Vector_Index) 0235 return DB_Long_Long_Integer; 0236 0237 not overriding 0238 function Get_Into_Vector_Long_Float 0239 (This : in Statement; 0240 Position : in Into_Position; 0241 Index : in Vector_Index) 0242 return DB_Long_Float; 0243 0244 not overriding 0245 function Get_Into_Vector_Time 0246 (This : in Statement; 0247 Position : in Into_Position; 0248 Index : in Vector_Index) 0249 return Ada.Calendar.Time; 0250 0251 -- Creation of single use elements. 0252 0253 not overriding 0254 procedure Use_String (This : in Statement; Name : in String); 0255 0256 not overriding 0257 procedure Use_Integer (This : in Statement; Name : in String); 0258 0259 not overriding 0260 procedure Use_Long_Long_Integer (This : in Statement; Name : in String); 0261 0262 not overriding 0263 procedure Use_Long_Float (This : in Statement; Name : in String); 0264 0265 not overriding 0266 procedure Use_Time (This : in Statement; Name : in String); 0267 0268 -- Creation of vector use elements. 0269 0270 not overriding 0271 procedure Use_Vector_String (This : in Statement; Name : in String); 0272 0273 not overriding 0274 procedure Use_Vector_Integer (This : in Statement; Name : in String); 0275 0276 not overriding 0277 procedure Use_Vector_Long_Long_Integer (This : in Statement; Name : in String); 0278 0279 not overriding 0280 procedure Use_Vector_Long_Float (This : in Statement; Name : in String); 0281 0282 not overriding 0283 procedure Use_Vector_Time (This : in Statement; Name : in String); 0284 0285 -- Modifiers for single use elements. 0286 0287 not overriding 0288 procedure Set_Use_State 0289 (This : in Statement; 0290 Name : in String; 0291 State : in Data_State); 0292 0293 not overriding 0294 procedure Set_Use_String 0295 (This : in Statement; 0296 Name : in String; 0297 Value : in String); 0298 0299 not overriding 0300 procedure Set_Use_Integer 0301 (This : in Statement; 0302 Name : in String; 0303 Value : in DB_Integer); 0304 0305 not overriding 0306 procedure Set_Use_Long_Long_Integer 0307 (This : in Statement; 0308 Name : in String; 0309 Value : in DB_Long_Long_Integer); 0310 0311 not overriding 0312 procedure Set_Use_Long_Float 0313 (This : in Statement; 0314 Name : in String; 0315 Value : in DB_Long_Float); 0316 0317 not overriding 0318 procedure Set_Use_Time 0319 (This : in Statement; 0320 Name : in String; 0321 Value : in Ada.Calendar.Time); 0322 0323 -- Modifiers for vector use elements. 0324 0325 not overriding 0326 function Get_Use_Vectors_Size (This : in Statement) return Natural; 0327 0328 not overriding 0329 function Use_Vectors_First_Index (This : in Statement) return Vector_Index; 0330 0331 not overriding 0332 function Use_Vectors_Last_Index (This : in Statement) return Vector_Index; 0333 0334 not overriding 0335 procedure Use_Vectors_Resize (This : in Statement; New_Size : in Natural); 0336 0337 not overriding 0338 procedure Set_Use_Vector_State 0339 (This : in Statement; 0340 Name : in String; 0341 Index : in Vector_Index; 0342 State : in Data_State); 0343 0344 not overriding 0345 procedure Set_Use_Vector_String 0346 (This : in Statement; 0347 Name : in String; 0348 Index : in Vector_Index; 0349 Value : in String); 0350 0351 not overriding 0352 procedure Set_Use_Vector_Integer 0353 (This : in Statement; 0354 Name : in String; 0355 Index : in Vector_Index; 0356 Value : in DB_Integer); 0357 0358 not overriding 0359 procedure Set_Use_Vector_Long_Long_Integer 0360 (This : in Statement; 0361 Name : in String; 0362 Index : in Vector_Index; 0363 Value : in DB_Long_Long_Integer); 0364 0365 not overriding 0366 procedure Set_Use_Vector_Long_Float 0367 (This : in Statement; 0368 Name : in String; 0369 Index : in Vector_Index; 0370 Value : in DB_Long_Float); 0371 0372 not overriding 0373 procedure Set_Use_Vector_Time 0374 (This : in Statement; 0375 Name : in String; 0376 Index : in Vector_Index; 0377 Value : in Ada.Calendar.Time); 0378 0379 -- Inspection of single use elements. 0380 -- 0381 -- Note: Use elements can be modified by the database if they 0382 -- are bound to out and inout parameters of stored procedures 0383 -- (although this is not supported by all database backends). 0384 -- This feature is available only for single use elements. 0385 0386 not overriding 0387 function Get_Use_State 0388 (This : in Statement; 0389 Name : in String) 0390 return Data_State; 0391 0392 not overriding 0393 function Get_Use_String 0394 (This : in Statement; 0395 Name : in String) 0396 return String; 0397 0398 not overriding 0399 function Get_Use_Integer 0400 (This : in Statement; 0401 Name : in String) 0402 return DB_Integer; 0403 0404 not overriding 0405 function Get_Use_Long_Long_Integer 0406 (This : in Statement; 0407 Name : in String) 0408 return DB_Long_Long_Integer; 0409 0410 not overriding 0411 function Get_Use_Long_Float 0412 (This : in Statement; 0413 Name : in String) 0414 return DB_Long_Float; 0415 0416 not overriding 0417 function Get_Use_Time 0418 (This : in Statement; 0419 Name : in String) 0420 return Ada.Calendar.Time; 0421 0422 private 0423 0424 -- Connection pool and supporting types. 0425 0426 type Connection_Array is array (Positive range <>) of Session; 0427 type Used_Array is array (Positive range <>) of Boolean; 0428 0429 -- Protected state for the connection pool. 0430 protected type Connection_Pool_PS (Size : Positive) is 0431 0432 procedure Open (Position : in Positive; Connection_String : in String); 0433 procedure Close (Position : in Positive); 0434 0435 entry Lease (S : in out Session'Class); 0436 procedure Give_Back (Position : in Positive); 0437 0438 private 0439 0440 Connections : Connection_Array (1 .. Size); 0441 Is_Used : Used_Array (1 .. Size) := (others => False); 0442 Available : Boolean := True; 0443 0444 end Connection_Pool_PS; 0445 type Connection_Pool_PS_Ptr is access all Connection_Pool_PS; 0446 0447 type Connection_Pool (Size : Positive) is tagged limited record 0448 Pool : aliased Connection_Pool_PS (Size); 0449 end record; 0450 0451 -- Session and supporting types. 0452 0453 type Session_Handle is new System.Address; 0454 0455 Null_Session_Handle : constant Session_Handle := 0456 Session_Handle (System.Null_Address); 0457 0458 type Session is new Ada.Finalization.Limited_Controlled with record 0459 Handle : Session_Handle; 0460 Initialized : Boolean := False; 0461 Belongs_To_Pool : Boolean := False; 0462 Pool : Connection_Pool_PS_Ptr; 0463 Position_In_Pool : Positive; 0464 end record; 0465 0466 overriding 0467 procedure Finalize (This : in out Session); 0468 0469 -- Statement and supporting types. 0470 0471 type Statement_Handle is new System.Address; 0472 0473 Null_Statement_Handle : constant Statement_Handle := 0474 Statement_Handle (System.Null_Address); 0475 0476 type Statement is new Ada.Finalization.Limited_Controlled with record 0477 Handle : Statement_Handle; 0478 Initialized : Boolean := False; 0479 end record; 0480 0481 overriding 0482 procedure Finalize (This : in out Statement); 0483 0484 type Into_Position is new Natural; 0485 0486 end SOCI;