16 changes: 11 additions & 5 deletions python/plugins/db_manager/db_plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@
class BaseError(Exception):
"""Base class for exceptions in the plugin."""
def __init__(self, e):
msg = e if isinstance(e, (str,unicode,QString)) else e.message
if isinstance(e, Exception):
msg = e.args[0] if len(e.args) > 0 else ''
else:
msg = e

try:
msg = unicode( msg )
except UnicodeDecodeError:
msg = unicode( msg, 'utf-8' )

self.msg = msg
Exception.__init__(self, msg)

def __unicode__(self):
return self.message
return self.msg

def __str__(self):
return unicode(self).encode('utf-8')
Expand All @@ -55,7 +60,7 @@ def __init__(self, e, query=None):
self.query = unicode( query ) if query != None else None

def __unicode__(self):
if self.query == None:
if self.query is None:
return BaseError.__unicode__(self)

msg = u"Error:\n%s" % BaseError.__unicode__(self)
Expand Down Expand Up @@ -976,8 +981,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 +996,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
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions python/plugins/db_manager/dlg_db_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(self, e, parent=None):
def sanitize(txt):
return "" if txt == None else "<pre>" + txt.replace('<','&lt;') + "</pre>"

if isinstance(e, DbError) and hasattr(e, 'query'):
self.setQueryMessage( sanitize(e.message), sanitize(e.query) )
if isinstance(e, DbError):
self.setQueryMessage( sanitize(e.msg), sanitize(e.query) )
else:
self.setMessage( sanitize(e.message) )
self.setMessage( sanitize(e.msg) )

def setMessage(self, msg):
self.txtErrorMsg.setHtml(msg)
Expand Down
9 changes: 5 additions & 4 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

self.mode = self.ASK_FOR_INPUT_MODE if self.inLayer is None else self.HAS_INPUT_MODE

# updates of UI
self.setupWorkingMode( self.mode )

self.connect(self.cboSchema, SIGNAL("currentIndexChanged(int)"), self.populateTables)
self.populateSchemas()
self.populateTables()
self.populateLayers()
self.populateEncodings()

# updates of UI
self.setupWorkingMode( self.mode )
self.connect(self.cboSchema, SIGNAL("currentIndexChanged(int)"), self.populateTables)



def setupWorkingMode(self, mode):
""" hide the widget to select a layer/file if the input layer
Expand Down