]> www.average.org Git - loctrkd.git/blobdiff - gps303/evstore.py
initial storage service
[loctrkd.git] / gps303 / evstore.py
index 1b1ae2dc398f29063ffcddf2716da7b2424de01c..b1950210555adb532e0cf645941857ca95bc3131 100644 (file)
@@ -1,16 +1,14 @@
-from logging import getLogger
 from sqlite3 import connect
 
 __all__ = ("initdb", "stow")
 
-log = getLogger("gps303")
-
 DB = None
 
 SCHEMA = """create table if not exists events (
     timestamp real not null,
     imei text,
     clntaddr text not null,
+    length int,
     proto int not null,
     payload blob
 )"""
@@ -22,19 +20,20 @@ def initdb(dbname):
     DB.execute(SCHEMA)
 
 
-def stow(clntaddr, timestamp, imei, proto, payload):
+def stow(clntaddr, timestamp, imei, length, proto, payload):
     assert DB is not None
     parms = dict(
         zip(
-            ("clntaddr", "timestamp", "imei", "proto", "payload"),
-            (str(clntaddr), timestamp, imei, proto, payload),
+            ("clntaddr", "timestamp", "imei", "length", "proto", "payload"),
+            (str(clntaddr), timestamp, imei, length, proto, payload),
         )
     )
-    log.debug("inserting %s", parms)
     DB.execute(
         """insert or ignore into events
-                (timestamp, imei, clntaddr, proto, payload)
-                values (:timestamp, :imei, :clntaddr, :proto, :payload)""",
+                (timestamp, imei, clntaddr, length, proto, payload)
+                values
+                (:timestamp, :imei, :clntaddr, :length, :proto, :payload)
+        """,
         parms,
     )
     DB.commit()