Bug report #8066

trying to run a sql query on a database through db manage broken, throws error

Added by Mathieu Pellerin - nIRV about 11 years ago. Updated about 11 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:DB Manager
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:16905

Description

Steps to reproduce:
1. Open db manager
2. Enter into a database (spatialite or postgis, doesn't matter)
3. Open the SQL window
4. Enter a simple SQL query (i.e. select * from my_table)
5. Click on Execture
6. QGIS throws a python error console with this content:

An error has occured while executing Python code:

Traceback (most recent call last):
  File "C:/OSGeo4W/apps/qgis-dev/./python/plugins\\db_manager\\dlg_sql_window.py", line 144, in executeSql
    sql = self.getSql()
  File "C:/OSGeo4W/apps/qgis-dev/./python/plugins\\db_manager\\dlg_sql_window.py", line 137, in getSql
    sql = sql.replace( QRegExp( ";\\\\s*$" ), "" )
TypeError: coercing to Unicode: need string or buffer, QRegExp found

Python version:
2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]

QGIS version:
1.9.0-Master Master, d547b25

Python path: ['C:/OSGeo4W/apps/qgis-dev/./python/plugins\\\\sextante', 'C:/OSGeo4W/apps/qgis-dev/./python', 'C:\\\\Users\\\\MATH/.qgis2/python', 'C:\\\\Users\\\\MATH/.qgis2/python/plugins', 'C:/OSGeo4W/apps/qgis-dev/./python/plugins', 'C:\\\\OSGeo4W\\\\apps\\\\orfeotoolbox\\\\wrapping\\\\lib', 'C:\\\\OSGeo4W\\\\apps\\\\orfeotoolbox\\\\wrapping\\\\Python', 'C:\\\\OSGeo4W\\\\apps\\\\orfeotoolbox\\\\python', 'C:\\\\', 'C:\\\\OSGeo4W\\\\bin\\\\python27.zip', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\DLLs', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\plat-win', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\lib-tk', 'C:\\\\OSGeo4W\\\\bin', 'C:\\\\OSGeo4W\\\\apps\\\\Python27', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages\\\\PIL', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages\\\\win32', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages\\\\win32\\\\lib', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages\\\\Pythonwin', 'C:\\\\OSGeo4W\\\\apps\\\\Python27\\\\lib\\\\site-packages\\\\wx-2.8-msw-unicode', 'C:\\\\OSGeo4W\\\\apps\\\\qgis-dev\\\\python\\\\plugins\\\\fTools\\\\tools']
<p>

Flagging this as a blocker as it breaks SQL execution.

Associated revisions

Revision 192e1301
Added by Jürgen Fischer about 11 years ago

replace foo.replace( QRegExp(regexp), bar) with re.sub(regexp,bar,foo) (fixes #8066)

History

#1 Updated by Gavin Fleming about 11 years ago

affects me too, same description.

#2 Updated by Salvatore Larosa about 11 years ago

can not be reproduced here on the latest master (Linux).

I don't understand why it happens on Windows, maybe converting
the QRegExp to str might helps ??

If you can give at it a try apply the following patch (I cannot test on Windows just guessing here)

diff --git a/python/plugins/db_manager/dlg_sql_window.py b/python/plugins/db_manager/dlg_sql_window.
index 106be27..efa1d8b 100644
--- a/python/plugins/db_manager/dlg_sql_window.py
+++ b/python/plugins/db_manager/dlg_sql_window.py
@@ -134,7 +134,7 @@ class DlgSqlWindow(QDialog, Ui_Dialog):
     if sql == "":
       sql = self.editSql.toPlainText()
     # try to sanitize query
-    sql = sql.replace( QRegExp( ";\\\\s*$" ), "" )
+    sql = sql.replace( str(QRegExp( ";\\\\s*$" )), "" )
     return sql

   def clearSql(self):

#3 Updated by Giovanni Manghi about 11 years ago

  • Pull Request or Patch supplied changed from No to Yes

#4 Updated by Jürgen Fischer about 11 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF