You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: python/plugins/db_manager/dlg_field_properties.py
+17-12
Original file line number
Diff line number
Diff line change
@@ -56,18 +56,23 @@ def setField(self, fld):
56
56
self.chkNull.setChecked(notfld.notNull)
57
57
iffld.hasDefault:
58
58
self.editDefault.setText(fld.default)
59
-
# Check with SQL query if a comment exists for the field
60
-
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"% (self.table.name, self.editName.text())
61
-
# Get the comment for the field with SQL Query
62
-
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"% (self.table.name, self.editName.text())
res=self.db.connector._fetchone(c)[0] # Fetch data
65
-
# Check if result is 1 then it's ok, else we don't want to get a value
66
-
ifres==1:
67
-
c=self.db.connector._execute(None, sql) # Execute query returning the comment value
68
-
res=self.db.connector._fetchone(c)[0] # Fetch the comment value
69
-
self.db.connector._close_cursor(c) # Close cursor
70
-
self.editCom.setText(res) # Set comment value
59
+
# This is an ugly patch, but the comments PR https://github.com/qgis/QGIS/pull/8831 added
60
+
# support for postgres only and broke all the others :(
61
+
try:
62
+
# Check with SQL query if a comment exists for the field
63
+
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"% (self.table.name, self.editName.text())
64
+
# Get the comment for the field with SQL Query
65
+
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"% (self.table.name, self.editName.text())
Copy file name to clipboardexpand all lines: python/plugins/db_manager/dlg_table_properties.py
+15-3
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@
29
29
fromqgis.utilsimportOverrideCursor
30
30
31
31
from .db_plugins.data_modelimportTableFieldsModel, TableConstraintsModel, TableIndexesModel
32
-
from .db_plugins.pluginimportBaseError
32
+
from .db_plugins.pluginimportBaseError, DbError
33
33
from .dlg_db_errorimportDlgDbError
34
34
35
35
from .dlg_field_propertiesimportDlgFieldProperties
@@ -333,25 +333,37 @@ def deleteIndex(self):
333
333
DlgDbError.showError(e, self)
334
334
335
335
defcreateComment(self):
336
-
#Function that add a comment to the selected table
336
+
"""Adds a comment to the selected table"""
337
+
337
338
try:
338
339
#Using the db connector, executing de SQL query Comment on table
339
340
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\';'.format(self.table.schema().name, self.table.name, self.viewComment.text()))
340
341
exceptDbErrorase:
341
342
DlgDbError.showError(e, self)
342
343
return
344
+
exceptExceptionase:
345
+
# This is an ugly patch, but the comments PR https://github.com/qgis/QGIS/pull/8831 added
346
+
# support for postgres only and broke all the others :(
347
+
QMessageBox.information(self, self.tr("Add comment"), self.tr("Comments are not supported for this database."))
0 commit comments