Reputation: 601
I use sqlite for my simple iOS app. The problem is that I can't get the result from the query. I will skip the code which is responsible for opening the database. It works.
NSString *query = @"SELECT * FROM tickets LIMIT 0,1";
if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK)
{
NSString *strResult = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
NSLog(@"%@", strResult);
sqlite3_finalize(statement);
}
Here the app crash with a message:
NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
I'm 100% sure that the query
SELECT * FROM tickets LIMIT 0,1
return result which is not NULL. I have tested the query above with sqlite client and it works fine.
What is wrong here ?
Upvotes: 0
Views: 94
Reputation: 4920
You didn't evaluate your statement. You should use:
int sqlite3_step(sqlite3_stmt*);
after sqlite3_prepare_v2
.
Upvotes: 2