diff --git a/python/plugins/db_manager/dlg_import_vector.py b/python/plugins/db_manager/dlg_import_vector.py index dd65310636d..82076b8614c 100644 --- a/python/plugins/db_manager/dlg_import_vector.py +++ b/python/plugins/db_manager/dlg_import_vector.py @@ -156,7 +156,6 @@ class DlgImportVector(QDialog, Ui_Dialog): settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath()) settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat) - self.cboInputLayer.setCurrentIndex(-1) self.cboInputLayer.setEditText(filename) def reloadInputLayer(self): @@ -369,6 +368,11 @@ class DlgImportVector(QDialog, Ui_Dialog): if self.chkSpatialIndex.isEnabled() and self.chkSpatialIndex.isChecked(): self.db.connector.createSpatialIndex((schema, table), geom) + # add comment on table + if self.chkCom.isEnabled() and self.chkCom.isChecked(): + # using connector executing COMMENT ON TABLE query (with editCome.text() value) + self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}E\''.format(schema, table, self.editCom.text())) + self.db.connection().reconnect() self.db.refresh() QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful.")) diff --git a/python/plugins/db_manager/dlg_table_properties.py b/python/plugins/db_manager/dlg_table_properties.py index 107a516a2df..36a2685153c 100644 --- a/python/plugins/db_manager/dlg_table_properties.py +++ b/python/plugins/db_manager/dlg_table_properties.py @@ -59,6 +59,10 @@ class DlgTableProperties(QDialog, Ui_Dialog): m = TableIndexesModel(self) self.viewIndexes.setModel(m) + #Display comment in line edit + m = self.table.comment + self.viewComment.setText(m) + self.btnAddColumn.clicked.connect(self.addColumn) self.btnAddGeometryColumn.clicked.connect(self.addGeometryColumn) self.btnEditColumn.clicked.connect(self.editColumn) @@ -71,6 +75,11 @@ class DlgTableProperties(QDialog, Ui_Dialog): self.btnAddSpatialIndex.clicked.connect(self.createSpatialIndex) self.btnDeleteIndex.clicked.connect(self.deleteIndex) + #Connect button add Comment to function + self.btnAddComment.clicked.connect(self.createComment) + #Connect button delete Comment to function + self.btnDeleteComment.clicked.connect(self.deleteComment) + self.refresh() def refresh(self): @@ -322,3 +331,29 @@ class DlgTableProperties(QDialog, Ui_Dialog): self.refresh() except BaseError as e: DlgDbError.showError(e, self) + + def createComment(self): + #Function that add 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())) + except DbError as e: + DlgDbError.showError(e, self) + return + self.refresh() + #Display successful message + QMessageBox.information(self, self.tr("Add comment"), self.tr("Table successfully commented")) + + def deleteComment(self): + #Function that drop the comment to 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)) + except DbError as e: + DlgDbError.showError(e, self) + return + self.refresh() + #Refresh line edit, put a void comment + self.viewComment.setText('') + #Display successful message + QMessageBox.information(self, self.tr("Delete comment"), self.tr("Comment deleted")) diff --git a/python/plugins/db_manager/ui/DlgImportVector.ui b/python/plugins/db_manager/ui/DlgImportVector.ui old mode 100644 new mode 100755 index 8267b66316c..00575e64aa4 --- a/python/plugins/db_manager/ui/DlgImportVector.ui +++ b/python/plugins/db_manager/ui/DlgImportVector.ui @@ -7,7 +7,7 @@ 0 0 482 - 496 + 627 @@ -254,6 +254,20 @@ + + + + Comment + + + + + + + false + + + @@ -310,8 +324,8 @@ reject() - 334 - 486 + 343 + 617 286 @@ -326,12 +340,12 @@ setEnabled(bool) - 129 - 239 + 155 + 268 - 460 - 239 + 463 + 272 @@ -342,12 +356,12 @@ setEnabled(bool) - 141 - 265 + 167 + 306 - 442 - 265 + 463 + 310 @@ -358,12 +372,12 @@ setEnabled(bool) - 119 - 343 + 145 + 404 - 455 - 343 + 463 + 406 @@ -374,8 +388,8 @@ accept() - 461 - 486 + 470 + 617 508 @@ -390,12 +404,12 @@ setEnabled(bool) - 134 - 281 + 160 + 341 - 357 - 281 + 463 + 341 @@ -406,12 +420,28 @@ setEnabled(bool) - 134 - 307 + 160 + 372 - 357 - 307 + 463 + 372 + + + + + chkCom + toggled(bool) + editComment + setEnabled(bool) + + + 64 + 549 + + + 215 + 552 diff --git a/python/plugins/db_manager/ui/DlgTableProperties.ui b/python/plugins/db_manager/ui/DlgTableProperties.ui old mode 100644 new mode 100755 index 82f7a245445..38cc29d2479 --- a/python/plugins/db_manager/ui/DlgTableProperties.ui +++ b/python/plugins/db_manager/ui/DlgTableProperties.ui @@ -23,7 +23,7 @@ Columns - + @@ -68,8 +68,8 @@ - 40 - 20 + 13 + 29 @@ -89,7 +89,7 @@ Constraints - + @@ -141,7 +141,7 @@ Indexes - + @@ -157,7 +157,7 @@ - + @@ -196,6 +196,57 @@ + + + true + + + Comment + + + + + + Comment defined for this table: + + + + + + + + + + + + Add comment + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete comment + + + + + + +