I am trying to delete some entries in my sqlite database on my iPhone app, but am getting a weird error.
Here is my code:
if(sqlite3_open([databasePath UTF8String], &yerocDB)==SQLITE_OK)
{
sqlite3_stmt *compiledstatement;
NSString *deleteSql=[NSString stringWithFormat: @"delete from Favorites_Table where playlist_name = Studying and date = 1/1/2012"];
const char *sqlstmt = [deleteSql UTF8String];
if(sqlite3_prepare_v2(yerocDB, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
{
int result = sqlite3_step(compiledstatement);
if(SQLITE_DONE != result)
NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(yerocDB) );
}else{
NSLog(@"didn't delete error: %s", sqlite3_errmsg(yerocDB));
}
sqlite3_finalize(compiledstatement);
}
but then I get the error:
didn't delete error: no such column: Studying
playlist_name and date are my columns…Why is it saying the “Studying” is not a column?
You need to wrap
Studyingin single quotes. And your date.This:
Should be this:
The reason is that if you don’t put it in single quotes, the parser will think it’s a column name. In your first query, you were trying to delete from
Favorites_Tablewhere theplaylist_namecolumn equalled theStudyingcolumn. Henceforth your error, “No such column.”And once you fixed the quotes around studying, your date was going to throw an error, too. Dates use ISO format (yyyy-mm-dd) to compare. Don’t use the localized mm/dd/yyyy or dd/mm/yyyy formats, as a rule of thumb.