Skip to content

Commit 524f6ab

Browse files
committedOct 8, 2015
Add a dialect select to ogrsql
Add the ability to select sqlite or ogrsql dialects when executing SQL Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
1 parent 4c1e056 commit 524f6ab

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎python/plugins/processing/algs/gdal/ogrsql.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@
2828
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
2929
from processing.core.parameters import ParameterVector
3030
from processing.core.parameters import ParameterString
31+
from processing.core.parameters import ParameterSelection
3132
from processing.core.outputs import OutputVector
3233

3334
from processing.algs.gdal.GdalUtils import GdalUtils
3435
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
3536

3637

38+
DIALECTS = [None, 'ogrsql', 'sqlite']
39+
3740
class OgrSql(OgrAlgorithm):
3841

3942
INPUT = 'INPUT'
4043
OUTPUT = 'OUTPUT'
4144
SQL = 'SQL'
45+
DIALECT = 'DIALECT'
4246

4347
def defineCharacteristics(self):
4448
self.name, self.i18n_name = self.trAlgorithm('Execute SQL')
@@ -48,6 +52,12 @@ def defineCharacteristics(self):
4852
[ParameterVector.VECTOR_TYPE_ANY], False))
4953
self.addParameter(ParameterString(self.SQL, self.tr('SQL'), ''))
5054

55+
self.addParameter(ParameterSelection(
56+
self.DIALECT,
57+
self.tr('Dialect'),
58+
DIALECTS)
59+
)
60+
5161
self.addOutput(OutputVector(self.OUTPUT, self.tr('SQL result')))
5262

5363
def getConsoleCommands(self):
@@ -60,6 +70,13 @@ def getConsoleCommands(self):
6070
arguments.append('-sql')
6171
arguments.append(sql)
6272

73+
dialectIdx = self.getParameterValue(self.DIALECT)
74+
dialect = DIALECTS[dialectIdx]
75+
76+
if dialect:
77+
arguments.append("-dialect")
78+
arguments.append(dialect)
79+
6380
output = self.getOutputFromName(self.OUTPUT)
6481
outFile = output.value
6582
arguments.append(outFile)

0 commit comments

Comments
 (0)
Please sign in to comment.