Fix create and delete comment from tableProperties

This commit is contained in:
Ailurupoda 2019-02-07 09:56:48 +01:00
parent f3dfd97d90
commit 63c010dbb5
7 changed files with 38 additions and 8 deletions

View File

@ -624,6 +624,12 @@ class GPKGDBConnector(DBConnector):
"""Comment the table""" """Comment the table"""
return '' return ''
def commentTable(self, schema, tablename, comment):
return ''
def unCommentTable(self, schema, tablename):
return ''
def getComment(self, tab, field, db): def getComment(self, tab, field, db):
"""Returns the comment for a field""" """Returns the comment for a field"""
return '' return ''

View File

@ -1311,6 +1311,12 @@ class OracleDBConnector(DBConnector):
"""Comment the table""" """Comment the table"""
return '' return ''
def commentTable(self, schema, tablename, comment):
return ''
def unCommentTable(self, schema, tablename):
return ''
def getComment(self, tab, field, db): def getComment(self, tab, field, db):
"""Returns the comment for a field""" """Returns the comment for a field"""
return '' return ''

View File

@ -743,8 +743,11 @@ class PostGisDBConnector(DBConnector):
self._commit() self._commit()
def commentTable(self, schema, tablename, comment): def commentTable(self, schema, tablename, comment, db):
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\''.format(schema, tablename, comment)) db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(schema, tablename, comment))
def unCommentTable(self, schema, tablename, db):
db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.format(schema, tablename))
def getComment(self, tab, field, db): def getComment(self, tab, field, db):
"""Returns the comment for a field""" """Returns the comment for a field"""
@ -754,7 +757,6 @@ class PostGisDBConnector(DBConnector):
sql = "Select pd.description from pg_description pd, pg_class pc, pg_attribute pa where relname = '%s' and attname = '%s' and pa.attrelid = pc.oid and pd.objoid = pc.oid and pd.objsubid = pa.attnum" % (tab, field) sql = "Select pd.description from pg_description pd, pg_class pc, pg_attribute pa where relname = '%s' and attname = '%s' and pa.attrelid = pc.oid and pd.objoid = pc.oid and pd.objsubid = pa.attnum" % (tab, field)
c = db.connector._execute(None, sql_cpt) # Execute Check query c = db.connector._execute(None, sql_cpt) # Execute Check query
res = db.connector._fetchone(c)[0] # Store result res = db.connector._fetchone(c)[0] # Store result
print(tab, field, sql_cpt, sql)
if res == 1: if res == 1:
# When a comment exists # When a comment exists
c = db.connector._execute(None, sql) # Execute query c = db.connector._execute(None, sql) # Execute query

View File

@ -575,6 +575,12 @@ class SpatiaLiteDBConnector(DBConnector):
"""Comment the table""" """Comment the table"""
return '' return ''
def commentTable(self, schema, tablename, comment):
return ''
def unCommentTable(self, schema, tablename):
return ''
def getComment(self, tab, field, db): def getComment(self, tab, field, db):
"""Returns the comment for a field""" """Returns the comment for a field"""
return '' return ''

View File

@ -346,6 +346,12 @@ class VLayerConnector(DBConnector):
"""Comment the table""" """Comment the table"""
return '' return ''
def commentTable(self, schema, tablename, comment):
return ''
def unCommentTable(self, schema, tablename):
return ''
def getComment(self, tab, field, db): def getComment(self, tab, field, db):
"""Returns the comment for a field""" """Returns the comment for a field"""
return '' return ''

View File

@ -373,9 +373,10 @@ class DlgImportVector(QDialog, Ui_Dialog):
self.db.connector.createSpatialIndex((schema, table), geom) self.db.connector.createSpatialIndex((schema, table), geom)
# add comment on table # add comment on table
supportCom = self.db.supportsComment()
if self.chkCom.isEnabled() and self.chkCom.isChecked() and supportCom == True: if self.chkCom.isEnabled() and self.chkCom.isChecked() and supportCom == True:
# using connector executing COMMENT ON TABLE query (with editCome.text() value) # using connector executing COMMENT ON TABLE query (with editCome.text() value)
self.db.connector.commentTable(db, schema, table, self.editCom.text()) self.db.connector.commentTable(schema, table, self.editCom.text(), self.db)
self.db.connection().reconnect() self.db.connection().reconnect()
self.db.refresh() self.db.refresh()

View File

@ -338,8 +338,10 @@ class DlgTableProperties(QDialog, Ui_Dialog):
def createComment(self): def createComment(self):
"""Adds a comment to the selected table""" """Adds a comment to the selected table"""
try: try:
#Using the db connector, executing de SQL query Comment on table schem = self.table.schema().name
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(self.table.schema().name, self.table.name, self.viewComment.text())) tab = self.table.name
com = self.viewComment.text()
self.db.connector.commentTable(schem, tab, com, self.db)
except DbError as e: except DbError as e:
DlgDbError.showError(e, self) DlgDbError.showError(e, self)
return return
@ -350,8 +352,9 @@ class DlgTableProperties(QDialog, Ui_Dialog):
def deleteComment(self): def deleteComment(self):
"""Drops the comment on the selected table""" """Drops the comment on the selected table"""
try: try:
#Using the db connector, executing de SQL query Comment on table using the NULL definition schem = self.table.schema().name
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.format(self.table.schema().name, self.table.name)) tab = self.table.name
self.db.connector.unCommentTable(schem, tab, self.db)
except DbError as e: except DbError as e:
DlgDbError.showError(e, self) DlgDbError.showError(e, self)
return return