Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if the row has been inserted?

Tags:

python

sqlite

When using sqlite3 for python, how do I determine if a row has been successfully inserted into a table? e.g.

conn = sqlite3.connect("test.db")
c = conn.cursor()

c.execute("INSERT INTO TEST VALUES ('sample text')")

c.commit()
c.close()
like image 512
Sheldon Avatar asked Nov 09 '12 18:11

Sheldon


1 Answers

If no exception was thrown when calling execute() or commit(), it was inserted when you called commit().

Committing a transaction successfully is a guarantee from the database layer that the insert was written to disk.

like image 66
Martijn Pieters Avatar answered Nov 05 '22 07:11

Martijn Pieters