Skip to content

Commit a9795ad

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 c130372 commit a9795ad

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
@@ -552,6 +552,9 @@ def explicitSpatialIndex(self):
552552
def spatialIndexClause(self, src_table, src_column, dest_table, dest_table_column):
553553
return None
554554

555+
def hasLowercaseFieldNamesOption(self):
556+
return False
557+
555558

556559
class Schema(DbItemObject):
557560

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

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

169169
item.runRefreshMaterializedView()
170170

171+
def hasLowercaseFieldNamesOption(self):
172+
return True
173+
171174

172175
class PGSchema(Schema):
173176

‎python/plugins/db_manager/dlg_import_vector.py

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

111+
self.chkLowercaseFieldNames.setEnabled(self.db.hasLowercaseFieldNamesOption())
112+
if not self.chkLowercaseFieldNames.isEnabled():
113+
self.chkLowercaseFieldNames.setChecked(False)
114+
111115
def populateLayers(self):
112116
self.cboInputLayer.clear()
113117
for index, layer in enumerate(iface.legendInterface().layers()):
@@ -302,13 +306,18 @@ def accept(self):
302306
else:
303307
geom = None
304308

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

309320
providerName = self.db.dbplugin().providerName()
310-
311-
options = {}
312321
if self.chkDropTable.isChecked():
313322
options['overwrite'] = True
314323

‎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.