Skip to content

Commit

Permalink
Merge pull request #3625 from rldhont/db_manager_lowercaseFieldNames
Browse files Browse the repository at this point in the history
[DB Manager] Allow lowercase field names for homogenize PostGIS Import
  • Loading branch information
rldhont committed Oct 19, 2016
2 parents c130372 + a9795ad commit 5d4cf2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions python/plugins/db_manager/db_plugins/plugin.py
Expand Up @@ -552,6 +552,9 @@ def explicitSpatialIndex(self):
def spatialIndexClause(self, src_table, src_column, dest_table, dest_table_column):
return None

def hasLowercaseFieldNamesOption(self):
return False


class Schema(DbItemObject):

Expand Down
3 changes: 3 additions & 0 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -168,6 +168,9 @@ def runRefreshMaterializedViewSlot(self, item, action, parent):

item.runRefreshMaterializedView()

def hasLowercaseFieldNamesOption(self):
return True


class PGSchema(Schema):

Expand Down
13 changes: 11 additions & 2 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -108,6 +108,10 @@ def checkSupports(self):
if not self.chkSpatialIndex.isEnabled():
self.chkSpatialIndex.setChecked(False)

self.chkLowercaseFieldNames.setEnabled(self.db.hasLowercaseFieldNamesOption())
if not self.chkLowercaseFieldNames.isEnabled():
self.chkLowercaseFieldNames.setChecked(False)

def populateLayers(self):
self.cboInputLayer.clear()
for index, layer in enumerate(iface.legendInterface().layers()):
Expand Down Expand Up @@ -302,13 +306,18 @@ def accept(self):
else:
geom = None

options = {}
if self.chkLowercaseFieldNames.isEnabled() and self.chkLowercaseFieldNames.isChecked():
pk = pk.lower()
if geom:
geom = geom.lower()
options['lowercaseFieldNames'] = True

# get output params, update output URI
self.outUri.setDataSource(schema, table, geom, "", pk)
uri = self.outUri.uri(False)

providerName = self.db.dbplugin().providerName()

options = {}
if self.chkDropTable.isChecked():
options['overwrite'] = True

Expand Down
9 changes: 8 additions & 1 deletion python/plugins/db_manager/ui/DlgImportVector.ui
Expand Up @@ -253,7 +253,7 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="chkSpatialIndex">
<property name="text">
<string>Create spatial index</string>
Expand All @@ -267,6 +267,13 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="chkLowercaseFieldNames">
<property name="text">
<string>Convert field names to lowercase</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 5d4cf2f

Please sign in to comment.