鉴于声明:
const char *sql = "INSERT INTO FooTable (barStr) VALUES (?)";
以下使用sqlite3_bind_text
(及相关sqlite3_bind_*
函数)是否足以防止 SQL 注入攻击?
sqlite3 *db;
sqlite3_stmt *dbps;
int dbrc = sqlite3_open([dbFilePath UTF8String], &db);
if (dbrc) {
// handle error
return;
}
dbrc = sqlite3_prepare_v2 (db, sql, -1, &dbps, NULL);
sqlite3_bind_text(dbps, 1, [userContent UTF8String], -1, SQLITE_TRANSIENT);
dbrc = sqlite3_step(dbps);
if (SQLITE_DONE != dbrc) {
// handle error
}
sqlite3_finalize (dbps);
sqlite3_close(db);