]> www.average.org Git - pulsecounter.git/blobdiff - linux/dbstore.c
separate dbstore module
[pulsecounter.git] / linux / dbstore.c
diff --git a/linux/dbstore.c b/linux/dbstore.c
new file mode 100644 (file)
index 0000000..edd4431
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <time.h>
+
+#include "dbstore.h"
+
+int dbstore(uint8_t which, uint32_t val)
+{
+       time_t t;
+       int i;
+       struct tm tm;
+       char buf[64];
+       char tstr[64];
+       char *table = (which == 1) ? "coldcnt" : "hotcnt";
+
+       t = time(NULL);
+       (void)gmtime_r(&t, &tm);
+       (void)strftime(tstr, sizeof(tstr), "%Y-%m-%d %H:%M:%S", &tm);
+       printf("insert into %s values (\"%s\",%u);\n", table, tstr, val);
+       return 0;
+}