Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:09:57+00:00 2026-05-26T20:09:57+00:00

In a project I started out with MySQL as database. Instead of checking first,

  • 0

In a project I started out with MySQL as database. Instead of checking first, I just do an insert and if I get an IntegrityError exception with code 1062, I know that there is a duplicate entry and warn the user, to do this and that.

that looks basically like this:

try:
    # add duplicate, nothing bad happens yet, is only in sqla session
    db.session.add(User(email='already_used_email@address_that_has_to_be_unique.com'))
    # commit, now the IntegrityError is raised, when sqla inserts
    db.session.commit()
except IntegrityError as e:
    db.session.rollback()
    # this is what i do with mysql, check the exception for code 1062
    # how can i replace this with something db independent?
    code, msg = e.orig
    if code == 1062:
        # send warning
        pass

Now, for one this makes it already impossible to test with eg. in-memory sqlite. Not nice, but I could live with that.

Second however, I might (have to/want to for other out of scope of this question issues) switch to Postgres. Of course I could just change the code to (also) check for Postgres error codes, but I was hoping there is a way to have SQLALchemy tell me, that a duplicate happened independent from the database. A database dialect abstraction…?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:09:59+00:00Added an answer on May 26, 2026 at 8:09 pm

    What you want to search for is something called “SQLSTATE” – a set of standard error codes that cover most common RDBMS error states. They don’t necessarily provide enough detail for all purposes though, and I don’t know if sqlite supports them.

    • http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html
    • http://dev.mysql.com/doc/refman/5.0/en/error-handling.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive inherited some code which started out as an Android project but really is
I have just started learning Erlang and am trying out some Project Euler problems
just started building out a rails project from scratch after months of re-purposing of
We had a test project that started out as MbUnit v3 / Gallio but
This is a project I'm doing for my own amusement. I started out wanting
Have just started out with EF for Oracle in targeting .Net 4.0. Have added
I'm working on a Haskell project and I started out by organizing it like
I started out with a navigation based project and am pushing further views onto
I am working on a CakePHP 2 project. It originally started out in 2.0.x
I've just started looking at a project that has >20k unit tests written in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.