You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
975 B
41 lines
975 B
#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
|