Skip to content

Commit

Permalink
Try to add cancel support for Oracle databases in dbmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere authored and nyalldawson committed Apr 21, 2018
1 parent b22121a commit d589ba7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/plugins/db_manager/db_plugins/oracle/connector.py
Expand Up @@ -1743,3 +1743,7 @@ def getSqlDictionary(self):
def getQueryBuilderDictionary(self):
from .sql_dictionary import getQueryBuilderDictionary
return getQueryBuilderDictionary()

def cancel(self):
# how to cancel an Oracle query?
pass
36 changes: 35 additions & 1 deletion python/plugins/db_manager/db_plugins/oracle/data_model.py
Expand Up @@ -26,7 +26,11 @@

from qgis.PyQt.QtCore import QTime

from ..data_model import TableDataModel, SqlResultModel, BaseTableModel
from ..data_model import (TableDataModel,
SqlResultModel,
SqlResultModelAsync,
SqlResultModelTask,
BaseTableModel)
from ..plugin import DbError


Expand Down Expand Up @@ -114,6 +118,36 @@ def fetchMoreData(self, row_start):
self.fetchedFrom = row_start


class ORSqlResultModelTask(SqlResultModelTask):

def __init__(self, db, sql, parent):
super().__init__(db, sql, parent)

def run(self):
try:
self.model = ORSqlResultModel(self.db, self.sql, None)
except BaseError as e:
self.error = e
QgsMessageLog.logMessage(e.msg)
return False

return True

def cancel(self):
self.db.connector.cancel()
SqlResultModelTask.cancel(self)


class ORSqlResultModelAsync(SqlResultModelAsync):

def __init__(self, db, sql, parent):
super().__init__()

self.task = ORSqlResultModelTask(db, sql, parent)
self.task.taskCompleted.connect(self.modelDone)
self.task.taskTerminated.connect(self.modelDone)


class ORSqlResultModel(SqlResultModel):

def __init__(self, db, sql, parent=None):
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/db_manager/db_plugins/oracle/plugin.py
Expand Up @@ -192,6 +192,11 @@ def sqlResultModel(self, sql, parent):
from .data_model import ORSqlResultModel
return ORSqlResultModel(self, sql, parent)

def sqlResultModelAsync(self, sql, parent):
from .data_model import ORSqlResultModelAsync

return ORSqlResultModelAsync(self, sql, parent)

def toSqlLayer(self, sql, geomCol, uniqueCol,
layerName=u"QueryLayer", layerType=None,
avoidSelectById=False, filter=""):
Expand Down

0 comments on commit d589ba7

Please sign in to comment.