File: postgresql_test.adb

package info (click to toggle)
soci 4.1.2-2~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 17,968 kB
  • sloc: ansic: 169,887; cpp: 54,198; javascript: 12,258; ada: 1,973; sh: 36; makefile: 12; xml: 2
file content (609 lines) | stat: -rw-r--r-- 23,813 bytes parent folder | download | duplicates (5)
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
with SOCI;
with SOCI.PostgreSQL;
with Ada.Text_IO;
with Ada.Calendar;
with Ada.Exceptions;
with Ada.Numerics.Discrete_Random;
with Ada.Command_Line;

procedure PostgreSQL_Test is

   procedure Test_1 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing basic constructor function");

      declare
         S : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         null;
      end;
   exception
      when E : SOCI.Database_Error =>
         Ada.Text_IO.Put_Line ("Database_Error: ");
         Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Message (E));
   end Test_1;

   procedure Test_2 (Connection_String : in String) is
      S : SOCI.Session;
   begin
      Ada.Text_IO.Put_Line ("testing open/close");

      S.Close;
      S.Open (Connection_String);
      S.Close;
   end Test_2;

   procedure Test_3 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing empty start/commit");

      declare
         S : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         S.Start;
         S.Commit;
      end;
   end Test_3;

   procedure Test_4 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing simple statements");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         SQL.Execute ("create table ada_test ( i integer )");
         SQL.Execute ("drop table ada_test");
      end;
   end Test_4;

   procedure Test_5 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing independent statements");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
         St_1 : SOCI.Statement := SOCI.Make_Statement (SQL);
         St_2 : SOCI.Statement := SOCI.Make_Statement (SQL);
      begin
         St_1.Prepare ("create table ada_test ( i integer )");
         St_2.Prepare ("drop table ada_test");
         St_1.Execute;
         St_2.Execute;
      end;
   end Test_5;

   procedure Test_6 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing data types and into elements");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            Pos := St.Into_String;
            St.Prepare ("select 'Hello'");
            St.Execute (True);
            pragma Assert (St.Get_Into_String (Pos) = "Hello");
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
            Value : SOCI.DB_Integer;
            use type SOCI.DB_Integer;
         begin
            Pos := St.Into_Integer;
            St.Prepare ("select 123");
            St.Execute (True);
            Value := St.Get_Into_Integer (Pos);
            pragma Assert (Value = 123);
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
            Value : SOCI.DB_Long_Long_Integer;
            use type SOCI.DB_Long_Long_Integer;
         begin
            Pos := St.Into_Long_Long_Integer;
            St.Prepare ("select 10000000000");
            St.Execute (True);
            Value := St.Get_Into_Long_Long_Integer (Pos);
            pragma Assert (Value = 10_000_000_000);
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
            Value : SOCI.DB_Long_Float;
            use type SOCI.DB_Long_Float;
         begin
            Pos := St.Into_Long_Float;
            St.Prepare ("select 3.625");
            St.Execute (True);
            Value := St.Get_Into_Long_Float (Pos);
            pragma Assert (Value = SOCI.DB_Long_Float (3.625));
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
            Value : Ada.Calendar.Time;
         begin
            Pos := St.Into_Time;
            St.Prepare ("select timestamp '2008-06-30 21:01:02'");
            St.Execute (True);
            Value := St.Get_Into_Time (Pos);
            pragma Assert (Ada.Calendar.Year (Value) = 2008);
            pragma Assert (Ada.Calendar.Month (Value) = 6);
            pragma Assert (Ada.Calendar.Day (Value) = 30);
            pragma Assert
              (Ada.Calendar.Seconds (Value) =
                 Ada.Calendar.Day_Duration (21 * 3_600 + 1 * 60 + 2));
         end;
      end;
   end Test_6;

   procedure Test_7 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing types with into vectors");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
         St : SOCI.Statement := SOCI.Make_Statement (SQL);
         Pos_Id : SOCI.Into_Position;
         Pos_Str : SOCI.Into_Position;
         Pos_LL : SOCI.Into_Position;
         Pos_LF : SOCI.Into_Position;
         Pos_TM : SOCI.Into_Position;

         use type SOCI.Data_State;
         use type Ada.Calendar.Time;
         use type SOCI.DB_Integer;
         use type SOCI.DB_Long_Long_Integer;
         use type SOCI.DB_Long_Float;

      begin
         SQL.Execute ("create table soci_test (" &
                        " id integer," &
                        " str varchar (20)," &
                        " ll bigint," &
                        " lf double precision," &
                        " tm timestamp" &
                        ")");
         SQL.Execute ("insert into soci_test (id, str, ll, lf, tm)" &
                        " values (1, 'abc', 10000000000, 3.0, timestamp '2008-06-30 21:01:02')");
         SQL.Execute ("insert into soci_test (id, str, ll, lf, tm)" &
                        " values (2, 'xyz', -10000000001, -3.125, timestamp '2008-07-01 21:01:03')");
         SQL.Execute ("insert into soci_test (id, str, ll, lf, tm)" &
                        " values (3, null, null, null, null)");

         Pos_Id := St.Into_Vector_Integer;
         Pos_Str := St.Into_Vector_String;
         Pos_LL := St.Into_Vector_Long_Long_Integer;
         Pos_LF := St.Into_Vector_Long_Float;
         Pos_TM := St.Into_Vector_Time;

         St.Into_Vectors_Resize (10); -- arbitrary batch size

         St.Prepare ("select id, str, ll, lf, tm from soci_test order by id");
         St.Execute (True);

         pragma Assert (St.Get_Into_Vectors_Size = 3);

         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 0) = 1);
         pragma Assert (St.Get_Into_Vector_State (Pos_Str, 0) = SOCI.Data_Not_Null);
         pragma Assert (St.Get_Into_Vector_String (Pos_Str, 0) = "abc");
         pragma Assert (St.Get_Into_Vector_Long_Long_Integer (Pos_LL, 0) = 10_000_000_000);
         pragma Assert (St.Get_Into_Vector_Long_Float (Pos_LF, 0) = SOCI.DB_Long_Float (3.0));
         pragma Assert (St.Get_Into_Vector_Time (Pos_TM, 0) =
                          Ada.Calendar.Time_Of (2008, 6, 30,
                                                Duration (21 * 3_600 + 1 * 60 + 2)));

         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 1) = 2);
         pragma Assert (St.Get_Into_Vector_State (Pos_Str, 1) = SOCI.Data_Not_Null);
         pragma Assert (St.Get_Into_Vector_String (Pos_Str, 1) = "xyz");
         pragma Assert (St.Get_Into_Vector_Long_Long_Integer (Pos_LL, 1) = -10_000_000_001);
         pragma Assert (St.Get_Into_Vector_Long_Float (Pos_LF, 1) = SOCI.DB_Long_Float (-3.125));
         pragma Assert (St.Get_Into_Vector_Time (Pos_TM, 1) =
                          Ada.Calendar.Time_Of (2008, 7, 1,
                                                Duration (21 * 3_600 + 1 * 60 + 3)));

         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 2) = 3);
         pragma Assert (St.Get_Into_Vector_State (Pos_Str, 2) = SOCI.Data_Null);
         pragma Assert (St.Get_Into_Vector_State (Pos_LL, 2) = SOCI.Data_Null);
         pragma Assert (St.Get_Into_Vector_State (Pos_LF, 2) = SOCI.Data_Null);
         pragma Assert (St.Get_Into_Vector_State (Pos_TM, 2) = SOCI.Data_Null);

         SQL.Execute ("drop table soci_test");
      end;
   end Test_7;

   procedure Test_8 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing multi-batch operation with into vectors");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
         St : SOCI.Statement := SOCI.Make_Statement (SQL);
         Pos_Id : SOCI.Into_Position;
         Got_Data : Boolean;

         use type SOCI.DB_Integer;
      begin
         SQL.Execute ("create table soci_test (" &
                        " id integer" &
                        ")");
         SQL.Execute ("insert into soci_test (id) values (1)");
         SQL.Execute ("insert into soci_test (id) values (2)");
         SQL.Execute ("insert into soci_test (id) values (3)");
         SQL.Execute ("insert into soci_test (id) values (4)");
         SQL.Execute ("insert into soci_test (id) values (5)");
         SQL.Execute ("insert into soci_test (id) values (6)");
         SQL.Execute ("insert into soci_test (id) values (7)");
         SQL.Execute ("insert into soci_test (id) values (8)");
         SQL.Execute ("insert into soci_test (id) values (9)");
         SQL.Execute ("insert into soci_test (id) values (10)");

         Pos_Id := St.Into_Vector_Integer;
         St.Into_Vectors_Resize (4); -- batch of 4 elements

         St.Prepare ("select id from soci_test order by id");
         St.Execute;

         Got_Data := St.Fetch;
         pragma Assert (Got_Data);
         pragma Assert (St.Get_Into_Vectors_Size = 4);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 0) = 1);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 1) = 2);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 2) = 3);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 3) = 4);

         Got_Data := St.Fetch;
         pragma Assert (Got_Data);
         pragma Assert (St.Get_Into_Vectors_Size = 4);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 0) = 5);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 1) = 6);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 2) = 7);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 3) = 8);

         Got_Data := St.Fetch;
         pragma Assert (Got_Data);
         pragma Assert (St.Get_Into_Vectors_Size = 2);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 0) = 9);
         pragma Assert (St.Get_Into_Vector_Integer (Pos_Id, 1) = 10);

         Got_Data := St.Fetch;
         pragma Assert (not Got_Data);
         pragma Assert (St.Get_Into_Vectors_Size = 0);

         SQL.Execute ("drop table soci_test");
      end;
   end Test_8;

   procedure Test_9 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing data types and use elements");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);

         use type SOCI.DB_Integer;
         use type SOCI.DB_Long_Long_Integer;
         use type SOCI.DB_Long_Float;
      begin
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            St.Use_String ("value");
            St.Set_Use_String ("value", "123");
            Pos := St.Into_Integer;
            St.Prepare ("select cast(:value as integer)");
            St.Execute (True);
            pragma Assert (St.Get_Into_Integer (Pos) = 123);
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            St.Use_Integer ("value");
            St.Set_Use_Integer ("value", 123);
            Pos := St.Into_String;
            St.Prepare ("select cast(:value as text)");
            St.Execute (True);
            pragma Assert (St.Get_Into_String (Pos) = "123");
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            St.Use_Long_Long_Integer ("value");
            St.Set_Use_Long_Long_Integer ("value", 10_000_000_000);
            Pos := St.Into_String;
            St.Prepare ("select cast(:value as text)");
            St.Execute (True);
            pragma Assert (St.Get_Into_String (Pos) = "10000000000");
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            St.Use_Long_Float ("value");
            St.Set_Use_Long_Float ("value", SOCI.DB_Long_Float (5.625));
            Pos := St.Into_String;
            St.Prepare ("select cast(:value as text)");
            St.Execute (True);
            pragma Assert (St.Get_Into_String (Pos) = "5.625");
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
         begin
            St.Use_Time ("value");
            St.Set_Use_Time ("value", Ada.Calendar.Time_Of
                               (2008, 7, 1, Ada.Calendar.Day_Duration (3723)));
            Pos := St.Into_String;
            St.Prepare ("select cast(:value as text)");
            St.Execute (True);
            pragma Assert (St.Get_Into_String (Pos) = "2008-07-01 01:02:03");
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos : SOCI.Into_Position;
            use type SOCI.Data_State;
         begin
            St.Use_Integer ("value");
            St.Set_Use_State ("value", SOCI.Data_Null);
            Pos := St.Into_Integer;
            St.Prepare ("select cast(:value as integer)");
            St.Execute (True);
            pragma Assert (St.Get_Into_State (Pos) = SOCI.Data_Null);
         end;
      end;
   end Test_9;

   procedure Test_10 (Connection_String : in String) is
   begin
      Ada.Text_IO.Put_Line ("testing vector use elements and row traversal with single into elements");

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);

         Time_1 : constant Ada.Calendar.Time := Ada.Calendar.Time_Of
           (2008, 7, 1, Ada.Calendar.Day_Duration (1));
         Time_2 : constant Ada.Calendar.Time := Ada.Calendar.Time_Of
           (2008, 7, 2, Ada.Calendar.Day_Duration (2));
         Time_3 : constant Ada.Calendar.Time := Ada.Calendar.Time_Of
           (2008, 7, 3, Ada.Calendar.Day_Duration (3));
         Time_4 : constant Ada.Calendar.Time := Ada.Calendar.Time_Of
           (2008, 7, 4, Ada.Calendar.Day_Duration (4));
         Time_5 : constant Ada.Calendar.Time := Ada.Calendar.Time_Of
           (2008, 7, 5, Ada.Calendar.Day_Duration (5));

      begin
         SQL.Execute ("create table soci_test (" &
                        " id integer," &
                        " str varchar (20)," &
                        " ll bigint," &
                        " lf double precision," &
                        " tm timestamp" &
                        ")");

         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
         begin
            St.Use_Vector_Integer ("id");
            St.Use_Vector_String ("str");
            St.Use_Vector_Long_Long_Integer ("ll");
            St.Use_Vector_Long_Float ("lf");
            St.Use_Vector_Time ("tm");

            St.Use_Vectors_Resize (6);
            St.Set_Use_Vector_Integer ("id", 0, 1);
            St.Set_Use_Vector_Integer ("id", 1, 2);
            St.Set_Use_Vector_Integer ("id", 2, 3);
            St.Set_Use_Vector_Integer ("id", 3, 4);
            St.Set_Use_Vector_Integer ("id", 4, 5);
            St.Set_Use_Vector_Integer ("id", 5, 6);
            St.Set_Use_Vector_String ("str", 0, "abc");
            St.Set_Use_Vector_String ("str", 1, "def");
            St.Set_Use_Vector_String ("str", 2, "ghi");
            St.Set_Use_Vector_String ("str", 3, "jklm");
            St.Set_Use_Vector_String ("str", 4, "no");
            St.Set_Use_Vector_State ("str", 5, SOCI.Data_Null);
            St.Set_Use_Vector_Long_Long_Integer ("ll", 0, 10_000_000_000);
            St.Set_Use_Vector_Long_Long_Integer ("ll", 1, 10_000_000_001);
            St.Set_Use_Vector_Long_Long_Integer ("ll", 2, 10_000_000_002);
            St.Set_Use_Vector_Long_Long_Integer ("ll", 3, 10_000_000_003);
            St.Set_Use_Vector_Long_Long_Integer ("ll", 4, 10_000_000_004);
            St.Set_Use_Vector_State ("ll", 5, SOCI.Data_Null);
            St.Set_Use_Vector_Long_Float ("lf", 0, SOCI.DB_Long_Float (0.0));
            St.Set_Use_Vector_Long_Float ("lf", 1, SOCI.DB_Long_Float (0.125));
            St.Set_Use_Vector_Long_Float ("lf", 2, SOCI.DB_Long_Float (0.25));
            St.Set_Use_Vector_Long_Float ("lf", 3, SOCI.DB_Long_Float (0.5));
            St.Set_Use_Vector_Long_Float ("lf", 4, SOCI.DB_Long_Float (0.625));
            St.Set_Use_Vector_State ("lf", 5, SOCI.Data_Null);
            St.Set_Use_Vector_Time ("tm", 0, Time_1);
            St.Set_Use_Vector_Time ("tm", 1, Time_2);
            St.Set_Use_Vector_Time ("tm", 2, Time_3);
            St.Set_Use_Vector_Time ("tm", 3, Time_4);
            St.Set_Use_Vector_Time ("tm", 4, Time_5);
            St.Set_Use_Vector_State ("tm", 5, SOCI.Data_Null);

            St.Prepare ("insert into soci_test (id, str, ll, lf, tm)" &
                          " values (:id, :str, :ll, :lf, :tm)");
            St.Execute (True);
         end;
         declare
            St : SOCI.Statement := SOCI.Make_Statement (SQL);
            Pos_Id : SOCI.Into_Position;
            Pos_Str : SOCI.Into_Position;
            Pos_LL : SOCI.Into_Position;
            Pos_LF : SOCI.Into_Position;
            Pos_TM : SOCI.Into_Position;
            Got_Data : Boolean;

            use type Ada.Calendar.Time;
            use type SOCI.Data_State;
            use type SOCI.DB_Integer;
            use type SOCI.DB_Long_Long_Integer;
            use type SOCI.DB_Long_Float;

         begin
            Pos_Id := St.Into_Integer;
            Pos_Str := St.Into_String;
            Pos_LL := St.Into_Long_Long_Integer;
            Pos_LF := St.Into_Long_Float;
            Pos_TM := St.Into_Time;

            St.Prepare ("select id, str, ll, lf, tm from soci_test order by id");
            St.Execute;

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 1);
            pragma Assert (St.Get_Into_String (Pos_Str) = "abc");
            pragma Assert (St.Get_Into_Long_Long_Integer (Pos_LL) = 10_000_000_000);
            pragma Assert (St.Get_Into_Long_Float (Pos_LF) = SOCI.DB_Long_Float (0.0));
            pragma Assert (St.Get_Into_Time (Pos_TM) = Time_1);

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 2);
            pragma Assert (St.Get_Into_String (Pos_Str) = "def");
            pragma Assert (St.Get_Into_Long_Long_Integer (Pos_LL) = 10_000_000_001);
            pragma Assert (St.Get_Into_Long_Float (Pos_LF) = SOCI.DB_Long_Float (0.125));
            pragma Assert (St.Get_Into_Time (Pos_TM) = Time_2);

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 3);
            pragma Assert (St.Get_Into_String (Pos_Str) = "ghi");
            pragma Assert (St.Get_Into_Long_Long_Integer (Pos_LL) = 10_000_000_002);
            pragma Assert (St.Get_Into_Long_Float (Pos_LF) = SOCI.DB_Long_Float (0.25));
            pragma Assert (St.Get_Into_Time (Pos_TM) = Time_3);

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 4);
            pragma Assert (St.Get_Into_String (Pos_Str) = "jklm");
            pragma Assert (St.Get_Into_Long_Long_Integer (Pos_LL) = 10_000_000_003);
            pragma Assert (St.Get_Into_Long_Float (Pos_LF) = SOCI.DB_Long_Float (0.5));
            pragma Assert (St.Get_Into_Time (Pos_TM) = Time_4);

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 5);
            pragma Assert (St.Get_Into_String (Pos_Str) = "no");
            pragma Assert (St.Get_Into_Long_Long_Integer (Pos_LL) = 10_000_000_004);
            pragma Assert (St.Get_Into_Long_Float (Pos_LF) = SOCI.DB_Long_Float (0.625));
            pragma Assert (St.Get_Into_Time (Pos_TM) = Time_5);

            Got_Data := St.Fetch;
            pragma Assert (Got_Data);
            pragma Assert (St.Get_Into_State (Pos_Id) = SOCI.Data_Not_Null);
            pragma Assert (St.Get_Into_Integer (Pos_Id) = 6);
            pragma Assert (St.Get_Into_State (Pos_Str) = SOCI.Data_Null);
            pragma Assert (St.Get_Into_State (Pos_LL) = SOCI.Data_Null);
            pragma Assert (St.Get_Into_State (Pos_LF) = SOCI.Data_Null);
            pragma Assert (St.Get_Into_State (Pos_TM) = SOCI.Data_Null);

            Got_Data := St.Fetch;
            pragma Assert (not Got_Data);
         end;

         SQL.Execute ("drop table soci_test");
      end;
   end Test_10;

   procedure Test_11 (Connection_String : in String) is

      --  test parameters:
      Pool_Size : constant := 3;
      Number_Of_Tasks : constant := 10;
      Iterations_Per_Task : constant := 1000;

      type Small_Integer is mod 20;
      package My_Random is new Ada.Numerics.Discrete_Random (Small_Integer);
      Rand : My_Random.Generator;

      Pool : SOCI.Connection_Pool (Pool_Size);

   begin
      Ada.Text_IO.Put_Line ("testing connection pool");

      My_Random.Reset (Rand);

      for I in 1 .. Pool_Size loop
         Pool.Open (I, Connection_String);
      end loop;

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         SQL.Execute ("create table soci_test ( id integer )");
      end;

      declare

         task type Worker;
         task body Worker is
         begin

            for I in 1 .. Iterations_Per_Task loop
               declare
                  SQL : SOCI.Session;
                  V : Small_Integer;
               begin
                  Pool.Lease (SQL);

                  V := My_Random.Random (Rand);
                  SQL.Execute ("insert into soci_test (id) values (" &
                                 Small_Integer'Image (V) & ")");
               end;
            end loop;
         exception
            when others =>
               Ada.Text_IO.Put_Line ("An exception occured in the worker task.");
         end Worker;

         W : array (1 .. Number_Of_Tasks) of Worker;

      begin
         Ada.Text_IO.Put_Line ("--> waiting for the tasks to complete (might take a while)");
      end;

      declare
         SQL : SOCI.Session := SOCI.Make_Session (Connection_String);
      begin
         SQL.Execute ("drop table soci_test");
      end;
   end Test_11;

begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Expecting one argument: connection string");
      return;
   end if;

   declare
      Connection_String : String := Ada.Command_Line.Argument (1);
   begin
      Ada.Text_IO.Put_Line ("testing with " & Connection_String);

      SOCI.PostgreSQL.Register_Factory_PostgreSQL;

      Test_1 (Connection_String);
      Test_2 (Connection_String);
      Test_3 (Connection_String);
      Test_4 (Connection_String);
      Test_5 (Connection_String);
      Test_6 (Connection_String);
      Test_7 (Connection_String);
      Test_8 (Connection_String);
      Test_9 (Connection_String);
      Test_10 (Connection_String);
      Test_11 (Connection_String);
   end;
end PostgreSQL_Test;