充分利用SQLite的INT值 [英] Getting int values from SQLite
问题描述
我听说使用 sqlite3_ prepare_v2
而不是 sqlite_exec
来从数据库中获得的整数,但我失败了找到任何的例子。 这页面是无益也。现在我正在从数据库的字符串,所以我需要用来分析它们的atoi
这似乎是缓慢和无效的。
有很多关于这样类似的问题,但他们对OBJ-C和iOS SDK。我需要C / C ++提示或例子。
先谢谢了。
I heard of using sqlite3_prepare_v2
instead of sqlite_exec
to get integers from database, but I failed to find any examples. This page wasn't helpful also. Now I am getting strings from database, so I need to parse them with atoi
and this seems to be slow and ineffective.
There a lot of similar questions on SO, but they are about obj-c and iOS SDK. I need C/C++ hint or example.
Thanks in advance.
推荐答案
在 sqlite3_ prepare
成功,你一定不要忘记清理语句 sqlite3_finalize
。
为了得到结果记录,通话 sqlite3_step
,直到它不会返回 SQLITE_ROW
。
为了得到当前结果记录的值,调用 sqlite3_column_ *功能的:
After sqlite3_prepare
has succeeded, you must not forget to clean up the statement with sqlite3_finalize
.
To get the result records, call sqlite3_step
until it does not return SQLITE_ROW
.
To get the values of the current result record, call the sqlite3_column_* functions:
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, "SELECT 42", -1, &stmt, NULL) != SQLITE_OK)
...error...
else {
for (;;) {
int rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE)
break;
if (rc != SQLITE_ROW) {
...error...
break;
}
printf("value: %d\n", sqlite3_column_int(stmt, 0));
}
sqlite3_finalize(stmt);
}
这篇关于充分利用SQLite的INT值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!