Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS3 QtSqlDatabase 'QSPATIALITE' driver crash #25960

Closed
qgib opened this issue Feb 8, 2018 · 7 comments
Closed

QGIS3 QtSqlDatabase 'QSPATIALITE' driver crash #25960

qgib opened this issue Feb 8, 2018 · 7 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority Plugins Regression Something which used to work, but doesn't anymore

Comments

@qgib
Copy link
Contributor

qgib commented Feb 8, 2018

Author Name: Jakub Kosik (@jakosek)
Original Redmine Issue: 18064
Affected QGIS version: master
Redmine category:python_plugins


I'm trying to port my plugin to python3/Qt5/QGIS3. I'm using spatialite database with QtSqlDatabase to manage plugin requests:
@db = QSqlDatabase.addDatabase('QSPATIALITE')@
When I execute any QSqlQuery on that db - QGIS crashes. Tested with driver 'QSQLITE', no crash (and no spatial functions).

@qgib
Copy link
Contributor Author

qgib commented Feb 22, 2018

Author Name: Giovanni Manghi (@gioman)


  • priority_id was changed from Normal to High

@qgib
Copy link
Contributor Author

qgib commented May 3, 2018

Author Name: Johannes Liem (Johannes Liem)


Hello, I have the very same problem porting my plugin.

Maybe the following helps somehow (not sure if is it appropriate to post here):

from qgis.PyQt.QtSql import QSqlDatabase, QSqlQuery

db = QSqlDatabase.addDatabase('QSPATIALITE')
db.setDatabaseName("Path to Spatialite File e.g. manually created with QGIS")
print(db.isValid(), QSqlDatabase.isDriverAvailable('QSPATIALITE')) #returns both True, if query below is commented out

if not db.open():
    print("DB not open")
else:
    print("DB open")
    q = QSqlQuery(db)
    q.exec_("SELECT sqlite_version(), spatialite_version()")
    q.first()
    print(str(q.value(0)), str(q.value(1)))
    db.close()

Running this code in the QGIS python console (3.0.2) results in a crash (it works in 2.18.19):

QSqlCachedResult::detachFromResultSet :
QSqlQuery::~QSqlQuery :
PyInit_sip :
Py_HashPointer :
Py_CheckFunctionResult :
PyEval_EvalFrameDefault :
PyErr_Occurred :
PyEval_EvalCode
... much more here ...

QGIS Info
QGIS Version: 3.0.2-Girona
QGIS code revision: 307d082e3d
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.16299

I am thinking about a work around using qgis.utils.spatialite_connect for all spatial queries (https://gis.stackexchange.com/questions/260527/how-to-create-a-spatialite-layer-in-qgis-3-with-python) and the 'QSQLITE' driver for non spatial queries to populate PyQt Views/Models/DataMappers (which in my case do not require spatial queries)

@qgib
Copy link
Contributor Author

qgib commented May 4, 2018

Author Name: Jakub Kosik (@jakosek)


I've done with same workaround as you thinking - works for now.

db = QSqlDatabase.addDatabase('QSQLITE')
query = QSqlQuery(db)
request = query.exec_(exp)
if request:
	[...]
else:
	connection = spatialite_connect(dbfile)
	cursor = connection.cursor()
	[...]

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2018

Author Name: Johannes Liem (Johannes Liem)


This problem appears to be fixed #27247
Just successfully tried the code I posted above with QGIS version: 3.2.2-Bonn, QGIS code revision: 2684216

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2018

Author Name: Giovanni Manghi (@gioman)


Johannes Liem wrote:

This problem appears to be fixed

can the ticket issuer confirm? Thanks!


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2018

Author Name: Jakub Kosik (@jakosek)


Yes, I can confirm, works now! Tested on nightly 3.3.0 rev 85d7400

@qgib
Copy link
Contributor Author

qgib commented Aug 22, 2018

Author Name: Giovanni Manghi (@gioman)


  • status_id was changed from Feedback to Closed
  • resolution was changed from to fixed/implemented

@qgib qgib closed this as completed Aug 22, 2018
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority Plugins Crash/Data Corruption Regression Something which used to work, but doesn't anymore labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption High Priority Plugins Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

No branches or pull requests

1 participant