2017-12-04 13:55:03 +00:00
|
|
|
#include "databasesql.h"
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlPragmas =
|
|
|
|
"PRAGMA locking_mode=EXCLUSIVE;"
|
|
|
|
"PRAGMA journal_mode=WAL;"
|
|
|
|
"PRAGMA synchronous=NORMAL;"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlCreateTables =
|
|
|
|
"CREATE TABLE app("
|
|
|
|
" id INTEGER PRIMARY KEY,"
|
2017-12-05 03:24:48 +00:00
|
|
|
" path TEXT UNIQUE NOT NULL,"
|
2017-12-05 05:06:15 +00:00
|
|
|
" creat_time INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER NOT NULL,"
|
2017-12-05 03:24:48 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL"
|
2017-12-04 13:55:03 +00:00
|
|
|
");"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_app_hour("
|
|
|
|
" app_id INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER NOT NULL,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" PRIMARY KEY (app_id, traf_time)"
|
2017-12-04 13:55:03 +00:00
|
|
|
") WITHOUT ROWID;"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_app_day("
|
|
|
|
" app_id INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER NOT NULL,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" PRIMARY KEY (app_id, traf_time)"
|
2017-12-04 13:55:03 +00:00
|
|
|
") WITHOUT ROWID;"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_app_month("
|
|
|
|
" app_id INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER NOT NULL,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL,"
|
2017-12-06 09:45:31 +00:00
|
|
|
" PRIMARY KEY (app_id, traf_time)"
|
2017-12-04 13:55:03 +00:00
|
|
|
") WITHOUT ROWID;"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_hour("
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER PRIMARY KEY,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL"
|
|
|
|
") WITHOUT ROWID;"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_day("
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER PRIMARY KEY,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL"
|
|
|
|
") WITHOUT ROWID;"
|
|
|
|
|
|
|
|
"CREATE TABLE traffic_month("
|
2017-12-06 09:45:31 +00:00
|
|
|
" traf_time INTEGER PRIMARY KEY,"
|
2017-12-04 13:55:03 +00:00
|
|
|
" in_bytes INTEGER NOT NULL,"
|
|
|
|
" out_bytes INTEGER NOT NULL"
|
|
|
|
") WITHOUT ROWID;"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlSelectAppId =
|
|
|
|
"SELECT id FROM app WHERE path = ?1;"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertAppId =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO app(path, creat_time, traf_time, in_bytes, out_bytes)"
|
2017-12-05 05:06:15 +00:00
|
|
|
" VALUES(?1, ?2, ?3, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlSelectAppPaths =
|
|
|
|
"SELECT path FROM app ORDER BY creat_time;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficAppHour =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_app_hour(app_id, traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?2, ?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficAppDay =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_app_day(app_id, traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?2, ?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficAppMonth =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_app_month(app_id, traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?2, ?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficHour =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_hour(traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficDay =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_day(traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlInsertTrafficMonth =
|
2017-12-06 09:45:31 +00:00
|
|
|
"INSERT INTO traffic_month(traf_time, in_bytes, out_bytes)"
|
2017-12-04 13:55:03 +00:00
|
|
|
" VALUES(?1, 0, 0);"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficAppHour =
|
|
|
|
"UPDATE traffic_app_hour"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE app_id = ?4 and traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficAppDay =
|
|
|
|
"UPDATE traffic_app_day"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE app_id = ?4 and traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficAppMonth =
|
|
|
|
"UPDATE traffic_app_month"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE app_id = ?4 and traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficHour =
|
|
|
|
"UPDATE traffic_hour"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficDay =
|
|
|
|
"UPDATE traffic_day"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficMonth =
|
|
|
|
"UPDATE traffic_month"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
2017-12-06 09:45:31 +00:00
|
|
|
" WHERE traf_time = ?1;"
|
2017-12-04 13:55:03 +00:00
|
|
|
;
|
2017-12-05 03:24:48 +00:00
|
|
|
|
|
|
|
const char * const DatabaseSql::sqlUpdateTrafficAppTotal =
|
|
|
|
"UPDATE app"
|
|
|
|
" SET in_bytes = in_bytes + ?2,"
|
|
|
|
" out_bytes = out_bytes + ?3"
|
|
|
|
" WHERE id = ?1;"
|
|
|
|
;
|