Skip to content
Permalink
Browse files
dbmanager: avoid duplicate field error (fix #6279)
  • Loading branch information
brushtyler committed Nov 29, 2012
1 parent 3542b08 commit 0239795d7931b614be22e87d12beecf20372b5c6
Showing with 8 additions and 6 deletions.
  1. +8 −6 python/plugins/db_manager/dlg_import_vector.py
@@ -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,
@@ -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 )
@@ -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)
@@ -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()

0 comments on commit 0239795

Please sign in to comment.