UI: SqliteDb: Add vacuum().

This commit is contained in:
Nodir Temirkhodjaev 2021-05-13 15:30:58 +03:00
parent 8efd9449bf
commit d2dba3b8c1
5 changed files with 22 additions and 19 deletions

View File

@ -96,6 +96,11 @@ bool SqliteDb::detach(const QString &schemaName)
return ok;
}
bool SqliteDb::vacuum()
{
return execute("VACUUM;");
}
bool SqliteDb::execute(const char *sql)
{
return sqlite3_exec(m_db, sql, nullptr, nullptr, nullptr) == SQLITE_OK;

View File

@ -51,6 +51,8 @@ public:
bool attach(const QString &schemaName, const QString &filePath = QString());
bool detach(const QString &schemaName);
bool vacuum();
bool execute(const char *sql);
bool executeStr(const QString &sql);

View File

@ -208,8 +208,8 @@ bool StatManager::updateTrafDay(qint64 unixTime)
bool StatManager::clearTraffic()
{
sqliteDb()->beginTransaction();
sqliteDb()->execute(StatSql::sqlClearTraffic);
sqliteDb()->execute(StatSql::sqlVacuum);
sqliteDb()->execute(StatSql::sqlDeleteAllTraffic);
sqliteDb()->vacuum();
sqliteDb()->commitTransaction();
clearAppIdCache();
@ -410,7 +410,7 @@ bool StatManager::deleteConnAll()
sqliteDb()->stmt(StatSql::sqlDeleteAllConnBlock) },
sqliteDb()->stmt(StatSql::sqlSelectDeletedAllConnAppList));
sqliteDb()->execute(StatSql::sqlVacuum);
sqliteDb()->vacuum();
sqliteDb()->commitTransaction();

View File

@ -158,6 +158,17 @@ const char *const StatSql::sqlResetAppTrafTotals =
"UPDATE traffic_app"
" SET traf_time = ?1, in_bytes = 0, out_bytes = 0;";
const char *const StatSql::sqlDeleteAllTraffic =
"DELETE FROM traffic_app;"
"DELETE FROM traffic_app_hour;"
"DELETE FROM traffic_app_day;"
"DELETE FROM traffic_app_month;"
"DELETE FROM traffic_hour;"
"DELETE FROM traffic_day;"
"DELETE FROM traffic_month;"
"DELETE FROM app WHERE ("
" SELECT 1 FROM conn c WHERE c.app_id = app.app_id LIMIT 1) IS NULL;";
const char *const StatSql::sqlInsertConn =
"INSERT INTO conn(app_id, conn_time, process_id, inbound, blocked,"
" ip_proto, local_port, remote_port, local_ip, remote_ip)"
@ -191,16 +202,3 @@ const char *const StatSql::sqlSelectDeletedAllConnAppList =
"SELECT t.app_id, t.path FROM app t"
" LEFT JOIN traffic_app ta ON ta.app_id = t.app_id"
" WHERE ta.app_id IS NULL;";
const char *const StatSql::sqlClearTraffic =
"DELETE FROM traffic_app;"
"DELETE FROM traffic_app_hour;"
"DELETE FROM traffic_app_day;"
"DELETE FROM traffic_app_month;"
"DELETE FROM traffic_hour;"
"DELETE FROM traffic_day;"
"DELETE FROM traffic_month;"
"DELETE FROM app WHERE ("
" SELECT 1 FROM conn c WHERE c.app_id = app.app_id LIMIT 1) IS NULL;";
const char *const StatSql::sqlVacuum = "VACUUM;";

View File

@ -66,6 +66,7 @@ public:
static const char *const sqlSelectDeletedStatAppList;
static const char *const sqlResetAppTrafTotals;
static const char *const sqlDeleteAllTraffic;
static const char *const sqlInsertConn;
static const char *const sqlInsertConnBlock;
@ -79,9 +80,6 @@ public:
static const char *const sqlDeleteAllConn;
static const char *const sqlDeleteAllConnBlock;
static const char *const sqlSelectDeletedAllConnAppList;
static const char *const sqlClearTraffic;
static const char *const sqlVacuum;
};
#endif // STATSQL_H