Hi
I am trying to reuse a sqlite statement in my application in a method. Here's the relevant code
if(getsets_statement == nil){
const char *sql = "SELECT DISTINCT num,roll FROM mytable WHERE cls like ? and divname like ?";
if(sqlite3_prepare_v2(database, sql, -1, &getsets_statement, NULL) != SQLITE_OK){
NSAssert1(0, @"Error: Failed to prepare stmt with message '%s'", sqlite3_errmsg(database));
}
}
sqlite3_bind_text(getsets_statement, 1, [cls UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(getsets_statement, 2, [divname UTF8String], -1, SQLITE_TRANSIENT);
while(sqlite3_step(getsets_statement) == SQLITE_ROW){
setNumber= sqlite3_column_int(getsets_statement, 0);
roll = sqlite3_column_int(getsets_statement, 1);
[numArr addObject:[NSNumber numberWithInt:setNumber]];
[rollArr addObject:[NSNumber numberWithInt:roll]];
}
sqlite3_reset(getsets_statement);
The statement executes perfectly the first time it is called. But the next time I call this method, I get a sqlite3error. The values of divname and cls are present (did an NSLog and checked) but I don't understand why I am getting this error. I get the error at the 1st bind_text statement.
This is in the gdb console
Program received signal: “EXC_BAD_ACCESS”.
(gdb) where
#0 0x9041857f in sqlite3Error ()
#1 0x9041acea in vdbeUnbind ()
#2 0x9041b2c8 in bindText ()
Any help? Thanks.