/usr/share/doc/libgnadesqlite3-2-dev/examples/demo.adb is in libgnadesqlite3-2-dev 1.6.2-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | with Ada.Command_Line; use Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with GNU.DB.SQLite3; use GNU.DB.SQLite3;
with GNU.DB.Support.String_Tables;
with GNU.DB.Support.String_Vectors;
procedure Demo
is
use GNU.DB.Support;
function List
(Argc : Integer;
Argv : String_Vectors.Vector;
ColumnNames : String_Vectors.Vector)
return Return_Value;
function List
(Argc : Integer;
Argv : String_Vectors.Vector;
ColumnNames : String_Vectors.Vector)
return Return_Value
is begin
for I in Natural'(0) .. Natural (Argc) loop
Put_Line (ColumnNames.Element (I) & ": " & Argv.Element (I));
end loop;
return SQLITE_OK;
end List;
Db : aliased GNU.DB.SQLite3.Object;
Table : constant Table_Reference := new String_Tables.Vector;
Row_Cur : String_Tables.Cursor;
Col_Cur : String_Vectors.Cursor;
Result : Return_Value;
procedure Recreate_Db (File_Name : in String);
procedure Recreate_Db (File_Name : in String)
is
use Ada.Directories;
begin
if Exists (File_Name) then
Delete_File (File_Name);
end if;
Put_Line ("Opening database " & File_Name);
Result := Db.Open (File_Name);
end Recreate_Db;
use type String_Tables.Cursor;
begin
if Argument_Count = 0 then
Recreate_Db ("demo.db");
else
Recreate_Db (Argument (1));
end if;
if Result /= SQLITE_OK then
Put_Line ("error opening database");
Set_Exit_Status (Failure);
return;
end if;
Put_Line ("Create a table called DEMO with fields bla, ble and blo");
Db.Exec ("CREATE TABLE demo(bla INT, ble INT, blo INT);");
Db.Exec ("CREATE TABLE tare(Name String, Time Float, Data BLOB);");
New_Line;
Put_Line ("Insert 10 rows with (<n>, 200, 300)");
for I in 1 .. 10 loop
Db.Exec ("INSERT INTO demo VALUES(" & I'Img & ", 200, 300);");
end loop;
New_Line;
Put_Line ("Select everything in table DEMO");
New_Line;
Put_Line ("1: Using get_table");
Result := Db.Get_Table ("SELECT * FROM demo;", Table);
Row_Cur := Table.First;
loop
exit when Row_Cur = String_Tables.No_Element;
declare
Row : String_Vectors.Vector renames
Table.Element (String_Tables.To_Index (Row_Cur));
use type String_Vectors.Cursor;
begin
Col_Cur := String_Vectors.First (Row);
loop
exit when Col_Cur = String_Vectors.No_Element;
Put (Row.Element (String_Vectors.To_Index (Col_Cur)));
Put (", ");
String_Vectors.Next (Col_Cur);
end loop;
end;
New_Line;
String_Tables.Next (Row_Cur);
end loop;
New_Line;
Put_Line ("2: Using exec_with_callback; bla > 4");
Db.Exec ("SELECT * FROM demo where bla > 4;", List'Unrestricted_Access);
New_Line;
Db.Close;
end Demo;
|