63 lines
2.7 KiB
C++
63 lines
2.7 KiB
C++
#ifndef SQLQUERYEXECUTOR_H
|
||
#define SQLQUERYEXECUTOR_H
|
||
|
||
#include <QObject>
|
||
#include <QSqlQuery>
|
||
#include <QHash>
|
||
#include "global.h"
|
||
|
||
class SqlQueryExecutor : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
static SqlQueryExecutor& instance();
|
||
//单条SQL语句执行接口
|
||
QSqlQuery executeSQL(const QString& connectionName, const QString& strSQL, const QVariantHash& params = {}, bool useTranscation = false);
|
||
/**
|
||
* @brief 多条批量SQL语句执行接口
|
||
* @param sqlStatements SQL语句列表
|
||
* @param paramsList 参数列表(要与SQL语句一一对应)
|
||
*/
|
||
QSqlQuery executeBatchSQL(const QString& connectionName, const QStringList& sqlStatements,
|
||
const QList<QVariantHash>& paramsList = QList<QVariantHash>(), bool useTranscation = false);
|
||
QHash<QString, QString> getFiledType(const QString& connectionName, const QString& table, const QString& schema = "basic");
|
||
//基于具体业务的查询接口-对外调用
|
||
//属性组相关
|
||
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
||
const QString getAttributeGroupName(const QString&, int);
|
||
const AttributeGroup getAttributeGroupData(const QString&, int);
|
||
bool isPublicAttributeGroup(const QString&, int);
|
||
bool removeAttributeGroup(const QString&, int, int);
|
||
//模型相关
|
||
const QVector<Model> getModels(const QString&);
|
||
int getModelCount(const QString&);
|
||
bool addModel(const QString&, Model&);
|
||
bool modelNameExistsInDB(const QString&, const QString&);
|
||
bool modelTypeExistsInDB(const QString&, const QString&);
|
||
bool removeModel(const QString&, int);
|
||
bool addModleGrpus(const QString&, int, QVector<int>);
|
||
QVector<int> getModelGroups(const QString&, int);
|
||
//属性相关
|
||
int getAttributeCount(const QString&, int, int, const QString& filterChars = "");
|
||
int getAllAttributeCount(const QString&, const QString& filterChars = "");
|
||
bool getAttributeInfo(const QString&, const QString&, Attribute&);
|
||
int getAttributeID(const QString&, const QString&);
|
||
bool attributeTypeUseByModelGroup(const QString&, int, int, int);
|
||
bool batchInsertAttributes(const QString&, int, int, QList<Attribute>);
|
||
bool batchDeleteAttributes(const QString&, int, int, QList<int>);
|
||
bool batchUpdateAttributes(const QString&, int, int, QList<Attribute>);
|
||
|
||
signals:
|
||
void errorOccurred(const QString& error);
|
||
|
||
private:
|
||
explicit SqlQueryExecutor();
|
||
~SqlQueryExecutor();
|
||
// 禁止拷贝
|
||
SqlQueryExecutor(const SqlQueryExecutor&) = delete; //delete关键字表示该函数不可用,包括编译器自动生成的函数
|
||
SqlQueryExecutor& operator=(const SqlQueryExecutor&) = delete;
|
||
};
|
||
|
||
#endif //SQLQUERYEXECUTOR_H
|