Skip to content
Permalink
Browse files

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

  • Loading branch information
brushtyler committed May 27, 2013
1 parent 5e28220 commit f5aef0f54976bc3a688e4704660a0a08ba340c3d
@@ -976,8 +976,8 @@ def update(self, new_name, new_type_str=None, new_not_null=None, new_default_str
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 @@ def type2String(self):
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):
@@ -321,9 +321,13 @@ def __init__(self, row, table):
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]

0 comments on commit f5aef0f

Please sign in to comment.
You can’t perform that action at this time.