Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXC_BAD_ACCESS in sqlite_step(statement)

I am using sqlite database for iphone app. but its crash on "while loop" line while retrieving data from database sometimes.

-(void)GetMethod
{

    NSString *query = [[NSString alloc] initWithFormat:@"SELECT * FROM errorlogs"];
    sqlite3_stmt *statement;    
    if (sqlite3_prepare_v2(database, [query UTF8String],-1, &statement, nil) == SQLITE_OK) 
    {
        while (sqlite3_step(statement) == SQLITE_ROW) **// EXC_BAD_ACCESS ON THIS LINE**
        { 
            char *uid1 = (char *)sqlite3_column_text(statement, 0);
            NSString *uid = [NSString stringWithFormat:@"%s",uid1];
        }
    }
    sqlite3_finalize(statement);
}

why I am getting this EXC_BAD_ACCESS on while loop.

enter image description here Thanks.

like image 239
Dilip Lilaramani Avatar asked Jun 08 '12 14:06

Dilip Lilaramani


2 Answers

Try using the FMDB framework, it helped me a lot in my project.
Here's the link: https://github.com/ccgus/fmdb
Give it a look if you can ;)

like image 71
Rodolfo Matos Avatar answered Nov 03 '22 20:11

Rodolfo Matos


Either sqlite3_step(statement) or SQLITE_ROW is not initialized, or has already been released. When it runs the equality check on the nonexistent object, it throws EXE_BAD_ACCESS.

Are you returning any rows?

like image 2
PRNDL Development Studios Avatar answered Nov 03 '22 19:11

PRNDL Development Studios