SQLite中的“插入如果不存在”语句我有一个SQLite数据库。我试图插入值(users_id, lessoninfo_id)在餐桌上bookmarks,只有在这两者都不存在的情况下才行。INSERT INTO bookmarks(users_id,lessoninfo_id) VALUES(
(SELECT _id FROM Users WHERE User='"+$('#user_lesson').html()+"'),
(SELECT _id FROM lessoninfo
WHERE Lesson="+lesson_no+" AND cast(starttime AS int)="+Math.floor(result_set.rows.item(markerCount-1).starttime)+")
WHERE NOT EXISTS (
SELECT users_id,lessoninfo_id from bookmarks
WHERE users_id=(SELECT _id FROM Users
WHERE User='"+$('#user_lesson').html()+"') AND lessoninfo_id=(
SELECT _id FROM lessoninfo WHERE Lesson="+lesson_no+")))这会产生一个错误,即:语法附近的DB错误。
3 回答
慕村225694
TA贡献1880条经验 获得超4个赞
哈士奇WWW
TA贡献1799条经验 获得超6个赞
CREATE TABLE bookmarks( users_id INTEGER, lessoninfo_id INTEGER, UNIQUE(users_id, lessoninfo_id));
INSERT OR IGNORE INTO bookmarks(users_id, lessoninfo_id) VALUES(123, 456)
添加回答
举报
0/150
提交
取消