选择查询未准备好

发布于 2024-10-30 17:54:12 字数 1279 浏览 0 评论 0原文

在这里,我正在实现一个选择查询来从表中获取数据,但我的查询没有返回任何行。

下面是我正在使用的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱我好吗 2024-11-06 17:54:12

没有抛出错误或异常
通过我的申请。

嗯,是的,有。您对 sqlite3_prepare_v2() 的调用失败;它不返回 SQLITE_OK。

当您在数据库的 sqlite 提示符下运行此语句时会发生什么?

SELECT * from ts_Gallary;

尝试将此行替换

NSLog(@"query could not be prepared");

为可以为您提供有关错误的更多信息的内容。包括对 sqlite3_errmsg() 的调用。

No Error or exception is been thrown
by my application.

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?

SELECT * from ts_Gallary;

Try replacing this line

NSLog(@"query could not be prepared");

with something that will give you more information about the error. Include a call to sqlite3_errmsg().

一影成城 2024-11-06 17:54:12

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文