diff --git a/oslo/db/sqlalchemy/session.py b/oslo/db/sqlalchemy/session.py index 758ca19..c7ef0f2 100644 --- a/oslo/db/sqlalchemy/session.py +++ b/oslo/db/sqlalchemy/session.py @@ -328,12 +328,20 @@ class SqliteForeignKeysListener(PoolListener): # N columns - (IntegrityError) duplicate key value violates unique # constraint "name_of_our_constraint" # -# mysql: +# mysql+mysqldb: # 1 column - (IntegrityError) (1062, "Duplicate entry 'value_of_c1' for key # 'c1'") # N columns - (IntegrityError) (1062, "Duplicate entry 'values joined # with -' for key 'name_of_our_constraint'") # +# mysql+mysqlconnector: +# http://docs.sqlalchemy.org/en/rel_0_9/dialects/ +# mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector +# 1 column - (IntegrityError) 1062 (23000): Duplicate entry 'value_of_c1' for +# key 'c1' +# N columns - (IntegrityError) 1062 (23000): Duplicate entry 'values +# joined with -' for key 'name_of_our_constraint' +# # ibm_db_sa: # N columns - (IntegrityError) SQL0803N One or more values in the INSERT # statement, UPDATE statement, or foreign key update caused by a @@ -344,8 +352,9 @@ class SqliteForeignKeysListener(PoolListener): _DUP_KEY_RE_DB = { "sqlite": (re.compile(r"^.*columns?([^)]+)(is|are)\s+not\s+unique$"), re.compile(r"^.*UNIQUE\s+constraint\s+failed:\s+(.+)$")), - "postgresql": (re.compile(r"^.*duplicate\s+key.*\"([^\"]+)\"\s*\n.*$"),), - "mysql": (re.compile(r"^.*\(1062,.*'([^\']+)'\"\)$"),), + "postgresql": (re.compile(r'^.*duplicate\s+key.*"([^"]+)"\s*\n.*$'),), + "mysql": (re.compile( + r"^.*\b1062\b.*Duplicate entry '[^']+' for key '([^']+)'.*$"),), "ibm_db_sa": (re.compile(r"^.*SQL0803N.*$"),), } diff --git a/tests/sqlalchemy/test_utils.py b/tests/sqlalchemy/test_utils.py index a24a83a..effa884 100644 --- a/tests/sqlalchemy/test_utils.py +++ b/tests/sqlalchemy/test_utils.py @@ -719,13 +719,20 @@ class TestRaiseDuplicateEntryError(test_base.BaseTestCase): '(IntegrityError) UNIQUE constraint failed: tbl.a, tbl.b' ) - def test_mysql(self): + def test_mysql_mysqldb(self): self._test_impl( 'mysql', '(IntegrityError) (1062, "Duplicate entry ' '\'2-3\' for key \'uniq_tbl0a0b\'")' ) + def test_mysql_mysqlconnector(self): + self._test_impl( + 'mysql', + '(IntegrityError) 1062 (23000): Duplicate entry ' + '\'2-3\' for key \'uniq_tbl0a0b\'', + ) + def test_postgresql(self): self._test_impl( 'postgresql',