Python Forum
[split] sqlite3 detect IntegrityError - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: [split] sqlite3 detect IntegrityError (/thread-15457.html)



[split] sqlite3 detect IntegrityError - YASHNIT - Jan-18-2019

How do I get the (extended) result/error code from an SQLite query in Python? For example:

con = sqlite3.connect("mydb.sqlite")
cur = con.cursor()
sql_query = "INSERT INTO user VALUES(?, ?)"
sql_data = ("John", "MacDonald")

try:
cur.execute(sql_query, sql)
self.con.commit()

except sqlite3.Error as er:
# get the extended result code here
Now suppose the first column should be unique and there is already a database entry with "John" in the first column. This will throw an IntegrityError, but I'd like to know the SQLite result/error code as stated on I want to know, because I want to take a different action for different errors


RE: [split] sqlite3 detect IntegrityError - buran - Jan-18-2019

If this is not question for single purpose to post spam/advertisement link (now removed), repost with BB Code tags as instructed.