[C++] sqlite3_get_table 的使用

不知道为啥 sqlite3 里面使用 "UPDATE" 更新数据,更新失败也不报错,所以就想绕过去。先查一下字段存在不存在,然后再update

cpp 复制代码
std::string selectsql =  "SELECT COUNT(*) FROM table_name WHERE some_condition";
char** dbResult;
char* errmsg = NULL;        //用来存储错误信息字符串
int nRow = 0, nColumn = 0;  // nRow  查找出的总行数,nColumn 存储列
int ret = sqlite3_get_table(db, selectsql.c_str(), &dbResult, &nRow, &nColumn, &errmsg);
if (SQLITE_OK != ret || nRow == 0)
{

    sqlite3_free_table(dbResult);
   // do_something
}
 sqlite3_free_table(dbResult);
// do_something


std::string sql = "UPDATE table_name SET item1=? \
    WHERE item2=? and item3=? and item4=?;  ";

sqlite3_prepare_v2(db, sql.c_str(), -1, &statement, nullptr);
int index = 0;
QByteArray inByteArray
sqliteBind(statement, index, inByteArray.data(), inByteArray.length());  
sqliteBind(statement, index, "...");         
sqliteBind(statement, index, "...");  
sqliteBind(statement, index, "...");    
相关推荐
俺不要写代码1 分钟前
数据库:约束
数据库·mysql
KmSH8umpK7 分钟前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第四篇
数据库·redis·分布式
晚风吹红霞25 分钟前
C++异常处理核心知识点全解析
开发语言·c++
CoderCodingNo26 分钟前
【信奥业余科普】C++ 的奇妙之旅 | 17:面的铺展与文本的本质——二维数组与字符串
开发语言·c++
KmSH8umpK35 分钟前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第五篇
数据库·redis·分布式
lilihuigz39 分钟前
企业培训网站搭建指南:5步在WordPress上创建品牌学院
数据库
迷途之人不知返42 分钟前
优先级队列:priority_queue
数据结构·c++
曦夜日长1 小时前
C++ STL容器string(一):string的变量细节、默认函数的认识以及常用接口的使用
java·开发语言·c++
WL_Aurora1 小时前
MySQL 5 卸载到 MySQL 8 安装完整指南(不踩坑版)
数据库·mysql
代码中介商1 小时前
C++ STL 标准模板库完全指南:从容器到迭代器
开发语言·c++·stl