SQLite求问题
我正在使用 SQLite 版本 3 来运行以下代码。
//Run SQL SELCT query
sqlite3_prepare16_v2("SELECT * FROM table_name");
sqlite3_step();
//Need to review results in several iterations
for(int i = 0; i < n; i++)
{
//Seek to beginning
sqlite3_reset();
do
{
//Get values
sqlite3_column_int();
...
sqlite3_column_text16();
}
while(sqlite3_step() == SQLITE_ROW);
}
但由于某种原因,我得到的第一批数据全是0。我在上面的代码中做错了什么?
I'm using SQLite version 3 to run the following code.
//Run SQL SELCT query
sqlite3_prepare16_v2("SELECT * FROM table_name");
sqlite3_step();
//Need to review results in several iterations
for(int i = 0; i < n; i++)
{
//Seek to beginning
sqlite3_reset();
do
{
//Get values
sqlite3_column_int();
...
sqlite3_column_text16();
}
while(sqlite3_step() == SQLITE_ROW);
}
But for some reason the first batch of data I get is all 0's. What am I not doing correct in the code above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您显示的是伪代码,因为您缺少 sqlite3 函数的许多参数...
在
sqlite3_reset
之后和获取第一行值之前,您需要一个sqlite3_step
。您可以将
do {
...} while(sqlite3_step() == SQLITE_ROW)
更改为while(sqlite3_step() == SQLITE_ROW)
...}
来实现这一点。这也将消除在
sqlite3_prepare16_v2
之后立即执行的需要Assuming what you are showing is pseudocode since you're missing many arguments to the sqlite3 funcitons...
You need a
sqlite3_step
aftersqlite3_reset
and before getting the first row of values.You can change your
do {
...} while(sqlite3_step() == SQLITE_ROW)
to awhile(sqlite3_step() == SQLITE_ROW)
...}
to accomplish that.This will also eliminate the need to step immediately after the
sqlite3_prepare16_v2