Skip to content

Commit 0239795

Browse files
committedNov 29, 2012
dbmanager: avoid duplicate field error (fix #6279)
1 parent 3542b08 commit 0239795

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

‎python/plugins/db_manager/dlg_import_vector.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
4343

4444
self.default_pk = "id"
4545
self.default_geom = "geom"
46-
46+
4747
# updates of UI
4848
for widget in [self.radCreate, self.chkDropTable, self.radAppend,
4949
self.chkPrimaryKey, self.chkGeomColumn, self.chkSpatialIndex,
@@ -58,11 +58,14 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
5858
self.populateEncodings()
5959
self.updateUi()
6060

61+
# set default values
6162
self.cboTable.setEditText(self.outUri.table())
63+
6264
pk = self.outUri.keyColumn()
6365
self.editPrimaryKey.setText(pk if pk != "" else self.default_pk)
6466
geom = self.outUri.geometryColumn()
6567
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)
68+
6669
inCrs = self.inLayer.crs()
6770
srid = inCrs.postgisSrid() if inCrs.isValid() else 4236
6871
self.editSourceSrid.setText( "%s" % srid )
@@ -73,7 +76,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
7376

7477
def checkSupports(self):
7578
allowSpatial = self.db.connector.hasSpatialSupport()
76-
self.chkGeomColumn.setEnabled(allowSpatial)
79+
self.chkGeomColumn.setEnabled(allowSpatial and self.inLayer.hasGeometryType())
7780
self.chkSourceSrid.setEnabled(allowSpatial)
7881
self.chkTargetSrid.setEnabled(allowSpatial)
7982
self.chkSpatialIndex.setEnabled(allowSpatial)
@@ -168,12 +171,11 @@ def importLayer(self):
168171
schema = self.outUri.schema() if not self.cboSchema.isEnabled() else self.cboSchema.currentText()
169172
table = self.cboTable.currentText()
170173

174+
# get pk and geom field names from the source layer or use the
175+
# ones defined by the user
171176
pk = self.outUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
172-
pk = pk if pk != "" else self.default_pk
173-
174177
geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
175-
if self.inLayer.hasGeometryType():
176-
geom = geom if geom != "" else self.default_geom
178+
geom = geom if geom != "" else self.default_geom
177179

178180
self.outUri.setDataSource( schema, table, geom, QString(), pk )
179181
uri = self.outUri.uri()

0 commit comments

Comments
 (0)
Please sign in to comment.