Bug report #19419
QGIS 3.2 crashes when preparing a QSqlQuery with PyQGIS
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | Jürgen Fischer | ||
Category: | Unknown | ||
Affected QGIS version: | 3.2 | Regression?: | No |
Operating System: | Win10 | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | Yes | Copied to github as #: | 27247 |
Description
I created a simple test spatialite db (cp. attached screeshot) and try to query it from PyQGIS using QSqlDatabase / QSqlQuery classes.
The following done on the python console works fine:
from PyQt5.QtSql import *
db = QSqlDatabase.addDatabase('QSPATIALITE')
db.setDatabaseName('C:\\tmp\\test.sqlite')
db.open()
True
q = QSqlQuery(db)
But when trying to prepare the query like q.prepare('SELECT * FROM test')
QGIS crashes.
User Feedback¶
Report Details¶
Crash ID: 63da86ddcb0c96ee912d9d8b7f0158abc9388167
Stack Trace
QSqlCachedResult::detachFromResultSet : PyCFunction_FastCallDict : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyErr_Occurred : PyEval_EvalCode : PyDict_SetItemId : PyDict_SetItemId : PyCFunction_FastCallDict : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyErr_Occurred : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyErr_Occurred : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyObject_GenericGetAttr : PyEval_EvalFrameDefault : PyFunction_FastCallDict : PyObject_CallFunctionObjArgs : PyObject_Call : PyInit_sip : PyInit_Qsci : QWidget::event : QFrame::event : QAbstractScrollArea::event : PyInit_Qsci : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify : QCoreApplication::notifyInternal2 : QSizePolicy::QSizePolicy : QSizePolicy::QSizePolicy : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify : QCoreApplication::notifyInternal2 : QGuiApplicationPrivate::processKeyEvent : QWindowSystemInterface::sendWindowSystemEvents : QEventDispatcherWin32::processEvents : CallWindowProcW : DispatchMessageW : QEventDispatcherWin32::processEvents : qt_plugin_query_metadata : QEventLoop::exec : QCoreApplication::exec : main : BaseThreadInitThunk : RtlUserThreadStart :
QGIS Info
QGIS Version: 3.2.0-Bonn
QGIS code revision: bc43194061
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4
System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134
Associated revisions
qspatialite: 'update' qt5 port (fixes #19419)
qspatialite: 'update' qt5 port (fixes #19419)
(backport 6551913a, c7e914cd, 1201df57 & 67e846e3)
History
#1 Updated by Jürgen Fischer over 6 years ago
- Assignee set to Jürgen Fischer
#2 Updated by Jochen Schwarze over 6 years ago
seems to work at first sight when using QSQLITE driver instead of QSPATIALITE but this does of course not work when geometry involved in queries:
>>>db = QSqlDatabase.addDatabase('QSPATIALITE')
>>>db.setDatabaseName('C:\\tmp\\test.sqlite')
>>>db.open()
True
q = QSqlQuery('select some_int, geometry from test', db)
>>>while q.next():
>>>... print(q.value(0), q.value(1))
>>>q.lastError().text()
'no such table: test Unable to execute statement'
#3 Updated by Jürgen Fischer over 6 years ago
- % Done changed from 0 to 100
- Status changed from Open to Closed
Applied in changeset qgis|6551913aa499b02f4b6de1090cd350abe0bce16d.