当前位置: 首页 > news >正文

SQLiteHelper

方便进行数据库的操作

SQLiteHelper.h

#if !defined(AFX_SQLITEHELPER_H__59F8C44E_0D98_4422_AEB1_2FD927EE8902__INCLUDED_)
#define AFX_SQLITEHELPER_H__59F8C44E_0D98_4422_AEB1_2FD927EE8902__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include "sqlite3.h"
#include <vector>
#pragma  comment(lib,"sqlite3.lib")using namespace std;typedef int(*callBackFun)(void*, int, char**, char**);class SQLiteHelper
{
public:SQLiteHelper();~SQLiteHelper();sqlite3* getSqlite();//打开数据库bool OpenSqlite(CString strPath);//关闭数据库连接void CloseSqlite();//执行不返回数据的SQL语句(增、删、改)void ExecuteSqlite(CString& strSql);//执行查询操作void InquireSqlite(CString& strSql, callBackFun pCallfun);//获取字段名称int GetTableField(CString sTableName, vector<CString>& vTableField);//输出错误信息void OutPutInfo(CString strInfo);
private:sqlite3* pDB;
};#endif // !defined(AFX_SQLITEHELPER_H__59F8C44E_0D98_4422_AEB1_2FD927EE8902__INCLUDED_)

SQLiteHelper.cpp

#include "stdafx.h"
#include "SQLiteHelper.h"SQLiteHelper::SQLiteHelper()
{pDB = NULL;
}SQLiteHelper::~SQLiteHelper()
{
}sqlite3* SQLiteHelper::getSqlite()
{return pDB;
}bool SQLiteHelper::OpenSqlite(CString strPath)
{int nRes = sqlite3_open(strPath, &pDB);if (nRes != SQLITE_OK){CString cErrMsg = sqlite3_errmsg(pDB);OutPutInfo(cErrMsg);return false;}return true;
}void SQLiteHelper::CloseSqlite()
{sqlite3_close(pDB);
}void SQLiteHelper::ExecuteSqlite(CString& strSql)
{char* cErrMsg;int nRes = sqlite3_exec(pDB, strSql, 0, 0, &cErrMsg);if (nRes != SQLITE_OK){OutPutInfo(cErrMsg);}
}void SQLiteHelper::InquireSqlite(CString& strSql, callBackFun pCallfun)
{char* cErrMsg;int nRes = sqlite3_exec(pDB, strSql, pCallfun, 0, &cErrMsg);if (nRes != SQLITE_OK){OutPutInfo(cErrMsg);}
}int SQLiteHelper::GetTableField(CString sTableName,vector<CString>& vTableField)
{char** pResult = NULL;int nRow = 0;int nCol = 0;CString strSql = "select * from " + sTableName;int rc = sqlite3_get_table(pDB, strSql, &pResult, &nRow, &nCol, NULL);if (rc == SQLITE_OK){for (int i = 0; i < nCol; i++){vTableField.push_back(pResult[i]);}}sqlite3_free_table(pResult);return rc;
}void SQLiteHelper::OutPutInfo(CString strInfo)
{AfxMessageBox(strInfo);
}

http://www.mrgr.cn/news/31210.html

相关文章:

  • 视频单目标跟踪研究
  • 踩坑记录:adb修改settings数据库ContentObserver无回调
  • 基于存内计算架构的模型部署与映射优化
  • 【洛谷】P1313 [NOIP2011 提高组] 计算系数 的题解
  • MySQL —— 索引
  • mysql表逆向实体类
  • 大气网格化精细化监管监测系统
  • API 接口接入前:遵循标准流程与规范的注意事项
  • 云计算课程作业1
  • EC Shop安装指南 [ Apache PHP Mysql ]
  • CSP-J2024全真模拟题 阅读程序题3+程序填空题
  • OJ 旋转图像
  • postgresql gcc编译选项解释
  • Java集成gdal 处理解析tiff和shp数据
  • 大模型的实践应用30-大模型训练和推理中分布式核心技术的应用
  • iftop流量监控工具
  • 鸿蒙OpenHarmony【轻量系统内核通信机制(消息队列)】子系统开发
  • 红日药业携手实在智能,构建RPA数字员工平台满足业务一体化需求 | 实在RPA案例
  • cmake--set_target_properties
  • 20240921 每日AI必读资讯