fort/src/ui/db/databasesql.cpp

285 lines
8.6 KiB
C++
Raw Normal View History

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("
2017-12-08 07:18:37 +00:00
" 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 =
2017-12-08 07:18:37 +00:00
"SELECT app_id FROM app WHERE path = ?1;"
2017-12-04 13:55:03 +00:00
;
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::sqlDeleteAppId =
"DELETE FROM app WHERE app_id = ?1;"
;
2017-12-05 05:06:15 +00:00
const char * const DatabaseSql::sqlSelectAppPaths =
2017-12-08 07:18:37 +00:00
"SELECT app_id, path FROM app ORDER BY creat_time;"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafAppHour =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_app_hour(app_id, traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?4, ?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafAppDay =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_app_day(app_id, traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?4, ?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafAppMonth =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_app_month(app_id, traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?4, ?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafHour =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_hour(traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafDay =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_day(traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlInsertTrafMonth =
2017-12-06 09:45:31 +00:00
"INSERT INTO traffic_month(traf_time, in_bytes, out_bytes)"
2017-12-09 09:38:32 +00:00
" VALUES(?1, ?2, ?3);"
2017-12-04 13:55:03 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafAppHour =
2017-12-04 13:55:03 +00:00
"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
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafAppDay =
2017-12-04 13:55:03 +00:00
"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
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafAppMonth =
2017-12-04 13:55:03 +00:00
"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
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafAppTotal =
2017-12-09 09:38:32 +00:00
"UPDATE app"
" SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3"
" WHERE app_id = ?4 and 0 != ?1;"
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafHour =
2017-12-04 13:55:03 +00:00
"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
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafDay =
2017-12-04 13:55:03 +00:00
"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
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlUpdateTrafMonth =
2017-12-04 13:55:03 +00:00
"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
2017-12-06 13:40:58 +00:00
const char * const DatabaseSql::sqlSelectMinTrafAppHour =
"SELECT min(traf_time) FROM traffic_app_hour"
" WHERE app_id = ?1;"
;
const char * const DatabaseSql::sqlSelectMinTrafAppDay =
"SELECT min(traf_time) FROM traffic_app_day"
" WHERE app_id = ?1;"
;
const char * const DatabaseSql::sqlSelectMinTrafAppMonth =
"SELECT min(traf_time) FROM traffic_app_month"
" WHERE app_id = ?1;"
;
2017-12-08 07:18:37 +00:00
const char * const DatabaseSql::sqlSelectMinTrafAppTotal =
"SELECT traf_time FROM app WHERE app_id = ?1;"
;
2017-12-06 13:40:58 +00:00
const char * const DatabaseSql::sqlSelectMinTrafHour =
"SELECT min(traf_time) FROM traffic_hour;"
;
const char * const DatabaseSql::sqlSelectMinTrafDay =
"SELECT min(traf_time) FROM traffic_app_day;"
;
const char * const DatabaseSql::sqlSelectMinTrafMonth =
"SELECT min(traf_time) FROM traffic_app_month;"
;
2017-12-08 07:18:37 +00:00
const char * const DatabaseSql::sqlSelectMinTrafTotal =
"SELECT min(traf_time) FROM app;"
;
2017-12-06 13:40:58 +00:00
const char * const DatabaseSql::sqlSelectTrafAppHour =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
2017-12-06 13:40:58 +00:00
" FROM traffic_app_hour"
2017-12-08 07:18:37 +00:00
" WHERE app_id = ?2 and traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafAppDay =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
2017-12-06 13:40:58 +00:00
" FROM traffic_app_day"
2017-12-08 07:18:37 +00:00
" WHERE app_id = ?2 and traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafAppMonth =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
2017-12-06 13:40:58 +00:00
" FROM traffic_app_month"
2017-12-08 07:18:37 +00:00
" WHERE app_id = ?2 and traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafAppTotal =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
" FROM app"
" WHERE app_id = ?2 and 0 != ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafHour =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
" FROM traffic_hour WHERE traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafDay =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
" FROM traffic_day WHERE traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafMonth =
2017-12-08 07:18:37 +00:00
"SELECT in_bytes, out_bytes"
" FROM traffic_month WHERE traf_time = ?1;"
2017-12-06 13:40:58 +00:00
;
const char * const DatabaseSql::sqlSelectTrafTotal =
2017-12-08 07:18:37 +00:00
"SELECT sum(in_bytes), sum(out_bytes)"
" FROM app WHERE 0 != ?1;"
2017-12-06 13:40:58 +00:00
;
2017-12-11 06:05:49 +00:00
const char * const DatabaseSql::sqlDeleteTrafAppHour =
"DELETE FROM traffic_app_hour"
" WHERE traf_time < ?1"
" and app_id in (SELECT app_id FROM app);"
;
const char * const DatabaseSql::sqlDeleteTrafAppDay =
"DELETE FROM traffic_app_day"
" WHERE traf_time < ?1"
" and app_id in (SELECT app_id FROM app);"
;
const char * const DatabaseSql::sqlDeleteTrafAppMonth =
"DELETE FROM traffic_app_month"
" WHERE traf_time < ?1"
" and app_id in (SELECT app_id FROM app);"
;
const char * const DatabaseSql::sqlDeleteTrafHour =
"DELETE FROM traffic_hour WHERE traf_time < ?1;"
;
const char * const DatabaseSql::sqlDeleteTrafDay =
"DELETE FROM traffic_day WHERE traf_time < ?1;"
;
const char * const DatabaseSql::sqlDeleteTrafMonth =
"DELETE FROM traffic_month WHERE traf_time < ?1;"
;
const char * const DatabaseSql::sqlDeleteAppTrafHour =
"DELETE FROM traffic_app_hour"
" WHERE app_id = ?1;"
;
const char * const DatabaseSql::sqlDeleteAppTrafDay =
"DELETE FROM traffic_app_day"
" WHERE app_id = ?1;"
;
const char * const DatabaseSql::sqlDeleteAppTrafMonth =
"DELETE FROM traffic_app_month"
" WHERE app_id = ?1;"
;
const char * const DatabaseSql::sqlResetAppTrafTotals =
"UPDATE app SET traf_time = ?1, in_bytes = 0, out_bytes = 0;"
;