sqlite3 中的查询 问题,sqlite3_exec

swlilike swlilike 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用例子中的

// 查询数据表

const char * sSQL3 = "select * from logins;";

sqlite3_exec( db, sSQL3, _sql_callback, 0, &pErrMsg);

static int _sql_callback(void * notused, int argc, char ** argv, char ** szColName)
{
int i;
for ( i=0; i < argc; i++ )
{
printf( "%s = %s\n", szColName[i], argv[i] == 0 ? "NUL" : argv[i] );
}

return 1;
}


这个可以查询,不过只能查询一行数据, 怎么能全部查询到呢?
sqlite3_get_table 他们说容易出错
...全文

相关推荐

c语言数据库查询系统-C语言实现sqlite3数据库查询的基本方法.pdf

c语⾔数据库查询系统,C语⾔实现sqlite3数据库查询的基本⽅ 法 sqlite回传函数相关 说了3种基本⽅法:callback,gettable和预处理stmt⽅法 下⾯给出测试代码和测试⽤数据库,代码如下 #include #include #include #include "sqlite3.h" // //typedef int (*sqlite3_callback)( // void* data, /* Data provided in the 4th argument of sqlite3_exec() */ // int ncols, /* The number of columns in row */ // char** values, /* An array of strings representing fields in the row */ // char** headers /* An array of strings representing column names */ //); int callback(void* data, int ncols, char** values, char** headers) { int i; int len =0; int ll=0; for(i=0; i < ncols; i++) { if(strlen(headers[i])>len) len = strlen(headers[i]); } for(i=0; i < ncols; i++) { ll = len-strlen(headers[i]); while(ll) { fprintf(stdout," "); --ll; } fprintf(stdout, "%s: %sn", headers[i], values[i]); } fprintf(stdout, "n"); return 0; } int search_by_callback(const char* db_name, const char* sql_cmd) { int i = 0 ; int j = 0 ; int nrow = 0, ncolumn = 0; char **azResult; //⼆维数组存放结果 sqlite3 *db=NULL; char *zErrMsg = 0; int rc; int len=0; if(access(db_name, 0) == -1) { fprintf(stderr, "%s not foundn", db_name); return -1; } rc = sqlite3_open(db_name, &db); if( rc != SQLITE_OK) { fprintf(stderr, "%s open failed: %sn", db_name,sqlite3_errmsg(db)); sqlite3_close(db); return -1; } //查询数据 rc = sqlite3_exec( db,sql_cmd, callback, NULL, &zErrMsg ); if( rc != SQLITE_OK) { fprintf(stderr, "%s %s: %sn", db_name,sql_cmd, sqlite3_errmsg(db)); if(zErrMsg) { fprintf(stderr,"ErrMsg = %s n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); return -1; } if(zErrMsg) { sqlite3_free(zErrMsg); } //关闭数据库 sqlite3_close(db); return 0; } int search_by_table(const char* db_name, const char* sql_cmd) { int i = 0 ; int j = 0 ; int nrow = 0, ncolumn = 0; char **azResult; //⼆维数组存放结果 sqlite3 *db=NULL; char *zErrMsg = 0; int rc; int len=0; if(access(db_name, 0) == -1) { fprintf(stderr, "%s not foundn", db_name); return -1; } rc = sqlite3_open(db_name, &db); if( rc != SQLITE_OK) { fprintf(stderr, "%s open failed: %sn"

是空空呀

linux下的sqlite3C语言编程实例

linux下的sqlite3 C语言编程实例

粒坨-康

Sqlite3数据库源码_ios源码

Sqlite3

偏执梦想家

Sqlite3源码及示例

使用C++对Sqlite3的封装,包含了数据库连接和访问接口。使用时包含Sqlite3ExLib.h即可,内部有2个例子供参考。

tulingwangbo

sqlite的方法.docx

sqlite的方法.docx

进击的朱亚文
评论 3
收藏 已收藏
分享
返回顶部
swlilike
MS-SQL Server 34,876 成员 254,635 内容