“Insert if not exists” statement in SQLite

I have an SQLite database. I am trying to insert values (users_id, lessoninfo_id) in table bookmarks, only if both do not exist before in a row. 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 … Read more

How to retrieve inserted id after inserting row in SQLite using Python?

How to retrieve inserted id after inserting row in SQLite using Python? I have table like this: id INT AUTOINCREMENT PRIMARY KEY, username VARCHAR(50), password VARCHAR(50) I insert a new row with example data username=”test” and password=”test”. How do I retrieve the generated id in a transaction safe way? This is for a website solution, … Read more