2012-01-11 2 views
1

내 iPhone 앱에서 sqlite 데이터베이스의 일부 항목을 삭제하려고하는데 이상한 오류가 발생합니다. ... 왜이 (가) "공부하는"는 아닙니다 말하는목표 C에서 Sqlite 오류

didn't delete error: no such column: Studying 

PLAYLIST_NAME과 날짜가 내 열입니다 : 여기

내 코드입니다 :

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); 
} 

하지만 그때 나는 오류 기둥?

답변

4

Studying을 작은 따옴표로 묶어야합니다. 그리고 네 데이트.

이 :

delete from Favorites_Table 
where playlist_name = Studying and date = 1/1/2012 

이되어야한다

delete from Favorites_Table 
where playlist_name = 'Studying' and date = '2012-01-01' 

이유는 당신이 따옴표에 넣어하지 않는 경우, 파서는 열 이름이라고 생각하는 것입니다. 첫 번째 쿼리에서 Favorites_Table에서 playlist_name 열이 Studying 열과 같은 곳을 삭제하려고했습니다. 이후 귀하의 오류, "아니오 해당 열."

그리고 공부하면서 따옴표를 고정하면 날짜도 오류가 발생합니다. 날짜는 ISO 형식 (yyyy-mm-dd)을 사용하여 비교합니다. 일반적으로 현지화 된 mm/dd/yyyy 또는 dd/mm/yyyy 형식은 사용하지 마십시오.