选择查询未准备好
在这里,我正在实现一个选择查询来从表中获取数据,但我的查询没有返回任何行。
下面是我正在使用的代码:
if ((sqlite3_open([[self dataFilePath] UTF8String], &database))==SQLITE_OK)
{
NSLog(@"DataBase OpeneD..!!");
imageId=[[NSMutableArray alloc] init];
const char *slectImageIdQuery="SELECT * from ts_Gallary;";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, slectImageIdQuery, -1, &statement, nil)==SQLITE_OK)
{
NSLog(@"Query CREATED..!!");
while (sqlite3_step(statement)==SQLITE_ROW)
{
int iId=sqlite3_column_int(statement, 0);
NSString *imgTtl=[NSString stringWithFormat:@"%d",iId];
NSLog(@"image id in while=%d",iId);
[imageId addObject:[NSString stringWithFormat:@"%@",imgTtl]];
}
}
else
{
NSLog(@"query could not be prepared");
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
我的控制台显示:
2011-04-06 17:44:33.381 Tuscany[4680:207] DataBase OpeneD..!! 2011-04-06 17:44:33.382 Tuscany[4680:207] 查询无法准备
注意:这里 dataFilePath 是返回我的数据库和数据库<的路径的方法/strong> 是 sqlite3 对象
我的应用程序没有抛出错误或异常。
可能存在什么问题?如何发现问题并解决问题?
谢谢。
Here i am implementing a select query to fetch data from table but no any row is been returned by my query.
below is my code that i am using:
if ((sqlite3_open([[self dataFilePath] UTF8String], &database))==SQLITE_OK)
{
NSLog(@"DataBase OpeneD..!!");
imageId=[[NSMutableArray alloc] init];
const char *slectImageIdQuery="SELECT * from ts_Gallary;";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, slectImageIdQuery, -1, &statement, nil)==SQLITE_OK)
{
NSLog(@"Query CREATED..!!");
while (sqlite3_step(statement)==SQLITE_ROW)
{
int iId=sqlite3_column_int(statement, 0);
NSString *imgTtl=[NSString stringWithFormat:@"%d",iId];
NSLog(@"image id in while=%d",iId);
[imageId addObject:[NSString stringWithFormat:@"%@",imgTtl]];
}
}
else
{
NSLog(@"query could not be prepared");
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
My console display:
2011-04-06 17:44:33.381 Tuscany[4680:207] DataBase OpeneD..!!
2011-04-06 17:44:33.382 Tuscany[4680:207] query could not be prepared
Note: Here dataFilePath is method which return path of my database and database is sqlite3 object
No Error or exception is been thrown by my application.
What problem can there be and how can I detect the problem as well as solve that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,是的,有。您对 sqlite3_prepare_v2() 的调用失败;它不返回 SQLITE_OK。
当您在数据库的 sqlite 提示符下运行此语句时会发生什么?
尝试将此行替换
为可以为您提供有关错误的更多信息的内容。包括对 sqlite3_errmsg() 的调用。
Well, yeah, there is. Your call to sqlite3_prepare_v2() fails; it doesn't return SQLITE_OK.
What happens when you run this statement at your database's sqlite prompt?
Try replacing this line
with something that will give you more information about the error. Include a call to sqlite3_errmsg().
从 const char *slectImageIdQuery="SELECT * from ts_Gallary;" 中删除分号(;),
就像 const char *slectImageIdQuery="SELECT * from ts_Gallary" 一样且
工作正常。
Remove the semicolon(;) from const char *slectImageIdQuery="SELECT * from ts_Gallary;"
like const char *slectImageIdQuery="SELECT * from ts_Gallary"
and its work properly.