From 87d85c60f37006af8c21f0dbf14e0246bd179a5e Mon Sep 17 00:00:00 2001 From: trilader Date: Sun, 22 Nov 2020 21:29:45 +0100 Subject: [PATCH] Move more database stuff out of the main application file --- db.cpp | 14 ++++++++++++++ db.h | 3 ++- main.cpp | 30 +++++++++--------------------- yt.cpp | 31 +++++++++++++++++++++++++++++++ yt.h | 3 +++ 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/db.cpp b/db.cpp index d1ce70c..a4fb4ac 100644 --- a/db.cpp +++ b/db.cpp @@ -17,6 +17,20 @@ std::string get_string(sqlite3_stmt *row, int col) return std::string((char*)sqlite3_column_text(row, col)); } +void db_check_schema(); + +void db_init(const std::string &filename) +{ + SC(sqlite3_open(filename.c_str(), &db)); + db_check_schema(); +} + +void db_shutdown() +{ + sqlite3_close(db); + db = nullptr; +} + void db_check_schema() { bool settings_table_found = false; diff --git a/db.h b/db.h index 6232547..4e94a05 100644 --- a/db.h +++ b/db.h @@ -16,7 +16,8 @@ public: }; std::string get_string(sqlite3_stmt *row, int col); -void db_check_schema(); +void db_init(const std::string &filename); +void db_shutdown(); std::string db_get_setting(const std::string &key); void db_set_setting(const std::string &key, const std::string &value); diff --git a/main.cpp b/main.cpp index 5623846..7a3e820 100644 --- a/main.cpp +++ b/main.cpp @@ -134,21 +134,15 @@ void load_videos_for_channel(const std::string &channelId, bool force=false) { if(videos.find(channelId) != videos.end() && !force) return; + std::vector