DBManager: better handle for not supported constraint types (fix #7544)

This commit is contained in:
Giuseppe Sucameli 2013-05-27 01:24:56 +02:00
parent 5e282206c9
commit f5aef0f549
2 changed files with 9 additions and 4 deletions

View File

@ -976,8 +976,8 @@ class TableField(TableSubItemObject):
class TableConstraint(TableSubItemObject):
""" class that represents a constraint of a table (relation) """
TypeCheck, TypeForeignKey, TypePrimaryKey, TypeUnique = range(4)
types = { "c" : TypeCheck, "f" : TypeForeignKey, "p" : TypePrimaryKey, "u" : TypeUnique }
TypeCheck, TypeForeignKey, TypePrimaryKey, TypeUnique, TypeExclusion, TypeUnknown = range(6)
types = { "c" : TypeCheck, "f" : TypeForeignKey, "p" : TypePrimaryKey, "u" : TypeUnique, "x" : TypeExclusion }
onAction = { "a" : "NO ACTION", "r" : "RESTRICT", "c" : "CASCADE", "n" : "SET NULL", "d" : "SET DEFAULT" }
matchTypes = { "u" : "UNSPECIFIED", "f" : "FULL", "p" : "PARTIAL" }
@ -991,6 +991,7 @@ class TableConstraint(TableSubItemObject):
if self.type == TableConstraint.TypePrimaryKey: return "Primary key"
if self.type == TableConstraint.TypeForeignKey: return "Foreign key"
if self.type == TableConstraint.TypeUnique: return "Unique"
if self.type == TableConstraint.TypeExclusion: return "Exclusion"
return 'Unknown'
def fields(self):

View File

@ -321,9 +321,13 @@ class PGTableField(TableField):
class PGTableConstraint(TableConstraint):
def __init__(self, row, table):
TableConstraint.__init__(self, table)
self.name, constr_type, self.isDefferable, self.isDeffered, columns = row[:5]
self.name, constr_type_str, self.isDefferable, self.isDeffered, columns = row[:5]
self.columns = map(int, columns.split(' '))
self.type = TableConstraint.types[constr_type] # convert to enum
if constr_type_str in TableConstraint.types:
self.type = TableConstraint.types[constr_type_str]
else:
self.type = TableConstraint.TypeUnknown
if self.type == TableConstraint.TypeCheck:
self.checkSource = row[5]