Reputation: 2418
I want to use sqlite3 for my iphone application. But it is not working. Scenario is :- On click event of a button a method should run and retrieve the data from the database. But My sequence of program is not going into
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "select * from records";
sqlite3_stmt *compiledStatement;
0NSLog(@"%s", sqlite3_errmsg(database)); // Results - no error
-
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
//here NSLog statement does not work.
There is no problem in opening a database. What should be the reason? Any solution appreciable. Thanks
Upvotes: 0
Views: 174
Reputation: 98
Here is a modified example of my own code :
NSString *file = @"youdatabase.db"
sqlite3 *db;
if(sqlite3_open([file UTF8String], &db) == SQLITE_OK)
{
NSString *req = @"SELECT * FROM totoTable";
sqlite3_stmt *returnReq;
if(sqlite3_prepare(db, [req cStringUsingEncoding:NSUTF8StringEncoding], -1, &returnReq, NULL) == SQLITE_OK)
{
while (sqlite3_step(returnReq) == SQLITE_ROW)
{
//Printf first returned value
NSLog(@"%s", (char*)sqlite3_column_text(returnReq, 0));
}
}
sqlite3_close(db);
}
Hope it will help you ;-)
Upvotes: 0
Reputation: 1076
Try this: NSLog(@"%s", sqlite3_errmsg(database));
and see if there are some errors in your query.
Upvotes: 1