/** * file: DataManager/DataBase/DbMananger.h * purpose: create the sqlite db file and create tables * author: zhushengming@navinfo.com * All Rights Reserved(C)2021-2023 SWWX Co.Ltd. **/ #ifndef DATAMANAGER_DATABASE_DBMANAGER_H_ #define DATAMANAGER_DATABASE_DBMANAGER_H_ #include #include class DbManager { public: DbManager(); ~DbManager(); /** * @brief check if the sqlite file exists * @param dbPath * @return return true if the path exists, else return false */ bool isDbExists(QString dbPath); QSqlDatabase* createDatabase(QString dbPath); bool createTables(const QSqlDatabase* db); /** * @brief create a table * @param the DDL sql, for example "create table test(ID INTEGER PRIMARY KEY, NAME TEXT NOT NULL);" * @return 1 if the table is created successfull, else return 0 */ int createTable(const QSqlDatabase* db, QString ddl); /** * @brief check if a given table exits in the sqlite * @param tableName the name of the table * @return true if the table exists, else return false */ bool isTableExists(const QSqlDatabase* db, QString tableName); /** * @brief close the database */ void close(); private: QSqlDatabase database; }; #endif