打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MFC SQlite3封装工程
userphoto

2021.07.15

关注

https://blog.csdn.net/fz835304205/article/details/46639715

最近要做一个小工具,用到数据库,sql的数据库太麻烦,只是一个简单的数据库太多的功能也用不到,因此决定用sqlite3,以前在linux下玩过,但是不太深入,这次老大把活派下来了,没办法硬着头皮往前冲吧,于是开始在网上找相关的资料,找到了两个历程但是不是很理想,封装的水平感觉有限,最后在外国的网站上发现了一点干货

Kompex SQLite Wrapper for C++

http://sqlitewrapper.kompex-online.com/index.php?content=home

非常完美

数据库的部分代码如下:

void CSQliteMFCDlg::OnBnClickedButtonRead()

{

// TODO: 在此添加控件通知处理程序代码

Kompex::SQLiteDatabase *pDatabase = new Kompex::SQLiteDatabase("world.db3", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);

// move database to memory, so that we are work on the memory database hence

pDatabase->MoveDatabaseToMemory();

// create statement instance for sql queries/statements

Kompex::SQLiteStatement *pStmt = new Kompex::SQLiteStatement(pDatabase);

CString res, name;

int id;

#if 0

//res = pStmt->GetSqlResultString("SELECT NAME FROM sheet1 WHERE ID = 1;");

pStmt->Sql("SELECT * FROM sheet1;");

// process all results

while(pStmt->FetchRow())

{

id = pStmt->GetColumnInt("ID");

name = pStmt->GetColumnCString("NAME");

}

// do not forget to clean-up

pStmt->FreeQuery();

#endif

//pStmt->Sql(_T("SELECT * FROM sheet1 WHERE NAME LIKE '黄进';"));

pStmt->Sql(_T("SELECT * FROM Country;"));

m_List.DeleteAllItems();

while(m_List.DeleteColumn(0));

CRect rect;

m_List.GetWindowRect(&rect);

int colCnt = pStmt->GetColumnCount();

int width = rect.Width() / colCnt;

int col = 0;

int row = 0;

CString szText;

if(width < 160) width = 160;

for(col = 0; col < colCnt; col++)

{

szText = pStmt->GetColumnName16(col);

m_List.InsertColumn(col, szText, LVCFMT_LEFT, width);

}

while(pStmt->FetchRow())

{

szText = pStmt->GetColumnString16(0);

m_List.InsertItem(row, szText);

for(col = 1; col < colCnt; col++)

{

szText = pStmt->GetColumnString16(col);

m_List.SetItem(row, col, LVIF_TEXT, szText, 0, 0, 0, 0);

}

++row;

}

pStmt->FreeQuery();

}

完整工程的下载地址:http://download.csdn.net/detail/fz835304205/8839049

每天进步一点点,进步来源于痛苦

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C连接SQLite
iPhone开发之SQLite
sqlite查询表名判断字段是否存在等
不推荐使用sqlite3_get_table,而是使用sqlite3_prepare_v2替代
sqlite api使用代码实例
PreparedStatement的用法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服