Skip to content
Permalink
Browse files

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>
  • Loading branch information
om-henners committed Oct 8, 2015
1 parent 4c1e056 commit 524f6ab460c5890f0c973a8b3de8cc2ddc1a52f3
Showing with 17 additions and 0 deletions.
  1. +17 −0 python/plugins/processing/algs/gdal/ogrsql.py
@@ -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')
@@ -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):
@@ -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)

0 comments on commit 524f6ab

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