133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#ifndef __UIIVALUETABLE_H__
|
|
#include "UIIValueTable.h"
|
|
#endif
|
|
|
|
#include "comutil.h"
|
|
#include "UIITableField.h"
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
class TGADOSRV_API CUIISQLiteServer
|
|
{
|
|
public:
|
|
CUIISQLiteServer(void);
|
|
~CUIISQLiteServer(void);
|
|
|
|
//初始化
|
|
BOOL InitADOServer(LPCTSTR pszDbFileName,bool bTraySQLServer = true);
|
|
|
|
//建立连接、连接数据库,打开数据库
|
|
BOOL InitSQLServer(LPCTSTR pszConnection,bool bDisplayException = true);
|
|
|
|
//复制SQLite3 数据到 SQLServer; 数据库表和结构一一对应
|
|
//static 注意 表如果有image,binary 则必须有ID 字段
|
|
static BOOL SQLite3Data2SQLServer(LPCTSTR pszDbFileName,LPCTSTR pszDbName,LPCTSTR pszConnection);
|
|
|
|
//创建表
|
|
BOOL CreateDBTable(LPCTSTR pszTableName,Ttable& arFields);
|
|
|
|
//判断表是否存在
|
|
BOOL IsDbTableExist(LPCTSTR pszTableName);
|
|
|
|
//获取表的结构信息
|
|
BOOL GetTableStru(LPCTSTR pszTableName,Ttable& arFields,BOOL bTypeAsSQLite = TRUE);
|
|
|
|
//获取表的结构信息
|
|
BOOL GetTableStru(LPCTSTR pszTableName,CStringList& listField);
|
|
|
|
//删除数据库中的表
|
|
BOOL DeleteTable(LPCTSTR pszTableName);
|
|
|
|
//删除数据库中的若干表
|
|
BOOL DeleteTable(CStringArray& arTableNames);
|
|
|
|
//删除表中若干字段名
|
|
BOOL DeleteTableFields(LPCTSTR pszTableName,CStringArray& arFields);
|
|
|
|
//删除表中字段
|
|
BOOL DeleteTableFields(LPCTSTR pszTableName,LPCTSTR pszFields);
|
|
|
|
//向表中增加若干字段名
|
|
BOOL AppendTableFields(LPCTSTR pszTableName,Ttable& arFields);
|
|
|
|
//向表中增加字段
|
|
BOOL AppendTableFields(LPCTSTR pszTableName, CUIITableField& arFields);
|
|
|
|
//获得一个数值
|
|
int GetSelData(LPCTSTR pszStrSQL,CString& sValue);
|
|
|
|
//把获得相应的信息填到数组中
|
|
int GetSelData(LPCTSTR pszStrSQL,CStringArray& arStrValue);
|
|
int GetSelData(LPCTSTR pszStrSQL,CStringArray& arStrValue,int nFr, int nTo);
|
|
int GetSelData(LPCTSTR pszStrSQL,std::vector<CString>& arStrValue);
|
|
|
|
|
|
//是否是空选择集
|
|
BOOL IsSelEmpty(LPCTSTR pszStrSQL);
|
|
|
|
//把获得相应的信息填到链表中
|
|
int GetSelData(LPCTSTR pszStrSQL,CStringList& listStrValue,BOOL bMakeLower= TRUE);
|
|
int GetSelData(LPCTSTR pszStrSQL,CStringList& listStrValue, int nFr, int nTo, BOOL bMakeLower= TRUE);
|
|
|
|
//选取多个字段,把获得相应的信息填到'表'对象中
|
|
int GetSelData(LPCTSTR pszStrSQL,CUIIValueTable& valueTable,BOOL bUpdateLable = TRUE);
|
|
int GetSelData(LPCTSTR pszStrSQL,CUIIValueTable& valueTable, int nFr, int nTo, BOOL bUpdateLable = TRUE);
|
|
|
|
//选取两列,一个为Key,一个为Value建map select a,b from...; a-->b
|
|
int GetSelData(LPCTSTR pszSKey_ValueSQL,CMapStringToString& mapKey_Value);
|
|
int GetSelData(LPCTSTR pszSKey_ValueSQL, std::map<CString, CString> &mapKey_Value);
|
|
|
|
//选取一行,获得Field到对应数据的映射
|
|
int GetSelDataEx(LPCTSTR pszSelectSQL,CMapStringToString& mapFieldToValue);
|
|
int GetSelDataEx(LPCTSTR pszSelectSQL, std::map<CString, CString> &mapFieldToValue);
|
|
|
|
int GetSelDataEx(LPCTSTR pszSelectSQL, std::vector<std::vector<CString>> &datas);
|
|
int GetSelDataEx(LPCTSTR pszSelectSQL, std::vector<std::map<CString, CString>> &datas);
|
|
|
|
//blob 操作
|
|
//insert into table (id,name,picture) values (0,'namestr',?)
|
|
//table 对应 id,name 的数据
|
|
int InsertBlob(LPCTSTR pszSQL,void* pData,int nSize);
|
|
int InsertBlob(LPCTSTR pszSQL,LPCTSTR pszFile);
|
|
|
|
//update table set id=,name='namestr',picture=? where ...
|
|
int UpdateBlob(LPCTSTR pszSQL,void* pData,int nSize);
|
|
int UpdateBlob(LPCTSTR pszSQL,LPCTSTR pszFile);
|
|
|
|
//select picture from table where id=...
|
|
int GetSelBlob(LPCTSTR pszSQL,void*& pData,int& nSize);
|
|
int GetSelBlob(LPCTSTR pszSQL,LPCTSTR pszFilePath);
|
|
|
|
//获得数据库中所有的表名
|
|
void GetDbTableNameArray(CStringArray& arTables);
|
|
|
|
//获得数据库中所有的表名
|
|
void GetDBTableNameList(CStringList& listTables);
|
|
|
|
//执行SQL语句[如 删除,追加,更新]
|
|
BOOL ExecuteSQL(LPCTSTR pszStrSQL);
|
|
|
|
//判断数据库是否成功打开
|
|
BOOL IsDatabaseOpen();
|
|
|
|
//开始事务
|
|
void BeginTrans();
|
|
|
|
//回滚事务
|
|
void RollbackTrans();
|
|
|
|
//提交事务
|
|
void CommitTrans();
|
|
|
|
private:
|
|
|
|
BOOL TryInitSQLServer(LPCTSTR pszDbFileName);
|
|
|
|
protected:
|
|
|
|
void* m_pSQLiteDb;
|
|
void* m_pADORxDb;
|
|
};
|