javascript – Websql插入查询
作者:互联网
我是新的websql.i无法在websql中插入主键.
创建查询
db.transaction(function (tx) {
var sql =
"CREATE TABLE vehicles ( "+
"id integer primary key autoincrement,"+
"vehicle_ref_no VARCHAR(255),"+
"vehicle_plate_no VARCHAR(255),"+
)";
tx.executeSql(sql);
});
插入查询
db.transaction(
function (tx) {
tx.executeSql(
"INSERT INTO vehicles VALUES (?, ?)",
[data.vehicle_ref_no,
data.vehicle_plate_no,
],
function (tx, result) {
console.log("Query Success");
},
function (tx, error) {
console.log("Query Error: " + error.message);
}
);
},
function (error) {
console.log("Transaction Error: " + error.message);
},
function () {
console.log("Transaction Success");
}
);
这段代码不添加自动增量值,任何想法?
除了我以外,还有什么好方法吗?
解决方法:
您的INSERT语句不正确.您应该包括除id之外的列的名称
INSERT INTO vehicles (vehicle_ref_no, vehicle_plate_no) VALUES (?, ?);
或者为id传递NULL
INSERT INTO vehicles (id, vehicle_ref_no, vehicle_plate_no) VALUES (NULL, ?, ?);
要不就
INSERT INTO vehicles VALUES (NULL, ?, ?);
这是SQLFiddle演示
标签:javascript,database,html5,sql,web-sql 来源: https://codeday.me/bug/20190529/1176061.html