Project

General

Profile

« Previous | Next » 

Revision 3345

sql.py: ConstraintException: Also store the constraint's condition, if any

View differences:

lib/sql.py
54 54
        self.name = name
55 55

  
56 56
class ConstraintException(DbException):
57
    def __init__(self, name, cols, cause=None):
58
        DbException.__init__(self, 'Violated '+strings.as_tt(name)
59
            +' constraint on columns: '+strings.as_tt(', '.join(cols)), cause)
57
    def __init__(self, name, cond, cols, cause=None):
58
        msg = 'Violated '+strings.as_tt(name)+' constraint'
59
        if cond != None: msg += ' with condition '+cond
60
        if cols != []: msg += ' on columns: '+strings.as_tt(', '.join(cols))
61
        DbException.__init__(self, msg, cause)
60 62
        self.name = name
63
        self.cond = cond
61 64
        self.cols = cols
62 65

  
63 66
class MissingCastException(DbException):
......
512 515
                if recover: # need auto-rollback to run index_cols()
513 516
                    try: cols = index_cols(db, constraint)
514 517
                    except NotImplementedError: pass
515
                raise DuplicateKeyException(constraint, cols, e)
518
                raise DuplicateKeyException(constraint, None, cols, e)
516 519
            
517 520
            match = re.match(r'^null value in column "(.+?)" violates not-null'
518 521
                r' constraint', msg)
519
            if match: raise NullValueException('NOT NULL', [match.group(1)], e)
522
            if match:
523
                col, = match.groups()
524
                raise NullValueException('NOT NULL', None, [col], e)
520 525
            
521 526
            match = re.match(r'^(?:invalid input (?:syntax|value)\b.*?'
522 527
                r'|.+? field value out of range): "(.+?)"', msg)

Also available in: Unified diff