Skip to content
Permalink
Browse files

Restore Postgis Execute SQL alg

  • Loading branch information
nyalldawson committed Jun 22, 2017
1 parent 38f1d9c commit c33f94002d90e15907f30dc2a1d98eb7ba9f0fd4
@@ -26,10 +26,10 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication)
from qgis.core import (QgsApplication,
QgsProcessingParameterString)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterString
from processing.tools import postgis


@@ -49,13 +49,15 @@ def group(self):

def __init__(self):
super().__init__()
self.addParameter(ParameterString(

db_param = QgsProcessingParameterString(
self.DATABASE,
self.tr('Database'),
metadata={
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}}))
self.addParameter(ParameterString(self.SQL, self.tr('SQL query'), '', True))
self.tr('Database (connection name)'))
db_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.addParameter(db_param)
self.addParameter(QgsProcessingParameterString(self.SQL, self.tr('SQL query')))

def name(self):
return 'postgisexecutesql'
@@ -64,11 +66,13 @@ def displayName(self):
return self.tr('PostGIS execute SQL')

def processAlgorithm(self, parameters, context, feedback):
connection = self.getParameterValue(self.DATABASE)
self.db = postgis.GeoDB.from_name(connection)
sql = self.getParameterValue(self.SQL).replace('\n', ' ')
connection = self.parameterAsString(parameters, self.DATABASE, context)
db = postgis.GeoDB.from_name(connection)

sql = self.parameterAsString(parameters, self.SQL, context).replace('\n', ' ')
try:
self.db._exec_sql_and_commit(str(sql))
db._exec_sql_and_commit(str(sql))
except postgis.DbError as e:
raise GeoAlgorithmExecutionException(
self.tr('Error executing SQL:\n{0}').format(str(e)))
return {}
@@ -57,6 +57,7 @@
from .GridPolygon import GridPolygon
from .ImportIntoPostGIS import ImportIntoPostGIS
from .Merge import Merge
from .PostGISExecuteSQL import PostGISExecuteSQL

# from .RegularPoints import RegularPoints
# from .SymmetricalDifference import SymmetricalDifference
@@ -122,7 +123,6 @@
# from .RandomPointsAlongLines import RandomPointsAlongLines
# from .PointsToPaths import PointsToPaths
# from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
# from .PostGISExecuteSQL import PostGISExecuteSQL
# from .ImportIntoSpatialite import ImportIntoSpatialite
# from .SetVectorStyle import SetVectorStyle
# from .SetRasterStyle import SetRasterStyle
@@ -218,7 +218,6 @@ def getAlgs(self):
# RandomPointsPolygonsVariable(),
# RandomPointsAlongLines(), PointsToPaths(),
# SpatialiteExecuteSQL(), ImportIntoSpatialite(),
# PostGISExecuteSQL(),
# SetVectorStyle(), SetRasterStyle(),
# SelectByExpression(), HypsometricCurves(),
# SplitWithLines(), CreateConstantRaster(),
@@ -261,7 +260,8 @@ def getAlgs(self):
ExtentFromLayer(),
GridPolygon(),
ImportIntoPostGIS(),
Merge()
Merge(),
PostGISExecuteSQL()
]

if hasPlotly:

0 comments on commit c33f940

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