Skip to content
Permalink
Browse files

Merge pull request #9183 from Gustry/save_comments

keep comments when saving query, fix single line comment
  • Loading branch information
elpaso committed Feb 20, 2019
2 parents 89e3fce + f37d48f commit dd7a5f5b1e4693a12a7bccc8e95d1f3f39dd3083
Showing with 16 additions and 5 deletions.
  1. +16 −5 python/plugins/db_manager/dlg_sql_window.py
@@ -351,7 +351,7 @@ def executeSqlCompleted(self):

def executeSql(self):

sql = self._getSqlQuery()
sql = self._getExecutableSqlQuery()
if sql == "":
return

@@ -393,7 +393,7 @@ def _getSqlLayer(self, _filter):
else:
geomFieldName = None

query = self._getSqlQuery()
query = self._getSqlExecutableQuery()
if query == "":
return None

@@ -438,7 +438,7 @@ def loadSqlLayer(self):
QgsProject.instance().addMapLayers([layer], True)

def fillColumnCombos(self):
query = self._getSqlQuery()
query = self._getExecutableSqlQuery()
if query == "":
return

@@ -588,16 +588,27 @@ def createView(self):
name, ok = QInputDialog.getText(None, self.tr("View Name"), self.tr("View name"))
if ok:
try:
self.db.connector.createSpatialView(name, self._getSqlQuery())
self.db.connector.createSpatialView(name, self._getExecutableSqlQuery())
except BaseError as e:
DlgDbError.showError(e, self)

def _getSqlQuery(self):
sql = self.editSql.selectedText()
if len(sql) == 0:
sql = self.editSql.text().replace('\n', ' ').strip()
sql = self.editSql.text()
return sql

def _getExecutableSqlQuery(self):
sql = self._getSqlQuery()

# Clean it up!
lines = []
for line in sql.split('\n'):
if not line.strip().startswith('--'):
lines.append(line)
sql = ' '.join(lines)
return sql.strip()

def uniqueChanged(self):
# when an item is (un)checked, simply trigger an update of the combobox text
self.uniqueTextChanged(None)

0 comments on commit dd7a5f5

Please sign in to comment.
You can’t perform that action at this time.