Issue with QGIS DB Manager SQL Window

UPDATE: I just upgraded to QGIS 2.4 along with upgrading my OS to Linux Mint 17, and the problem described below no longer seems to an issue.

QGIS DB Manager has a SQL Window which is useful for extracting, joining, or transforming data before loading it in the map canvas. Unfortunately I found that the syntax highlighting causes keypresses to buffer while the highlighting module checks the syntax, and slows it down to the point of making it completely unusable. I reported this to the QGIS Developer mailing list, but the developer was not able to reproduce the problem and only a handful of the other listers were able to confirm it. I’m not sure why, as I have now experienced it on Linux and Windows (including an entire GIS lab of Windows machines), and a large group of my Geovisualization students who use Macs are also affected by it.

Until it can be fixed, I’ve found it necessary to disable syntax highlighting in the plugin. The affected file is dlg_sql_window.py. It is found in the following locations:

  • Linux: /usr/share/qgis/python/plugins/db_manager/dlg_sql_window.py
  • Mac: /Applications/QGIS.app/Contents/Resources/python/plugins/db_manager/dlg_sql_window.py
  • Windows OSGeo4W: C:\OSGeo4W\apps\qgis\python\plugins\db_manager\dlg_sql_window.py

The solution is to comment out lines 34 and 56. On Linux and Mac, editing this file requires administrative privileges, but this is not required in OSGeo4W. The beginning of the file is reproduced here so that you can see which lines need to be commented out.

# -*- coding: utf-8 -*-

"""
/***************************************************************************
Name                 : DB Manager
Description          : Database manager plugin for QGIS
Date                 : May 23, 2011
copyright            : (C) 2011 by Giuseppe Sucameli
email                : brush.tyler@gmail.com

The content of this file is based on
- PG_Manager by Martin Dobias (GPLv2 license)
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *

from .db_plugins.plugin import BaseError
from .dlg_db_error import DlgDbError

from .ui.ui_DlgSqlWindow import Ui_DbManagerDlgSqlWindow as Ui_Dialog

# COMMENT OUT THIS LINE -> from .highlighter import SqlHighlighter
from .completer import SqlCompleter

import re

class DlgSqlWindow(QDialog, Ui_Dialog):

  def __init__(self, iface, db, parent=None):
    QDialog.__init__(self, parent)
    self.iface = iface
    self.db = db
    self.setupUi(self)
    self.setWindowTitle( u"%s - %s [%s]" % (self.windowTitle(), db.connection().connectionName(), db.connection().typeNameString()) )

    self.defaultLayerName = 'QueryLayer'

    settings = QSettings()
    self.restoreGeometry(settings.value("/DB_Manager/sqlWindow/geometry", QByteArray(), type=QByteArray))

    self.editSql.setAcceptRichText(False)
    self.editSql.setFocus()
    SqlCompleter(self.editSql, self.db)
    # COMMENT OUT THIS LINE -> SqlHighlighter(self.editSql, self.db)

    # allow to copy results
    copyAction = QAction("copy", self)
    self.viewResult.addAction( copyAction )
    copyAction.setShortcuts(QKeySequence.Copy)
    QObject.connect(copyAction, SIGNAL("triggered()"), self.copySelectedResults)

# [subsequent code omitted]