[英]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.