#ifndef XSQLEXCUTE_H
#define XSQLEXCUTE_H

#include <QObject>
#include <QMutex>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>

class XSqlExcute : public QObject
{
    Q_OBJECT
public:
    explicit XSqlExcute(QObject *parent = nullptr);
    static XSqlExcute* instance();
    bool openMysql(QString hostName,QString databaseName,QString userName,QString password,QString connectionName);
    bool closeMysql();
    //执行语句
    bool excuteSQL(QString sql,QString connectionName);

    //查询
    QSqlQuery query(QString sql,QString connectionName);
    QSqlRecord record(QString sql,QString connectionName);

    //事务
    void transaction(QString connectionName);
    void commit(QString connectionName);
    void rollback(QString connectionName);

signals:

private:
//    explicit XSqlExcute(QObject *parent = nullptr);
private:
    static XSqlExcute* g_pSqlExc;
    static QMutex m_mutex;
    QSqlDatabase db;
};

#endif // XSQLEXCUTE_H
