2026-08-18 09:40:43 +08:00
|
|
|
#ifndef DATABASEMANAGER_H
|
|
|
|
|
#define DATABASEMANAGER_H
|
|
|
|
|
|
|
|
|
|
#include "dbconfig.h"
|
|
|
|
|
|
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
|
class DatabaseManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static DatabaseManager &instance();
|
|
|
|
|
|
|
|
|
|
void setConfig(const DbConfig &config);
|
|
|
|
|
DbConfig config() const;
|
|
|
|
|
|
|
|
|
|
bool open(QString *error = nullptr);
|
|
|
|
|
void close();
|
|
|
|
|
bool isOpen() const;
|
|
|
|
|
QSqlDatabase database() const;
|
|
|
|
|
QString lastErrorText() const;
|
|
|
|
|
|
|
|
|
|
bool transaction(QString *error = nullptr);
|
|
|
|
|
bool commit(QString *error = nullptr);
|
|
|
|
|
bool rollback(QString *error = nullptr);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
DatabaseManager();
|
|
|
|
|
DatabaseManager(const DatabaseManager &) = delete;
|
|
|
|
|
DatabaseManager &operator=(const DatabaseManager &) = delete;
|
|
|
|
|
|
2026-08-20 11:22:55 +08:00
|
|
|
QString connectionName() const;
|
|
|
|
|
|
2026-08-18 09:40:43 +08:00
|
|
|
DbConfig m_config;
|
|
|
|
|
QString m_lastErrorText;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // DATABASEMANAGER_H
|