Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix create and delete comment from tableProperties
  • Loading branch information
Ailurupoda committed Feb 7, 2019
1 parent f3dfd97 commit 63c010d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
6 changes: 6 additions & 0 deletions python/plugins/db_manager/db_plugins/gpkg/connector.py
Expand Up @@ -624,6 +624,12 @@ def commentTable(self, schema, tablename, comment):
"""Comment the table"""
return ''

def commentTable(self, schema, tablename, comment):
return ''

def unCommentTable(self, schema, tablename):
return ''

def getComment(self, tab, field, db):
"""Returns the comment for a field"""
return ''
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/db_manager/db_plugins/oracle/connector.py
Expand Up @@ -1311,6 +1311,12 @@ def commentTable(self, schema, tablename, comment):
"""Comment the table"""
return ''

def commentTable(self, schema, tablename, comment):
return ''

def unCommentTable(self, schema, tablename):
return ''

def getComment(self, tab, field, db):
"""Returns the comment for a field"""
return ''
Expand Down
8 changes: 5 additions & 3 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -743,8 +743,11 @@ def renameTable(self, table, new_table):

self._commit()

def commentTable(self, schema, tablename, comment):
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\''.format(schema, tablename, comment))
def commentTable(self, schema, tablename, comment, db):
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):
"""Returns the comment for a field"""
Expand All @@ -754,7 +757,6 @@ def getComment(self, tab, field, db):
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
res = db.connector._fetchone(c)[0] # Store result
print(tab, field, sql_cpt, sql)
if res == 1:
# When a comment exists
c = db.connector._execute(None, sql) # Execute query
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/db_manager/db_plugins/spatialite/connector.py
Expand Up @@ -575,6 +575,12 @@ def commentTable(self, schema, tablename, comment):
"""Comment the table"""
return ''

def commentTable(self, schema, tablename, comment):
return ''

def unCommentTable(self, schema, tablename):
return ''

def getComment(self, tab, field, db):
"""Returns the comment for a field"""
return ''
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/db_manager/db_plugins/vlayers/connector.py
Expand Up @@ -346,6 +346,12 @@ def commentTable(self, schema, tablename, comment):
"""Comment the table"""
return ''

def commentTable(self, schema, tablename, comment):
return ''

def unCommentTable(self, schema, tablename):
return ''

def getComment(self, tab, field, db):
"""Returns the comment for a field"""
return ''
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -373,9 +373,10 @@ def accept(self):
self.db.connector.createSpatialIndex((schema, table), geom)

# add comment on table
supportCom = self.db.supportsComment()
if self.chkCom.isEnabled() and self.chkCom.isChecked() and supportCom == True:
# 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.refresh()
Expand Down
11 changes: 7 additions & 4 deletions python/plugins/db_manager/dlg_table_properties.py
Expand Up @@ -338,8 +338,10 @@ def deleteIndex(self):
def createComment(self):
"""Adds a comment to the selected table"""
try:
#Using the db connector, executing de SQL query Comment on table
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(self.table.schema().name, self.table.name, self.viewComment.text()))
schem = self.table.schema().name
tab = self.table.name
com = self.viewComment.text()
self.db.connector.commentTable(schem, tab, com, self.db)
except DbError as e:
DlgDbError.showError(e, self)
return
Expand All @@ -350,8 +352,9 @@ def createComment(self):
def deleteComment(self):
"""Drops the comment on the selected table"""
try:
#Using the db connector, executing de SQL query Comment on table using the NULL definition
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.format(self.table.schema().name, self.table.name))
schem = self.table.schema().name
tab = self.table.name
self.db.connector.unCommentTable(schem, tab, self.db)
except DbError as e:
DlgDbError.showError(e, self)
return
Expand Down

0 comments on commit 63c010d

Please sign in to comment.