Skip to content
Permalink
Browse files

Replace db.connector/self + is None

  • Loading branch information
Ailurupoda committed Feb 8, 2019
1 parent 68c541b commit 9741515faefbaf8811f6d64f181dfcc7408ab796
@@ -620,11 +620,11 @@ def runVacuum(self):
""" run vacuum on the db """
self._execute_and_commit("VACUUM")

def commentTable(self, schema, tablename, db, comment=None):
def commentTable(self, schema, tablename, comment=None):
"""Comment the table"""
return ''

def getComment(self, tablename, field, db):
def getComment(self, tablename, field):
"""Returns the comment for a field"""
return ''

@@ -1307,11 +1307,11 @@ def renameSchema(self, schema, new_schema):
# Unsupported in Oracle
pass

def commentTable(self, schema, tablename, db, comment=None):
def commentTable(self, schema, tablename, comment=None):
"""Comment the table"""
return ''

def getComment(self, tablename, field, db):
def getComment(self, tablename, field):
"""Returns the comment for a field"""
return ''

@@ -742,25 +742,25 @@ def renameTable(self, table, new_table):

self._commit()

def commentTable(self, schema, tablename, db, comment=None):
if comment == None:
db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.format(schema, tablename))
def commentTable(self, schema, tablename, comment=None):
if comment is None:
self._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.format(schema, tablename))
else:
db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(schema, tablename, comment))
self._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(schema, tablename, comment))

def getComment(self, tablename, field, db):
def getComment(self, tablename, field):
"""Returns the comment for a field"""
# SQL Query checking if a comment exists for the field
sql_cpt = "Select count(*) 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" % (tablename, field)
# SQL Query that return the comment of the 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" % (tablename, field)
c = db.connector._execute(None, sql_cpt) # Execute Check query
res = db.connector._fetchone(c)[0] # Store result
c = self._execute(None, sql_cpt) # Execute Check query
res = self._fetchone(c)[0] # Store result
if res == 1:
# When a comment exists
c = db.connector._execute(None, sql) # Execute query
res = db.connector._fetchone(c)[0] # Store result
db.connector._close_cursor(c) # Close cursor
c = self._execute(None, sql) # Execute query
res = self._fetchone(c)[0] # Store result
self._close_cursor(c) # Close cursor
return res # Return comment
else:
return ''
@@ -571,11 +571,11 @@ def runVacuum(self):
c.execute('VACUUM')
self.connection.isolation_level = '' # reset to default isolation

def commentTable(self, schema, tablename, db, comment=None):
def commentTable(self, schema, tablename, comment=None):
"""Comment the table"""
return ''

def getComment(self, tablename, field, db):
def getComment(self, tablename, field):
"""Returns the comment for a field"""
return ''

@@ -342,11 +342,11 @@ def runVacuum(self):
print("**unimplemented** runVacuum")
return False

def commentTable(self, schema, tablename, db, comment=None):
def commentTable(self, schema, tablename, comment=None):
"""Comment the table"""
return ''

def getComment(self, tablename, field, db):
def getComment(self, tablename, field):
"""Returns the comment for a field"""
return ''

@@ -67,7 +67,7 @@ def setField(self, fld):
print(tab)
field = fld.name
print(field)
res = self.db.connector.getComment(tab, field, self.db)
res = self.db.connector.getComment(tab, field)
print(res)
self.editCom.setText(res) # Set comment value
#except:
@@ -376,7 +376,8 @@ def accept(self):
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(schema, table, self.db, self.editCom.text())
com = self.editCome.text()
self.db.connector.commentTable(schema, table, com)

self.db.connection().reconnect()
self.db.refresh()
@@ -341,7 +341,7 @@ def createComment(self):
schem = self.table.schema().name
tab = self.table.name
com = self.viewComment.text()
self.db.connector.commentTable(schem, tab, self.db, com)
self.db.connector.commentTable(schem, tab, com)
except DbError as e:
DlgDbError.showError(e, self)
return
@@ -354,7 +354,7 @@ def deleteComment(self):
try:
schem = self.table.schema().name
tab = self.table.name
self.db.connector.commentTable(schem, tab, self.db)
self.db.connector.commentTable(schem, tab)
except DbError as e:
DlgDbError.showError(e, self)
return

0 comments on commit 9741515

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