I have written a simple sql select query to fetch data from my table.
when executed in command line i get 50 rows, but here in my routine while debugging i get 0 rows.
- (NSMutableArray *) getAllItems {
NSMutableArray *arr = [[NSMutableArray alloc] init];
const char *sql = "select * from mytable;";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
int ret = sqlite3_step(selectstmt);
while( ret == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Item *itemObj = [[Item alloc] init];
itemObj.itemid = primaryKey;
itemObj.itemdesc = [NSString stringWithUTF8String
char *)sqlite3_column_text(selectstmt, 1)];
[arr addObject:itemObj];
[itemObj release];
}
}
return arr;
}
in the line
while( ret == SQLITE_ROW) {
i get ret = SQLITE_DONE in the first iteration itself, and it comes out of the loop to have arr 0 items
where am i going wrong ? I created the .db3 file using sqlite3 client in windows, is that the problem ? but when i execute the same query in commandline i get proper data
CH
when executed in command line i get 50 rows, but here in my routine while debugging i get 0 rows.
- (NSMutableArray *) getAllItems {
NSMutableArray *arr = [[NSMutableArray alloc] init];
const char *sql = "select * from mytable;";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
int ret = sqlite3_step(selectstmt);
while( ret == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Item *itemObj = [[Item alloc] init];
itemObj.itemid = primaryKey;
itemObj.itemdesc = [NSString stringWithUTF8String
[arr addObject:itemObj];
[itemObj release];
}
}
return arr;
}
in the line
while( ret == SQLITE_ROW) {
i get ret = SQLITE_DONE in the first iteration itself, and it comes out of the loop to have arr 0 items
where am i going wrong ? I created the .db3 file using sqlite3 client in windows, is that the problem ? but when i execute the same query in commandline i get proper data
CH