#ifndef SQL_OPR_H #define SQL_OPR_H #include #include #include #include #include struct AccountRecord { int32_t id{}; int32_t money{}; std::string payType{}; std::string dt; std::string thing; std::string classify; std::string remark; std::string additionFile{}; }; struct CommonRecord { int32_t id{}; std::string key; std::string value; std::string type; std::string mark; }; struct RepayRecord { int32_t id{}; int32_t accID{}; int32_t money{}; std::string dt; std::string remark; }; using ClassifyRecordList = std::vector; using AccountRecordList = std::vector; using RepayRecordList = std::vector; class ACTSqlOpr { public: ACTSqlOpr(); ~ACTSqlOpr(); public: bool OpenDb(const std::string& path); bool GetAccountList(AccountRecordList& ret); bool AppendAccount(AccountRecord& ret); bool DeleteAccount(int32_t id); bool UpdateAccount(AccountRecord& ret); QSqlDatabase& GetDb(); const std::string& GetLastErr(); private: bool generateDefaultTB(); private: QSqlDatabase db_; std::string dbPath_{}; std::string lastErr_{}; }; class ComSqlOpr { public: ComSqlOpr(QSqlDatabase& db); public: bool GetClassifyList(ClassifyRecordList& ret); bool GetItem(CommonRecord& ret, const std::string& key); bool UpdateItem(CommonRecord& ret); bool InserItem(CommonRecord& ret); bool DeleteItem(const std::string& value); bool CheckContent(); bool CheckClassifyExist(const std::string& value); const std::string& GetLastErr(); private: bool CheckAndInsert(const std::string& key, const std::string& value, const std::string& type, const std::string& mark); private: bool generateDefaultTB(); private: QSqlDatabase& db_; std::string lastErr_{}; }; class RepaySqlOpr { public: RepaySqlOpr(QSqlDatabase& db); public: bool GetRepayResult(RepayRecordList& ret, int32_t accID); bool InsertRepayRecord(RepayRecord& ret); bool updateRepayRecord(RepayRecord& ret); bool deleteRepayRecord(int32_t id); const std::string& GetLastErr(); private: bool generateDefaultTB(); private: QSqlDatabase& db_; std::string lastErr_{}; }; #endif // SQL_OPR_H