3 with Ada
.Task_Attributes
;
17 entry Start
(Id
: in Positive);
21 entry Start
(Id
: in Positive);
24 type TLS_DBH
is record
25 Handle
: access DB
.Handle
'Class;
29 type TLS_DBH_Access
is access all TLS_DBH
;
31 Null_DBH
: constant TLS_DBH
:=
32 TLS_DBH
'(Handle => null, Connected => False);
34 DB_Path : constant String := DB.SQLite.In_Memory_Database;
37 new Task_Attributes (Attribute => TLS_DBH, Initial_Value => Null_DBH);
39 procedure Connect (DBH : in TLS_DBH_Access);
40 -- Connects to the database if needed
46 procedure Connect (DBH : in TLS_DBH_Access) is
48 if not DBH.Connected then
49 DBH.Handle := new DB.SQLite.Handle;
50 DBH.Handle.Connect (DB_Path);
51 DBH.Connected := True;
52 DBH_TLS.Set_Value (DBH.all);
61 DBH : constant TLS_DBH_Access := TLS_DBH_Access (DBH_TLS.Reference);
63 Max_Insert : constant Positive := 10000;
65 Current : Positive := 1;
69 accept Start (Id : in Positive) do
72 -- Insert a first element
74 SQL : constant String := "insert into test (counter, tid) values ("
75 & Positive'Image (Current) & ", " & Positive'Image (Task_Id) & ")";
77 DBH.Handle.Execute (SQL);
79 Current := Current + 1;
83 exit when Current = Max_Insert;
86 SQL : constant String := "insert into test (counter, tid) values ("
87 & Positive'Image (Current) & ", "
88 & Positive'Image (Task_Id) & ")";
90 DBH.Handle.Execute (SQL);
92 Current := Current + 1;
96 when E : others => Text_IO.Put_Line (Exception_Information (E));
104 DBH : constant TLS_DBH_Access := TLS_DBH_Access (DBH_TLS.Reference);
106 Last : Positive := 1;
108 accept Start (Id : in Positive) do
110 Text_IO.Put_Line ("Reader " & Positive'Image (Task_Id) & " start");
115 Iter : DB.SQLite.Iterator;
116 Line : DB.String_Vectors.Vector;
118 DBH.Handle.Prepare_Select
119 (Iter, "select max(counter), tid from test");
121 Iter.Get_Line (Line);
123 (DB.String_Vectors.Element (Line, 1)) = 9999 then
124 Text_IO.Put_Line ("Reader "
125 & Positive'Image (Task_Id)
126 & " Stop successfully");
132 (DB.String_Vectors.Element (Line, 1)) /= Last then
133 Last := Positive'Value (DB.String_Vectors.Element (Line, 1));
135 ("Reader " & Positive'Image (Task_Id) & " see "
136 & DB.String_Vectors.Element (Line, 1) & " write by "
137 & DB.String_Vectors.Element (Line, 2));
145 when E : others => Text_IO.Put_Line (Exception_Information (E));
149 Morzhol.Logs.Set (Morzhol.Logs.Information, False);
150 Morzhol.Logs.Set (Morzhol.Logs.Warnings, False);
151 Morzhol.Logs.Set (Morzhol.Logs.Error, True); -- show errors
154 DBH : constant TLS_DBH_Access := TLS_DBH_Access (DBH_TLS.Reference);
158 ("create table test ('Counter
' boolean, 'tid
' integer)");