Skip to content

Commit

Permalink
Restore Postgis Execute SQL alg
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 22, 2017
1 parent 38f1d9c commit c33f940
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 16 additions & 12 deletions python/plugins/processing/algs/qgis/PostGISExecuteSQL.py
Expand Up @@ -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


Expand All @@ -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'
Expand All @@ -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 {}
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -218,7 +218,6 @@ def getAlgs(self):
# RandomPointsPolygonsVariable(),
# RandomPointsAlongLines(), PointsToPaths(),
# SpatialiteExecuteSQL(), ImportIntoSpatialite(),
# PostGISExecuteSQL(),
# SetVectorStyle(), SetRasterStyle(),
# SelectByExpression(), HypsometricCurves(),
# SplitWithLines(), CreateConstantRaster(),
Expand Down Expand Up @@ -261,7 +260,8 @@ def getAlgs(self):
ExtentFromLayer(),
GridPolygon(),
ImportIntoPostGIS(),
Merge()
Merge(),
PostGISExecuteSQL()
]

if hasPlotly:
Expand Down

0 comments on commit c33f940

Please sign in to comment.