Why does SQLite not bring back any results from my database
Posted
by tigermain
on Stack Overflow
See other posts from Stack Overflow
or by tigermain
Published on 2010-01-28T15:38:23Z
Indexed on
2010/05/02
0:07 UTC
Read the original article
Hit count: 251
This is my first SQLite based iPhone app and I am trying to get it to read a menu hierarchy from my database.
The database appears to be registered fine as the compiled statement doesnt error (tried putting in valid table name to test) but for some reason sqlite3_step(compiledStmt) doesnt ever equal SQLITE_ROW as if to suggest there is no data in there; which there is.
sqlite3 *database;
menu = [[NSMutableArray alloc] init];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStmt = "SELECT * FROM Menu";
sqlite3_stmt *compiledStmt;
if (sqlite3_prepare_v2(database, sqlStmt, -1, &compiledStmt, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStmt) == SQLITE_ROW) {
NSString *aTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStmt, 1)];
MenuItem *menuItem = [[MenuItem alloc] init];
menuItem.title = aTitle;
[menu addObject:menuItem];
[menuItem release];
}
}
else {
NSLog(@"There is an error with the SQL Statement");
}
sqlite3_finalize(compiledStmt);
}
sqlite3_close(database);
© Stack Overflow or respective owner