以下のコードスニペットを使用して、テーブルからすべてのデータを削除しています
NSString *deleteStatementNS = [NSString stringWithFormat:
@"DELETE FROM %@",[tableNames objectAtIndex:i]];
const char *prepareDelete ="DELETE FROM '?'";
const char *tbleName = [[tableNames objectAtIndex:i] UTF8String];
if (sqlite3_prepare_v2(dBase, prepareDelete, -1, &dbpreprdstmnt, NULL) == SQLITE_OK)
{
dbrc = sqlite3_bind_text(dbpreprdstmnt, 1, tbleName, -1, SQLITE_TRANSIENT);
dbrc = sqlite3_step(dbpreprdstmnt);
sqlite3_finalize(dbpreprdstmnt);
dbpreprdstmnt = NULL;
}
else
{
NSLog(@"Error %@",[NSString stringWithCString:sqlite3_errmsg(dBase) encoding:NSUTF8StringEncoding]);
}
しかし、残念ながら、削除は行われていError no such table: ?
ません。ステートメントのみを準備できないため、エラーが発生します。しかし、私が以下のような準備ステートメントを使用する場合
const char *prepareDelete =[deleteStatementNS UTF8String];
これは完全に正常に機能しています。SQLインジェクション攻撃を停止するために変数をバインドできません。このエラーの背後にある理由を教えてください。このコードスニペットが正常に機能していると報告されている場所をたくさん見つけました。