sqlite中用sqlite3_get_table查询和用sqlite3_exec查询的结果不同的问题

flying_csd_1 2008-11-03 08:38:11
相同的sql语句,我用了不同的查询方式。
rc = sqlite3_exec( db, (PS8)sql, mmi_sqlite_query_callback, NULL, &zErrMsg );
rc=sqlite3_get_table(db, (PS8)sql,&datatable, &nRow, &nColumn, &zErrMsg);
前者查询结果正常。后者查询结果发现有些字段出现乱码,本来int型的数据,查询到的数据为字段的列名,有的数据是正常。
有的字符串型的数据第一个字符都有个乱码。这是怎么回事。
...全文
8767 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuyiweixiao 2012-10-27
  • 打赏
  • 举报
回复
我觉得既然它提供了,就没那么简单说有问题。继续找找是哪里的问题,一定要搞懂,函数原型是调用1楼说的那些函数,和自己调用这些函数又有什么区别呢?[Quote=引用 11 楼 的回复:]
我这几天也遇到了问题,开始用这个函数的时候结果是正确的,现在调用此函数返回1,提示没有那张表,哎
[/Quote]
zhuyiweixiao 2012-10-27
  • 打赏
  • 举报
回复
我这几天也遇到了问题,开始用这个函数的时候结果是正确的,现在调用此函数返回1,提示没有那张表,哎
l360220954 2012-10-19
  • 打赏
  • 举报
回复
那我如果也想找个char **p去接收查询出来的数据,这样的接口该怎么去封装呢。
猪的飞想 2012-01-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 iihero 的回复:]
sqlite3_get_table尽量少用。
[/Quote]

请问为什么sqlite3_get_table劲量少用啊?
flyingkate 2011-12-18
  • 打赏
  • 举报
回复
同意一楼的,大家都说gettable不推荐使用,其实sqlite3.h的注释中说的也比较明白了,用prepare,方式较好。这最近也在看这个东西,.h不亚于一个帮助文档,真不错。。
program2050 2011-09-29
  • 打赏
  • 举报
回复

void basic_interface()
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char sql[]="select * from addr;";
sqlite3_stmt *stmt;
int id;
unsigned char *street, *city;
rc = sqlite3_open("D:/VCWork/test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
return;
}
rc= sqlite3_prepare_v2(db,sql, strlen(sql), &stmt,0);
if( rc ){
fprintf(stderr, "Can't open statement: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
return;
}
//right align output format
printf("%10s %10s %10s/n", "id", "street", "city");
printf("%10s %10s %10s/n", "---", "---", "---");
while(sqlite3_step(stmt)==SQLITE_ROW ) {
id = sqlite3_column_int(stmt, 0);
street = (unsigned char*)sqlite3_column_text(stmt,1);
city = (unsigned char*)sqlite3_column_text(stmt, 2);
printf("%10d %10s %10s/n", id, street, city);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}

maotoula 2011-08-03
  • 打赏
  • 举报
回复
学习了。
yzlovme 2011-03-28
  • 打赏
  • 举报
回复
学习了。。。
iihero_ 2010-12-07
  • 打赏
  • 举报
回复 1
sqlite3_get_table尽量少用。
xghuzd 2010-12-07
  • 打赏
  • 举报
回复
学习了
天煞19 2010-11-12
  • 打赏
  • 举报
回复
学习了
谭建新 2009-04-01
  • 打赏
  • 举报
回复 1

这个问题是这样的,其实sqlite3_get_table这个API从一开始就是不推荐使用的,你可以看一下所有的SQLite范例,极少有用到这个API的,原因除了你提到的id取值范围问题之外,更重要的是它无法处理BLOB字段类型,所以在实际当中它只能算是一个测试API.

而且sqlite3_get_table函数本身你可以看一下源代码,也是由

int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt**, const char**);

int sqlite3_bind_double(sqlite3_stmt*, int, double);
int sqlite3_bind_int(sqlite3_stmt*, int, int);
int sqlite3_bind_int64(sqlite3_stmt*, int, long long int);
int sqlite3_bind_null(sqlite3_stmt*, int);
int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int n, void(*)(void*));

int sqlite3_step(sqlite3_stmt*);
这些API组合而成的.

所以正确的做法是自己使用上面API函数,这样当表中的数据很多的时候可以用__int64来接收ID

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧