758 for arg in ex.args: |
758 for arg in ex.args: |
759 # postgres, sqlserver |
759 # postgres, sqlserver |
760 mo = re.search("unique_[a-z0-9]{32}", arg) |
760 mo = re.search("unique_[a-z0-9]{32}", arg) |
761 if mo is not None: |
761 if mo is not None: |
762 raise UniqueTogetherError(session, cstrname=mo.group(0)) |
762 raise UniqueTogetherError(session, cstrname=mo.group(0)) |
763 # sqlite |
763 # old sqlite |
764 mo = re.search('columns (.*) are not unique', arg) |
764 mo = re.search('columns (.*) are not unique', arg) |
765 if mo is None: |
|
766 # sqlite > 3.7 |
|
767 mo = re.search('UNIQUE constraint failed: (.*)', arg) |
|
768 if mo is not None: # sqlite in use |
765 if mo is not None: # sqlite in use |
769 # we left chop the 'cw_' prefix of attribute names |
766 # we left chop the 'cw_' prefix of attribute names |
770 rtypes = [c.strip()[3:] |
767 rtypes = [c.strip()[3:] |
771 for c in mo.group(1).split(',')] |
768 for c in mo.group(1).split(',')] |
|
769 raise UniqueTogetherError(session, rtypes=rtypes) |
|
770 # sqlite after http://www.sqlite.org/cgi/src/info/c80e229dd9c1230a |
|
771 if arg.startswith('UNIQUE constraint failed:'): |
|
772 # message looks like: "UNIQUE constraint failed: foo.cw_bar, foo.cw_baz" |
|
773 # so drop the prefix, split on comma, drop the tablenames, and drop "cw_" |
|
774 columns = arg.split(':', 1)[1].split(',') |
|
775 rtypes = [c.split('.', 1)[1].strip()[3:] for c in columns] |
772 raise UniqueTogetherError(session, rtypes=rtypes) |
776 raise UniqueTogetherError(session, rtypes=rtypes) |
773 raise |
777 raise |
774 return cursor |
778 return cursor |
775 |
779 |
776 def doexecmany(self, session, query, args): |
780 def doexecmany(self, session, query, args): |