[英]WebSQL | SQLite - Inserting the “?” character into the database
我試圖將一個問題插入數據庫中,但是由於准備好的語句性質而導致一些問題。 錯誤如下:
could not prepare statement (1 near ")": syntax error)
這是使用的代碼:
tx.executeSql("INSERT INTO premade_questions ('Do you like animals?')",
[],
function() { console.log("Inserted"); },
function(n, error) { console.log(error.message); }
);
當我更改代碼以使用預准備的語句時,錯誤更改為:
could not prepare statement (1 near "?": syntax error)
更改后的代碼如下:
tx.executeSql("INSERT INTO premade_questions (?)",
['Do you like animals?'],
function() { console.log("Inserted"); },
function(n, error) { console.log(error.message); }
);
我嘗試轉義了?
但是沒有運氣。
您缺少VALUES
關鍵字:
如果表僅包含問題文本字段,則應將查詢更改為INSERT INTO premade_questions VALUES ('Do you like animals?')
如果您有更多字段,則應將它們添加到值中,或指定僅提供問題字段。 例如,如果字段名稱為question
,則您的查詢應為: INSERT INTO premade_questions (question) VALUES ('Do you like animals?')
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.