Skip to content

Commit 2b01c7c

Browse files
committedOct 19, 2016
[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 133a6f5 commit 2b01c7c

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-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
@@ -550,6 +550,9 @@ def explicitSpatialIndex(self):
550550
def spatialIndexClause(self, src_table, src_column, dest_table, dest_table_column):
551551
return None
552552

553+
def hasLowercaseFieldNamesOption(self):
554+
return False
555+
553556

554557
class Schema(DbItemObject):
555558

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def runRefreshMaterializedViewSlot(self, item, action, parent):
165165

166166
item.runRefreshMaterializedView()
167167

168+
def hasLowercaseFieldNamesOption(self):
169+
return True
170+
168171

169172
class PGSchema(Schema):
170173

‎python/plugins/db_manager/dlg_import_vector.py

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

109+
self.chkLowercaseFieldNames.setEnabled(self.db.hasLowercaseFieldNamesOption())
110+
if not self.chkLowercaseFieldNames.isEnabled():
111+
self.chkLowercaseFieldNames.setChecked(False)
112+
109113
def populateLayers(self):
110114
self.cboInputLayer.clear()
111115
for index, layer in enumerate(iface.legendInterface().layers()):
@@ -300,13 +304,18 @@ def accept(self):
300304
else:
301305
geom = None
302306

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

307318
providerName = self.db.dbplugin().providerName()
308-
309-
options = {}
310319
if self.chkDropTable.isChecked():
311320
options['overwrite'] = True
312321

‎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)
Please sign in to comment.