Python Forum
[split] sqlite3 detect IntegrityError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] sqlite3 detect IntegrityError
#1
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
Reply
#2
If this is not question for single purpose to post spam/advertisement link (now removed), repost with BB Code tags as instructed.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Does Python sqlite3 detect connection errors zatlas1 6 4,040 Jan-18-2019, 06:02 AM
Last Post: zatlas1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020