2012-02-17 21 views
0

私はSQLiteデータベースで作業しています。私はデータベースにデータを挿入しています。しかし、次は私のコードです、私はその動作していないデータベースからデータを削除したい、私は私が間違っているいくつかやっていると思いますいずれかが私を助けてください:iPhoneのSQLiteデータベースからテーブルデータを削除するには

-(IBAction)deleteData { 

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDir = [documentPaths objectAtIndex:0]; 
NSString *databasePath=[documentsDir stringByAppendingPathComponent:@"paddleEight.sqlite"]; 
NSLog(@"The Database Path is---> %@", databasePath); 

sqlite3_stmt *compiledStatement; 
sqlite3 *db; 
NSString *sqlStatement = @"DELETE from GalleryTabel;"; 


if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) { 


    if (sqlite3_prepare(db, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) { 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"record" message:@"record Deleted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     alert=nil; 
    } 
    sqlite3_finalize(compiledStatement); 
} 
} 
+0

GalleryTableの綴りは間違っていますか? –

+0

@Toby Allenに返信してくれてありがとうが、私は同じ名前を書いています。論理的な誤りを教えてください。 – iPhone4s

+0

@ iPhone4s私たちとエラーを共有する可能性はありますか? –

答えて

5

は、エラーがあるかどうかを確認し、NSLog(@"Error=%s",sqlite3_errmsg(&db)をロギングしてみます。 sqlite3_open statementの内部に入っていないか確認してください。

そして、私は決してdeleteステートメントを終了するためにセミコロンを使用していない、私の知識sqliteは非常に限られています。しかし、私はいつも使用しているNSString *sqlStatement = @"DELETE from GalleryTabel";セミコロンが削除されていることに注意してください。

prepare,step,finalizeメソッドの代わりにexecを試してみてください。例えば

NSString*deleteSQL=[NSString stringWithFormat:@"delete from GalleryTabel"]; 
const char*deleteStmt=[deleteScoreSQL UTF8String]; 
char*errMsg=nil; 

     if(sqlite3_exec(db, deleteScoreStmt, NULL, NULL, &errMsg)==SQLITE_OK) 
     { 
      NSLog(@"Deleted table"); 
     } 

は、この情報がお役に立てば幸いです。

関連する問題