[Qgis-developer] Use of Spatialite in a Python plugin for QGIS?

Noli Sicad nsicad at gmail.com
Fri Apr 29 02:36:58 EDT 2011


Hi Stefan,

Better read this one (below) to fix some of the problems you mentioned.

http://www.gaia-gis.it/spatialite-2.4.0-4/splite-python.html

Please note on this caveat found in the document above.

"Caveat
The most recent QGIS versions (1.6 / 1.7 trunk) are actually using
SpatiaLite v.2.4.0 so any Python plugin using the previous v.2.3.1 can
easily cause conflicts due to version incompatilibiles. And this fully
accounts for any issue noticed by QGIS users".

Noli


On 4/29/11, Stefan Keller <sfkeller at gmail.com> wrote:
> Hello,
>
> We are currently developing a Python Plugin for QGIS. We use
> SpatiaLite to manage some data. What we want to do is, querying a
> SpatiaLite database from a Python Plugin. We were able to get it to
> work with SQLite, using the following code:
>
> self.db = QSqlDatabase.addDatabase("QSQLITE")
> self.db.setDatabaseName("path.to.db.file")
> if self.db.open() == False:
>     raise "Connection Error!"
> query = QSqlQuery(self.db)
> query.exec_("SELECT sqlite_version()")
> if query.isActive():
>     print str(query.value(0).toString()) #
> else:
>     raise str(query.lastError().databaseText ())
> query.finish()
>
> But when we try using a spatialite-function, like "SELECT
> spatialite_version()", the query fails with "no such function:
> spatialite_version". We tried to load the spatialite-Extension
> manually, using "SELECT load_extension('libspatialite-2.dll');", but
> that resulted in an exception "not authorized".
>
> Our question is: What has to be done to use spatialite in a python-plugin?
>
> There is pyspatialite(http://code.google.com/p/pyspatialite/), but we
> would prefer using libraries already included in QGIS.
> Thanks for your help.
>
> Yours, Stefan and Tobias
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>


More information about the Qgis-developer mailing list