我正在尝试清理我对 SQLite 数据库的输入,并且我正在使用sqlite3_mprintf
它,但我得到了一些奇怪的结果。我尝试了不同的变化,我做错了吗?
const char * zChar = "It's a nice day";
cout << sqlite3_mprintf("INSERT INTO table(col1) VALUES('%Q')", zChar) << endl;
//INSERT INTO table(col1) VALUES(''It''s a nice day'')
cout << sqlite3_mprintf("INSERT INTO table(col1) VALUES(%Q)", zChar) << endl;
//INSERT INTO table(col1) VALUES('It''s a nice day')
cout << sqlite3_mprintf("INSERT INTO table(col1) VALUES('%q')", zChar) << endl;
//INSERT INTO table(col1) VALUES('It''s a nice day')
cout << sqlite3_mprintf("INSERT INTO table(col1) VALUES(%q)", zChar) << endl;
//INSERT INTO table(col1) VALUES(It''s a nice day)