sqlite problem

Discussion in 'iOS Programming' started by chhoda, Oct 9, 2009.

  1. chhoda macrumors 6502

    Joined:
    Oct 25, 2008
    #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
     
  2. chhoda thread starter macrumors 6502

    Joined:
    Oct 25, 2008
    #2
    got it

    oops sorry,found out that i was using an old .db3 file in the code. sorry
     
  3. g3funk macrumors member

    g3funk

    Joined:
    Oct 2, 2008
    #3
    old DB3 file will definitely trip you up every time. Glad things are working, code looks cool, what ya developing..if you can say.
     

Share This Page