You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Include/iData/iDataEngine/iSqlEngine.h

90 lines
2.7 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "Defines.h"
#include "iDataEngine_global.h"
class QSqlDatabase;
/// 该类实现基础的数据增删改功能
/// 对于数据链接QSqlDatabase本类不负责开启
class I_DATAENGINE_EXPORT iSqlEngine
{
public:
/// @brief 构造函数,非静态类
/// @param pSqlDb,数据载体,如果为空,则自动
/// 从ZxDbSimple中获取
/// @note 默认pSqlDb是打开的状态而且不负责关闭
iSqlEngine(QString sConnStr = "", QSqlDatabase* pSqlDb = NULL);
~iSqlEngine();
/// @brief 执行失败时,返回错误信息
QString getLastError();
public:
/// @brief 单纯执行SQL如删除
bool execSqlOnly(QString sSql);
/// @brief 查询数据
/// @param sSql
/// @param vvecData,数据载体
/// @param bTopOnly,是否仅仅返回一条记录
/// @param pListFieldNames,Rec.FieldName
/// @note 返回true并不代表vvecData一定有数据
bool queryData(QString sSql, VVecVariant& vvecData, \
bool bTopOnly = false, QStringList* pListFieldNames = NULL);
/// @brief 批量保存模式,需要统一删除原来的重复数据
/// @param sTable针对表名
/// @param vvecData结果
/// @param mapKeyFields主键字段位置+名称
bool saveData(QString sTable, VVecVariant& vvecData, \
QMap<int, QString> mapKeyFields);
// /// @brief 单条记录保存模式
// bool saveDataToDb(QString& sTable, \
// QStringList& listFieldKeys, \
// QMap<QString, QString>& mapFieldValues);
// /// @brief 插入单条记录
// bool insertSql(QString& sTable, \
// QMap<QString, QString>& mapFieldValues);
// /// @brief 更新单条记录
// bool updateSql(QString& sTable, \
// QStringList& listFieldKeys, \
// QMap<QString, QString>& mapFieldValues);
// /// @brief 删除
// bool deleteSql(QString& sTable, QMap<QString, QString>& mapFieldValues);
// /// @brief 检查关键字段在某个表中是否存在
// bool isRecordExists(QString& sTable, \
// QStringList& listFieldKeys, \
// QMap<QString, QString>& mapFieldValues);
private:
/// @brief 批量删除模式
/// @param sTable针对表名
/// @param vvecData结果
/// @param mapKeyFields主键字段位置+名称
bool deleteIfExists(QString sTable, VVecVariant& vvecData, \
QMap<int, QString> mapKeyFields);
// 内部匹配对
QString verifyValue(QString sField, QString sValue);
QString makeFieldPair(QString sField, QString sValue);
private:
QSqlDatabase* m_pSqlDb;
QString m_sConnStr;
QString m_sError;
};