Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dbmanager: avoid duplicate field error (fix #6279)
  • Loading branch information
brushtyler committed Nov 29, 2012
1 parent 3542b08 commit 0239795
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -43,7 +43,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

self.default_pk = "id"
self.default_geom = "geom"

# updates of UI
for widget in [self.radCreate, self.chkDropTable, self.radAppend,
self.chkPrimaryKey, self.chkGeomColumn, self.chkSpatialIndex,
Expand All @@ -58,11 +58,14 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
self.populateEncodings()
self.updateUi()

# set default values
self.cboTable.setEditText(self.outUri.table())

pk = self.outUri.keyColumn()
self.editPrimaryKey.setText(pk if pk != "" else self.default_pk)
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)

inCrs = self.inLayer.crs()
srid = inCrs.postgisSrid() if inCrs.isValid() else 4236
self.editSourceSrid.setText( "%s" % srid )
Expand All @@ -73,7 +76,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

def checkSupports(self):
allowSpatial = self.db.connector.hasSpatialSupport()
self.chkGeomColumn.setEnabled(allowSpatial)
self.chkGeomColumn.setEnabled(allowSpatial and self.inLayer.hasGeometryType())
self.chkSourceSrid.setEnabled(allowSpatial)
self.chkTargetSrid.setEnabled(allowSpatial)
self.chkSpatialIndex.setEnabled(allowSpatial)
Expand Down Expand Up @@ -168,12 +171,11 @@ def importLayer(self):
schema = self.outUri.schema() if not self.cboSchema.isEnabled() else self.cboSchema.currentText()
table = self.cboTable.currentText()

# get pk and geom field names from the source layer or use the
# ones defined by the user
pk = self.outUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
pk = pk if pk != "" else self.default_pk

geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
if self.inLayer.hasGeometryType():
geom = geom if geom != "" else self.default_geom
geom = geom if geom != "" else self.default_geom

self.outUri.setDataSource( schema, table, geom, QString(), pk )
uri = self.outUri.uri()
Expand Down

0 comments on commit 0239795

Please sign in to comment.