This is the code I'm using to select some records from my database. I'm binding two dates into my sql, however, when I get to sqlite3_step I get SQLITE_DONE where I should be getting SQLITE_ROW. It looks like its processing the bindings rather than querying the data.
What am I doing wrong ?
NSString *startDateRangeString = @"2000-05-01";
NSString *endDateRangeString = @"2011-05-01";
sqlite3 *database;
int result = sqlite3_open("mydb.db", &database);
if(result != SQLITE_OK)
{
NSLog(@"Could not open db.");
}
const char *sql = "select pid from tmp where due >= '%@' and due < '%@' order by due, pid;";
sqlite3_stmt *statementTMP;
int error_code = sqlite3_prepare_v2(database, sql, -1, &statementTMP, NULL);
if(error_code == SQLITE_OK) {
sqlite3_bind_text(statementTMP, 1, [startDateRangeString UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statementTMP, 2, [endDateRangeString UTF8String], -1, SQLITE_TRANSIENT);
int step_error_code = sqlite3_step(statementTMP);
while(sqlite3_step(statementTMP) == SQLITE_ROW) // I get 101 aka SQLITE_DONE
{
NSLog(@"Found!!");
}
}
sqlite3_finalize(statementTMP);
sqlite3_close(database);