数据库 | SQLite - 插入“?”字符存入数据库
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
关键字:
如果您 table 只包含问题文本字段,您应该将查询更改为 INSERT INTO premade_questions VALUES ('Do you like animals?')
如果您有更多字段,那么您应该将它们添加到值中,或者指定您只提供问题字段。例如,如果字段名称是 question
,那么您的查询应该是:INSERT INTO premade_questions (question) VALUES ('Do you like animals?')
.
我正在尝试将问题插入数据库,但是由于准备好的语句性质而遇到一些问题。错误如下:
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
关键字:
如果您 table 只包含问题文本字段,您应该将查询更改为 INSERT INTO premade_questions VALUES ('Do you like animals?')
如果您有更多字段,那么您应该将它们添加到值中,或者指定您只提供问题字段。例如,如果字段名称是 question
,那么您的查询应该是:INSERT INTO premade_questions (question) VALUES ('Do you like animals?')
.