44 from logilab.database import get_db_helper, sqlgen |
44 from logilab.database import get_db_helper, sqlgen |
45 |
45 |
46 from yams.schema import role_name |
46 from yams.schema import role_name |
47 |
47 |
48 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary, |
48 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary, |
49 UniqueTogetherError, UndoTransactionException) |
49 UniqueTogetherError, UndoTransactionException, ViolatedConstraint) |
50 from cubicweb import transaction as tx, server, neg_role |
50 from cubicweb import transaction as tx, server, neg_role |
51 from cubicweb.utils import QueryCache |
51 from cubicweb.utils import QueryCache |
52 from cubicweb.schema import VIRTUAL_RTYPES |
52 from cubicweb.schema import VIRTUAL_RTYPES |
53 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
53 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
54 from cubicweb.server import hook |
54 from cubicweb.server import hook |
729 # message looks like: "UNIQUE constraint failed: foo.cw_bar, foo.cw_baz" |
729 # message looks like: "UNIQUE constraint failed: foo.cw_bar, foo.cw_baz" |
730 # so drop the prefix, split on comma, drop the tablenames, and drop "cw_" |
730 # so drop the prefix, split on comma, drop the tablenames, and drop "cw_" |
731 columns = arg.split(':', 1)[1].split(',') |
731 columns = arg.split(':', 1)[1].split(',') |
732 rtypes = [c.split('.', 1)[1].strip()[3:] for c in columns] |
732 rtypes = [c.split('.', 1)[1].strip()[3:] for c in columns] |
733 raise UniqueTogetherError(cnx, rtypes=rtypes) |
733 raise UniqueTogetherError(cnx, rtypes=rtypes) |
|
734 |
|
735 mo = re.search('"cstr[a-f0-9]{32}"', arg) |
|
736 if mo is not None: |
|
737 # postgresql |
|
738 raise ViolatedConstraint(cnx, cstrname=mo.group(0)[1:-1]) |
|
739 if arg.startswith('CHECK constraint failed:'): |
|
740 # sqlite3 (new) |
|
741 raise ViolatedConstraint(cnx, cstrname=arg.split(':', 1)[1].strip()) |
|
742 mo = re.match('^constraint (cstr.*) failed$', arg) |
|
743 if mo is not None: |
|
744 # sqlite3 (old) |
|
745 raise ViolatedConstraint(cnx, cstrname=mo.group(1)) |
734 raise |
746 raise |
735 return cursor |
747 return cursor |
736 |
748 |
737 def doexecmany(self, cnx, query, args): |
749 def doexecmany(self, cnx, query, args): |
738 """Execute a query. |
750 """Execute a query. |