Skip to content

Commit

Permalink
DBManager: better handle for not supported constraint types (fix #7544)
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed May 27, 2013
1 parent 5e28220 commit f5aef0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions python/plugins/db_manager/db_plugins/plugin.py
Expand Up @@ -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" }
Expand All @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -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]
Expand Down

0 comments on commit f5aef0f

Please sign in to comment.