lithium3

Check-in [eee45bf240]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:lithium-access_log: refactor SQL table creation into a procedure
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: eee45bf240f6bbeb7e72c77a584e81b0f68b0a18
User & Date: nat 2017-01-23 22:38:32
Context
2017-01-24
21:54
lithium-access_log: create dedicated tables for string values check-in: 126306b9f8 user: nat tags: trunk
2017-01-23
22:38
lithium-access_log: refactor SQL table creation into a procedure check-in: eee45bf240 user: nat tags: trunk
2017-01-22
20:02
lithium-access_log: improve logging in Run_SQL in multiple instances check-in: 07c5bc74ff user: nat tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/lithium-access_log.adb.

95
96
97
98
99
100
101







102
103
104
105
106
107
108
     (Stmt : in out SQLite3.SQLite3_Statement;
      Values : in Log_Entry);

   procedure Initialize
     (Handle : in out SQLite3.SQLite3_DB;
      Name : in String);








   generic
      type Input_Type (<>) is limited private;
      with procedure Bind
        (Stmt : in out SQLite3.SQLite3_Statement;
         Input : in Input_Type) is <>;
   procedure Run_SQL
     (Handle : in SQLite3.SQLite3_DB;







>
>
>
>
>
>
>







95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
     (Stmt : in out SQLite3.SQLite3_Statement;
      Values : in Log_Entry);

   procedure Initialize
     (Handle : in out SQLite3.SQLite3_DB;
      Name : in String);

   procedure Run_Simple_SQL
     (Handle : in SQLite3.SQLite3_DB;
      SQL_String : in String;
      Name : in String);
      --  Run a simple one-time SQL query, without error handling
      --  besides throwing SQLite_Error exceptions.

   generic
      type Input_Type (<>) is limited private;
      with procedure Bind
        (Stmt : in out SQLite3.SQLite3_Statement;
         Input : in Input_Type) is <>;
   procedure Run_SQL
     (Handle : in SQLite3.SQLite3_DB;
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

   procedure Initialize
     (Handle : in out SQLite3.SQLite3_DB;
      Name : in String)
   is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
      Stmt : SQLite3.SQLite3_Statement;
   begin
      SQLite3.Open (Name, Handle, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Critical,
            "Unable to open """ & Name & """: "
            & SQLite3.Error_Code'Image (Status));
         raise SQLite_Error;
      end if;





















      SQLite3.Prepare (Handle, Create_SQL, Stmt, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Error,
            "Unable to prepare create statement: "
            & SQLite3.Error_Code'Image (Status)
            & ' ' & SQLite3.Error_Message (Handle));
         SQLite3.Close (Handle, Status);
         raise SQLite_Error;
      end if;

      loop
         SQLite3.Step (Stmt, Status);
         exit when Status = SQLite3.SQLITE_DONE;

         if Status /= SQLite3.SQLITE_ROW then
            Natools.Web.Log
              (Natools.Web.Severities.Error,

               "Unable to create: " & SQLite3.Error_Code'Image (Status)
               & ' ' & SQLite3.Error_Message (Handle));
            SQLite3.Close (Handle, Status);
            raise SQLite_Error;
         end if;
      end loop;

      SQLite3.Finish (Stmt, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Error,
            "Unable to finish create statement: "
            & SQLite3.Error_Code'Image (Status)
            & ' ' & SQLite3.Error_Message (Handle));
         SQLite3.Close (Handle, Status);
         raise SQLite_Error;
      end if;
   end Initialize;


   procedure Run_SQL
     (Handle : in SQLite3.SQLite3_DB;
      Stmt : in out SQLite3.SQLite3_Statement;
      Stmt_Ready : in out Boolean;
      Input : in Input_Type;







<











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|




|


<










>
|

<









|


<


|







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

   procedure Initialize
     (Handle : in out SQLite3.SQLite3_DB;
      Name : in String)
   is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;

   begin
      SQLite3.Open (Name, Handle, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Critical,
            "Unable to open """ & Name & """: "
            & SQLite3.Error_Code'Image (Status));
         raise SQLite_Error;
      end if;

      Create_Tables :
      begin
         Run_Simple_SQL (Handle, Create_SQL, "create");
      exception
         when SQLite_Error =>
            SQLite3.Close (Handle, Status);
            raise;
      end Create_Tables;
   end Initialize;


   procedure Run_Simple_SQL
     (Handle : in SQLite3.SQLite3_DB;
      SQL_String : in String;
      Name : in String)
   is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
      Stmt : SQLite3.SQLite3_Statement;
   begin
      SQLite3.Prepare (Handle, SQL_String, Stmt, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Error,
            "Unable to prepare " & Name & " statement: "
            & SQLite3.Error_Code'Image (Status)
            & ' ' & SQLite3.Error_Message (Handle));

         raise SQLite_Error;
      end if;

      loop
         SQLite3.Step (Stmt, Status);
         exit when Status = SQLite3.SQLITE_DONE;

         if Status /= SQLite3.SQLITE_ROW then
            Natools.Web.Log
              (Natools.Web.Severities.Error,
               "Unable to run " & Name & ": "
               & SQLite3.Error_Code'Image (Status)
               & ' ' & SQLite3.Error_Message (Handle));

            raise SQLite_Error;
         end if;
      end loop;

      SQLite3.Finish (Stmt, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Error,
            "Unable to finish " & Name & " statement: "
            & SQLite3.Error_Code'Image (Status)
            & ' ' & SQLite3.Error_Message (Handle));

         raise SQLite_Error;
      end if;
   end Run_Simple_SQL;


   procedure Run_SQL
     (Handle : in SQLite3.SQLite3_DB;
      Stmt : in out SQLite3.SQLite3_Statement;
      Stmt_Ready : in out Boolean;
      Input : in Input_Type;