我正在使用Ionic 2和SQLite尝试在表中插入注释,而point_id等于特定匹配的第二个最高point_id。所以我写了下面的查询,但Ionic 2正在抛弃我
sqlite3_prepare_v2 failure: no such column: match_id
INSERT INTO comments (point_id, match_id, comment, created_at)
VALUES((
SELECT name.point_id
FROM (
SELECT point_id from undo
WHERE match_id = ?
ORDER BY point_id DESC
LIMIT 2) AS name
WHERE match_id = ?
ORDER BY point_id LIMIT 1), ?, ?, ?)
我的整个离子2代码是
NativeStorage.getItem('matchID').then(matchID => {
let query = 'INSERT INTO comments (point_id, match_id, comment, created_at) '+
'VALUES((SELECT name.point_id FROM (SELECT point_id from undo WHERE match_id = ? ORDER BY point_id DESC LIMIT 2) AS name WHERE match_id = ? ORDER BY point_id LIMIT 1), ?, ?, ?)';
this.db.executeSql(query, [matchID.value, matchID.value, matchID.value, data.comment, new Date()]).then(data_comment => {
let toast = this.toastCtrl.create({
message: 'Comment was added successfully',
duration: 2000,
position: 'top'
});
toast.present();
console.log("comment entered", data_comment);
}, err => console.error("ERROR enter comment in match tracker ", err))
})
非常感谢。
答案 0 :(得分:1)
我改变了我的SQLite查询,现在它工作正常。如果其他人需要这个,那就是:
INSERT INTO comments (point_id, match_id, comment, created_at)
VALUES((
SELECT point_id from undo
WHERE match_id = ?
ORDER BY point_id DESC
LIMIT 1 OFFSET 1), ?, ?, ?)