def addColumn(self): """ open dialog to set column info and add column to table """ dlg = DlgFieldProperties(self) if not dlg.exec_(): return name = unicode(dlg.editName.text()) data_type = unicode(dlg.cboType.currentText()) is_null = dlg.chkNull.isChecked() default = unicode(dlg.editDefault.text()) if dlg.editLength.text().count() > 0: x = dlg.editLength.text().toInt() modifier = x[0] if x[1] else None else: modifier = None new_field = postgis_utils.TableField(name, data_type, is_null, default, modifier) self.emit(SIGNAL("aboutToChangeTable()")) try: # add column to table self.db.table_add_column(self.table, new_field, self.schema) self.populateFields() except postgis_utils.DbError, e: DlgDbError.showError(e, self)
def editColumn(self): """ open dialog to change column info and alter table appropriately """ num = self.currentColumn() if num == -1: return m = self.viewFields.model() # get column in table # (there can be missing number if someone deleted a column) column = unicode(m.item(num, 1).text()) for col in self.fields: if col.name == column: break print col.num, col.name dlg = DlgFieldProperties(self, col) if not dlg.exec_(): return new_name = unicode(dlg.editName.text()) new_data_type = unicode(dlg.cboType.currentText()) new_is_null = dlg.chkNull.isChecked() new_default = unicode(dlg.editDefault.text()) if dlg.editLength.text().count() > 0: x = dlg.editLength.text().toInt() new_modifier = x[0] if x[1] else -1 else: new_modifier = -1 self.emit(SIGNAL("aboutToChangeTable()")) try: if new_name != col.name: self.db.table_column_rename(self.table, col.name, new_name, self.schema) if new_data_type != col.data_type or new_modifier != col.modifier: if new_modifier >= 0: new_data_type += "(%d)" % new_modifier self.db.table_column_set_type(self.table, new_name, new_data_type, self.schema) if new_is_null == col.notnull: self.db.table_column_set_null(self.table, new_name, new_is_null, self.schema) if len(new_default) > 0 and new_default != col.default: self.db.table_column_set_default(self.table, new_name, new_default, self.schema) if len(new_default) == 0 and col.hasdefault: self.db.table_column_set_default(self.table, new_name, None, self.schema) self.populateFields() except postgis_utils.DbError, e: DlgDbError.showError(e, self)