Skip to content

Commit 7cec859

Browse files
committed
[DB Manager] Allow lowercase field names for homogenize PostGIS Import
PostGIS provider has an option to lowercase field names. This options is available for user in QGIS algorithm ImportIntoPostGIS and not in DB Mananger. This commit fix it.
1 parent 70186ee commit 7cec859

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

python/plugins/db_manager/db_plugins/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ def explicitSpatialIndex(self):
542542
def spatialIndexClause(self, src_table, src_column, dest_table, dest_table_column):
543543
return None
544544

545+
def hasLowercaseFieldNamesOption(self):
546+
return False
547+
545548

546549
class Schema(DbItemObject):
547550

python/plugins/db_manager/db_plugins/postgis/plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def runVacuumAnalyzeActionSlot(self, item, action, parent):
152152

153153
item.runVacuumAnalyze()
154154

155+
def hasLowercaseFieldNamesOption(self):
156+
return True
155157

156158
class PGSchema(Schema):
157159

python/plugins/db_manager/dlg_import_vector.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def checkSupports(self):
104104
if not self.chkSpatialIndex.isEnabled():
105105
self.chkSpatialIndex.setChecked(False)
106106

107+
self.chkLowercaseFieldNames.setEnabled(self.db.hasLowercaseFieldNamesOption())
108+
if not self.chkLowercaseFieldNames.isEnabled():
109+
self.chkLowercaseFieldNames.setChecked(False)
110+
107111
def populateLayers(self):
108112
self.cboInputLayer.clear()
109113
for index, layer in enumerate(iface.legendInterface().layers()):
@@ -298,13 +302,18 @@ def accept(self):
298302
else:
299303
geom = None
300304

305+
options = {}
306+
if self.chkLowercaseFieldNames.isEnabled() and self.chkLowercaseFieldNames.isChecked():
307+
pk = pk.lower()
308+
if geom:
309+
geom = geom.lower()
310+
options['lowercaseFieldNames'] = True
311+
301312
# get output params, update output URI
302313
self.outUri.setDataSource(schema, table, geom, "", pk)
303314
uri = self.outUri.uri(False)
304315

305316
providerName = self.db.dbplugin().providerName()
306-
307-
options = {}
308317
if self.chkDropTable.isChecked():
309318
options['overwrite'] = True
310319

python/plugins/db_manager/ui/DlgImportVector.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
</property>
254254
</widget>
255255
</item>
256-
<item row="7" column="0" colspan="2">
256+
<item row="8" column="0" colspan="2">
257257
<widget class="QCheckBox" name="chkSpatialIndex">
258258
<property name="text">
259259
<string>Create spatial index</string>
@@ -267,6 +267,13 @@
267267
</property>
268268
</widget>
269269
</item>
270+
<item row="7" column="0">
271+
<widget class="QCheckBox" name="chkLowercaseFieldNames">
272+
<property name="text">
273+
<string>Convert field names to lowercase</string>
274+
</property>
275+
</widget>
276+
</item>
270277
</layout>
271278
</widget>
272279
</item>

0 commit comments

Comments
 (0)