Skip to content

Commit

Permalink
Add a dialect select to ogrsql
Browse files Browse the repository at this point in the history
Add the ability to select sqlite or ogrsql dialects when executing SQL

Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
  • Loading branch information
om-henners committed Oct 8, 2015
1 parent 4c1e056 commit 524f6ab
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/plugins/processing/algs/gdal/ogrsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputVector

from processing.algs.gdal.GdalUtils import GdalUtils
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm


DIALECTS = [None, 'ogrsql', 'sqlite']

class OgrSql(OgrAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
SQL = 'SQL'
DIALECT = 'DIALECT'

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

self.addParameter(ParameterSelection(
self.DIALECT,
self.tr('Dialect'),
DIALECTS)
)

self.addOutput(OutputVector(self.OUTPUT, self.tr('SQL result')))

def getConsoleCommands(self):
Expand All @@ -60,6 +70,13 @@ def getConsoleCommands(self):
arguments.append('-sql')
arguments.append(sql)

dialectIdx = self.getParameterValue(self.DIALECT)
dialect = DIALECTS[dialectIdx]

if dialect:
arguments.append("-dialect")
arguments.append(dialect)

output = self.getOutputFromName(self.OUTPUT)
outFile = output.value
arguments.append(outFile)
Expand Down

0 comments on commit 524f6ab

Please sign in to comment.