lithium3

Check-in [16ac076d4f]
Login

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

Overview
Comment:lithium-access_log: insert string values into the dedicated tables
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 16ac076d4f54aa56b10f4e156b89755a869a1adc
User & Date: nat 2017-01-25 20:18:34
Context
2017-01-26
20:46
lithium-access_log: update the main table to refer to the string tables check-in: c4f1cd36e1 user: nat tags: trunk
2017-01-25
20:18
lithium-access_log: insert string values into the dedicated tables check-in: 16ac076d4f user: nat tags: trunk
2017-01-24
21:54
lithium-access_log: create dedicated tables for string values check-in: 126306b9f8 user: nat tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/lithium-access_log.adb.

90
91
92
93
94
95
96






97
98
99
100
101
102
103
     & "user_agent, cookies, build_time, export_time, "
     & "host, real_ip, forwarded_for) "
     & "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14);";

   procedure Bind
     (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;







>
>
>
>
>
>







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
     & "user_agent, cookies, build_time, export_time, "
     & "host, real_ip, forwarded_for) "
     & "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14);";

   procedure Bind
     (Stmt : in out SQLite3.SQLite3_Statement;
      Values : in Log_Entry);
      --  Bind a log entry to the main insert statement

   procedure Bind
     (Stmt : in out SQLite3.SQLite3_Statement;
      Value : in String);
      --  Bind a string value to a table-specific insert statement

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

   procedure Run_Simple_SQL
     (Handle : in SQLite3.SQLite3_DB;
211
212
213
214
215
216
217



















218
219
220
221
222
223
224
      Bind (10, Interfaces.C.double (Values.Build_Time), "build time");
      Bind (11, Interfaces.C.double (Values.Export_Time), "export time");
      Bind (12, Values.Strings (Host), "host");
      Bind (13, Values.Strings (Real_IP), "real IP");
      Bind (14, Values.Strings (Forwarded_For), "forwarded for");
   end Bind;





















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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
      Bind (10, Interfaces.C.double (Values.Build_Time), "build time");
      Bind (11, Interfaces.C.double (Values.Export_Time), "export time");
      Bind (12, Values.Strings (Host), "host");
      Bind (13, Values.Strings (Real_IP), "real IP");
      Bind (14, Values.Strings (Forwarded_For), "forwarded for");
   end Bind;


   procedure Bind
     (Stmt : in out SQLite3.SQLite3_Statement;
      Value : in String)
   is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
   begin
      SQLite3.Bind (Stmt, 1, Value, Status);

      if Status /= SQLite3.SQLITE_OK then
         Natools.Web.Log
           (Natools.Web.Severities.Error,
            "Unable to bind string value to statement: "
            & SQLite3.Error_Code'Image (Status));
         raise SQLite_Error;
      end if;
   end Bind;


   procedure Initialize
     (Handle : in out SQLite3.SQLite3_DB;
      Name : in String)
   is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
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

   -----------------
   -- Worker Task --
   -----------------

   procedure Run_SQL_Main is new Run_SQL (Log_Entry);



   task body Worker is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
      Current : Extended_Log_Entry;
      Handle : SQLite3.SQLite3_DB;
      Stmt : SQLite3.SQLite3_Statement;
      Stmt_Ready : Boolean := False;



   begin
      select
         accept Run (Values : in Log_Entry) do
            Current := Values;
         end Run;
      or
         terminate;
      end select;

      pragma Assert (not Current.Is_Empty);

      Initialize (Handle, "access.dat");
      SQLite3.Busy_Timeout (Handle, 60_000, Status);

      Main_Loop :
      loop











         Run_SQL_Main
           (Handle, Stmt, Stmt_Ready, Current, Insert_SQL, "insert");

         Queue.Next (Current);

         if Current.Is_Empty then
            select
               accept Run (Values : in Log_Entry) do
                  Current := Values;







>
>







>
>
>
















>
>
>
>
>
>
>
>
>
>
>

|







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

   -----------------
   -- Worker Task --
   -----------------

   procedure Run_SQL_Main is new Run_SQL (Log_Entry);

   procedure Run_SQL_String is new Run_SQL (String);

   task body Worker is
      use type SQLite3.Error_Code;
      Status : SQLite3.Error_Code;
      Current : Extended_Log_Entry;
      Handle : SQLite3.SQLite3_DB;
      Stmt : SQLite3.SQLite3_Statement;
      Stmt_Ready : Boolean := False;
      String_Stmt : array (String_Tables.Enum) of SQLite3.SQLite3_Statement;
      String_Stmt_Ready : array (String_Tables.Enum) of Boolean
        := (others => False);
   begin
      select
         accept Run (Values : in Log_Entry) do
            Current := Values;
         end Run;
      or
         terminate;
      end select;

      pragma Assert (not Current.Is_Empty);

      Initialize (Handle, "access.dat");
      SQLite3.Busy_Timeout (Handle, 60_000, Status);

      Main_Loop :
      loop
         Run_String_Inserts :
         for T in String_Tables.Enum loop
            Run_SQL_String
              (Handle,
               String_Stmt (T),
               String_Stmt_Ready (T),
               To_String (Current.Strings (T)),
               "INSERT OR IGNORE INTO " & Table_Name (T) & " VALUES (?1);",
               Table_Name (T) & " insert");
         end loop Run_String_Inserts;

         Run_SQL_Main
           (Handle, Stmt, Stmt_Ready, Current, Insert_SQL, "main insert");

         Queue.Next (Current);

         if Current.Is_Empty then
            select
               accept Run (Values : in Log_Entry) do
                  Current := Values;