Ticket #139: main3.adb

File main3.adb, 1.4 KB (added by Maxim Reznik, 9 years ago)
Line 
1with Ada.Wide_Wide_Text_IO;
2
3with League.Strings;
4with League.Holders.Floats;
5with League.Holders.Integers;
6--with Matreshka.Internals.SQL_Drivers.PostgreSQL.Factory;
7with Matreshka.Internals.SQL_Drivers.SQLite3.Factory;
8with SQL.Databases;
9with SQL.Queries;
10
11procedure Main is
12
13 function "+"
14 (Item : Wide_Wide_String) return League.Strings.Universal_String
15 renames League.Strings.To_Universal_String;
16
17 -- PostgreSQL
18
19-- DB_Driver : constant League.Strings.Universal_String := +"POSTGRESQL";
20-- DB_Options : constant League.Strings.Universal_String := +"";
21 -- Example: +"user='me' password='my' dbname='db'"
22
23 -- SQLite3
24
25 DB_Driver : constant League.Strings.Universal_String := +"SQLITE3";
26 DB_Options : constant League.Strings.Universal_String := +"test.db";
27
28 D : aliased SQL.Databases.SQL_Database
29 := SQL.Databases.Create (DB_Driver, DB_Options);
30
31begin
32 D.Open;
33
34 declare
35 Q : SQL.Queries.SQL_Query := D.Query;
36
37 begin
38 Q.Prepare
39 (+"CREATE TABLE point (x INTEGER, y CHARACTER VARYING, z FLOAT)");
40 Q.Execute;
41 end;
42
43 declare
44 Q : SQL.Queries.SQL_Query := D.Query;
45
46 begin
47 Q.Prepare (+"INSERT INTO point (x, y, z) VALUES (:x, :y, :z)");
48 Q.Bind_Value (+":z", League.Holders.Empty_Holder);
49 Q.Bind_Value (+":y", League.Holders.To_Holder (+"xyz"));
50 Q.Bind_Value (+":x", League.Holders.Integers.To_Holder (5));
51 Q.Execute;
52 end;
53end Main;