0

Is there any way to get id of inserted row inside sqlite ? I have .plist ( which contains only array of couple keys/values ) and I have parsed into array of dictionaries. I have to insert into table_one name from key ( just once because name is the same in every dictionary inside array ) and get id and the insert dictionary like row ( three values ) into table_two but to have parent_id column set to id of previous inserted row into table_one. How to solve this ?

PaolaJ.
  • 10,872
  • 22
  • 73
  • 111
  • What library are you using? Here is how to get the last insert id using the low-level sqlite library: http://stackoverflow.com/a/6242813/866915 – ErikR Dec 18 '14 at 03:43

1 Answers1

1

In Python, the cursor object has the lastrowid attribute:

cursor.execute("INSERT INTO foo(bar, baz) VALUES (?, ?)",
               ["hello", 12345])
foo_id = cursor.lastrowid
CL.
  • 173,858
  • 17
  • 217
  • 259