Reputation: 10520
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?
Upvotes: 1
Views: 1433
Reputation: 95093
You need to wrap Studying
in single quotes. And your date.
This:
delete from Favorites_Table
where playlist_name = Studying and date = 1/1/2012
Should be this:
delete from Favorites_Table
where playlist_name = 'Studying' and date = '2012-01-01'
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_Table
where the playlist_name
column equalled the Studying
column. 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.
Upvotes: 4