Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
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
 
got it

oops sorry,found out that i was using an old .db3 file in the code. sorry
 
old DB3 file will definitely trip you up every time. Glad things are working, code looks cool, what ya developing..if you can say.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.