Skip to content

Commit f3dfd97

Browse files
committed
New fix, still some need to be done
1 parent dff1853 commit f3dfd97

15 files changed

Lines changed: 127 additions & 66 deletions

File tree

python/plugins/db_manager/db_plugins/connector.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,4 @@ def getSqlDictionary(self):
232232
return []
233233

234234
def getQueryBuilderDictionary(self):
235-
return {}
236-
237-
def setField(self, fld, tablename=None, db=None):
238-
if fld is None:
239-
return
240-
return fld.name, fld.dataType, str(fld.modifier), fld.notNull, fld.default, None
235+
return {}

python/plugins/db_manager/db_plugins/gpkg/connector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,14 @@ def runVacuum(self):
620620
""" run vacuum on the db """
621621
self._execute_and_commit("VACUUM")
622622

623+
def commentTable(self, schema, tablename, comment):
624+
"""Comment the table"""
625+
return ''
626+
627+
def getComment(self, tab, field, db):
628+
"""Returns the comment for a field"""
629+
return ''
630+
623631
def addTableColumn(self, table, field_def):
624632
""" add a column to table """
625633

python/plugins/db_manager/db_plugins/gpkg/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=
177177
vl.setSubsetString(sql)
178178
return vl
179179

180-
def searchClass(self):
181-
return "GPKGDatabase"
180+
def supportsComment(self):
181+
return False
182182

183183

184184
class GPKGTable(Table):

python/plugins/db_manager/db_plugins/oracle/connector.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,16 @@ def updateCache(self, tableList, schema=None):
475475

476476
def singleGeomTypes(self, geomtypes, srids):
477477
"""Intelligent wkbtype grouping (multi with non multi)"""
478-
if (QgsWkbTypes.Polygon in geomtypes and
479-
QgsWkbTypes.MultiPolygon in geomtypes):
478+
if (QgsWkbTypes.Polygon in geomtypes
479+
and QgsWkbTypes.MultiPolygon in geomtypes):
480480
srids.pop(geomtypes.index(QgsWkbTypes.Polygon))
481481
geomtypes.pop(geomtypes.index(QgsWkbTypes.Polygon))
482-
if (QgsWkbTypes.Point in geomtypes and
483-
QgsWkbTypes.MultiPoint in geomtypes):
482+
if (QgsWkbTypes.Point in geomtypes
483+
and QgsWkbTypes.MultiPoint in geomtypes):
484484
srids.pop(geomtypes.index(QgsWkbTypes.Point))
485485
geomtypes.pop(geomtypes.index(QgsWkbTypes.Point))
486-
if (QgsWkbTypes.LineString in geomtypes and
487-
QgsWkbTypes.MultiLineString in geomtypes):
486+
if (QgsWkbTypes.LineString in geomtypes
487+
and QgsWkbTypes.MultiLineString in geomtypes):
488488
srids.pop(geomtypes.index(QgsWkbTypes.LineString))
489489
geomtypes.pop(geomtypes.index(QgsWkbTypes.LineString))
490490
if QgsWkbTypes.Unknown in geomtypes and len(geomtypes) > 1:
@@ -1306,6 +1306,14 @@ def renameSchema(self, schema, new_schema):
13061306
"""Rename a schema in the database."""
13071307
# Unsupported in Oracle
13081308
pass
1309+
1310+
def commentTable(self, schema, tablename, comment):
1311+
"""Comment the table"""
1312+
return ''
1313+
1314+
def getComment(self, tab, field, db):
1315+
"""Returns the comment for a field"""
1316+
return ''
13091317

13101318
def addTableColumn(self, table, field_def):
13111319
"""Add a column to a table."""

python/plugins/db_manager/db_plugins/oracle/plugin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def connect(self, parent=None):
9191
uri = QgsDataSourceUri()
9292

9393
settingsList = ["host", "port", "database", "username", "password"]
94-
host, port, database, username, password = [settings.value(x, "", type=str) for x in settingsList]
94+
host, port, database, username, password = [
95+
settings.value(x, "", type=str) for x in settingsList]
9596

9697
# get all of the connexion options
9798

@@ -202,7 +203,8 @@ def toSqlLayer(self, sql, geomCol, uniqueCol,
202203
uri = self.uri()
203204
con = self.database().connector
204205

205-
uri.setDataSource(u"", u"({}\n)".format(sql), geomCol, filter, uniqueCol.strip(u'"'))
206+
uri.setDataSource(u"", u"({}\n)".format(
207+
sql), geomCol, filter, uniqueCol.strip(u'"'))
206208
if avoidSelectById:
207209
uri.disableSelectAtId(True)
208210
provider = self.dbplugin().providerName()
@@ -261,8 +263,8 @@ def registerDatabaseActions(self, mainWindow):
261263
mainWindow.registerAction(action, QApplication.translate(
262264
"DBManagerPlugin", "&Table"), self.emptyTableActionSlot)
263265

264-
def searchClass(self):
265-
return "ORDatabase"
266+
def supportsComment(self):
267+
return False
266268

267269

268270
class ORSchema(Schema):
@@ -525,7 +527,7 @@ def __init__(self, row, table):
525527
def type2String(self):
526528
if (u"TIMESTAMP" in self.dataType or
527529
self.dataType in [u"DATE", u"SDO_GEOMETRY",
528-
u"BINARY_FLOAT", u"BINARY_DOUBLE"]):
530+
u"BINARY_FLOAT", u"BINARY_DOUBLE"]):
529531
return u"{}".format(self.dataType)
530532
if self.charMaxLen in [None, -1]:
531533
return u"{}".format(self.dataType)

python/plugins/db_manager/db_plugins/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ def definition(self):
10961096
return txt
10971097

10981098
def getComment(self):
1099+
"""Returns the comment for a field"""
10991100
return ''
11001101

11011102
def delete(self):

python/plugins/db_manager/db_plugins/postgis/connector.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def getInfo(self):
193193
self._close_cursor(c)
194194
return res
195195

196+
196197
def getSpatialInfo(self):
197198
""" returns tuple about PostGIS support:
198199
- lib version
@@ -511,25 +512,6 @@ def getTableFields(self, table):
511512
self._close_cursor(c)
512513
return res
513514

514-
def setField(self, fld, tablename, db):
515-
if fld is None:
516-
return
517-
print (tablename)
518-
# Check with SQL query if a comment exists for the field
519-
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, fld.name)
520-
# Get the comment for the field with SQL Query
521-
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, fld.name)
522-
c = db.connector._execute(None, sql_cpt) # Execute check query
523-
res = db.connector._fetchone(c)[0] # Fetch data
524-
# Check if result is 1 then it's ok, else we don't want to get a value
525-
if res == 1:
526-
c = db.connector._execute(None, sql) # Execute query returning the comment value
527-
res2 = db.connector._fetchone(c)[0] # Fetch the comment value
528-
db.connector._close_cursor(c) # Close cursor
529-
else :
530-
res2 = None
531-
return fld.name, fld.dataType, str(fld.modifier), fld.notNull, fld.default, res2
532-
533515
def getTableIndexes(self, table):
534516
""" get info about table's indexes. ignore primary key constraint index, they get listed in constraints """
535517
schema, tablename = self.getSchemaTableName(table)
@@ -761,6 +743,27 @@ def renameTable(self, table, new_table):
761743

762744
self._commit()
763745

746+
def commentTable(self, schema, tablename, comment):
747+
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\''.format(schema, tablename, comment))
748+
749+
def getComment(self, tab, field, db):
750+
"""Returns the comment for a field"""
751+
# SQL Query checking if a comment exists for the field
752+
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" % (tab, field)
753+
# SQL Query that return the comment of the field
754+
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)
755+
c = db.connector._execute(None, sql_cpt) # Execute Check query
756+
res = db.connector._fetchone(c)[0] # Store result
757+
print(tab, field, sql_cpt, sql)
758+
if res == 1:
759+
# When a comment exists
760+
c = db.connector._execute(None, sql) # Execute query
761+
res = db.connector._fetchone(c)[0] # Store result
762+
db.connector._close_cursor(c) # Close cursor
763+
return res # Return comment
764+
else:
765+
return ''
766+
764767
def moveTableToSchema(self, table, new_schema):
765768
schema, tablename = self.getSchemaTableName(table)
766769
if new_schema == schema:

python/plugins/db_manager/db_plugins/postgis/plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def runRefreshMaterializedViewSlot(self, item, action, parent):
181181
def hasLowercaseFieldNamesOption(self):
182182
return True
183183

184-
def searchClass(self):
185-
return "PGDatabase"
184+
def supportsComment(self):
185+
return True
186186

187187

188188
class PGSchema(Schema):
@@ -399,7 +399,7 @@ def __init__(self, row, table):
399399
if con.type == TableConstraint.TypePrimaryKey and self.num in con.columns:
400400
self.primaryKey = True
401401
break
402-
402+
403403
def getComment(self):
404404
"""Returns the comment for a field"""
405405
tab = self.table()
@@ -419,6 +419,7 @@ def getComment(self):
419419
return ''
420420

421421

422+
422423
class PGTableConstraint(TableConstraint):
423424

424425
def __init__(self, row, table):

python/plugins/db_manager/db_plugins/spatialite/connector.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ def deleteTable(self, table):
465465
self._execute(c, sql)
466466
self._commit()
467467

468+
return True
469+
468470
def emptyTable(self, table):
469471
""" delete all rows from table """
470472
if self.isRasterTable(table):
@@ -494,6 +496,7 @@ def renameTable(self, table, new_table):
494496
self._execute(c, sql)
495497

496498
self._commit()
499+
return True
497500

498501
def moveTable(self, table, new_table, new_schema=None):
499502
return self.renameTable(table, new_table)
@@ -568,10 +571,28 @@ def runVacuum(self):
568571
c.execute('VACUUM')
569572
self.connection.isolation_level = '' # reset to default isolation
570573

574+
def commentTable(self, schema, tablename, comment):
575+
"""Comment the table"""
576+
return ''
577+
578+
def getComment(self, tab, field, db):
579+
"""Returns the comment for a field"""
580+
return ''
581+
571582
def addTableColumn(self, table, field_def):
572583
""" add a column to table """
573584
sql = u"ALTER TABLE %s ADD %s" % (self.quoteId(table), field_def)
574585
self._execute_and_commit(sql)
586+
self._execute(None, sql)
587+
588+
sql = u"SELECT InvalidateLayerStatistics(%s)" % (self.quoteId(table))
589+
self._execute(None, sql)
590+
591+
sql = u"SELECT UpdateLayerStatistics(%s)" % (self.quoteId(table))
592+
self._execute(None, sql)
593+
594+
self._commit()
595+
return True
575596

576597
def deleteTableColumn(self, table, column):
577598
""" delete column from a table """

python/plugins/db_manager/db_plugins/spatialite/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def explicitSpatialIndex(self):
175175
def spatialIndexClause(self, src_table, src_column, dest_table, dest_column):
176176
return u""" "%s".ROWID IN (\nSELECT ROWID FROM SpatialIndex WHERE f_table_name='%s' AND search_frame="%s"."%s") """ % (src_table, src_table, dest_table, dest_column)
177177

178-
def searchClass(self):
179-
return "SLDatabase"
178+
def supportsComment(self):
179+
return False
180180

181181

182182
class SLTable(Table):

0 commit comments

Comments
 (0)