开发者

Select Query Is Not Being Prepared

Here i am implementing a select query to fetch data from table but no any row is been returned by my qu开发者_如何学运维ery.

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.


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().


Remove the semicolon(;) from const char *slectImageIdQuery="SELECT * from ts_Gallary;"

like const char *slectImageIdQuery="SELECT * from ts_Gallary"

and its work properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜