Skip to content

Commit

Permalink
Add support for Qt5 to qspatialite provider.
Browse files Browse the repository at this point in the history
The detachFromResultSet() changes in qsql_spatialite.{cpp,h} are taken
from https://code.qt.io/cgit/qt/qtbase.git/commit/?id=fc15a1d5e2cb064d
by Mark Brand <mabrand@mabrand.nl>.

Additionally the sqlite3 & sqlite3_stmt types need to be declared as
opaque pointers per http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

For Qt5 Q_PLUGIN_METADATA() should be used instead of Q_EXPORT_PLUGIN2()
per http://doc.qt.io/qt-5/qtquick-porting-qt5.html#qml-plugins
  • Loading branch information
sebastic committed Mar 12, 2016
1 parent 3b40e2b commit 12853b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/providers/spatialite/qspatialite/qsql_spatialite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
#include <sqlite3.h>
#include <qgsslconnect.h>

#if QT_VERSION >= 0x050000
Q_DECLARE_OPAQUE_POINTER(sqlite3*)
Q_DECLARE_OPAQUE_POINTER(sqlite3_stmt*)
#endif
Q_DECLARE_METATYPE(sqlite3*)
Q_DECLARE_METATYPE(sqlite3_stmt*)

Expand Down Expand Up @@ -325,10 +329,12 @@ QSpatiaLiteResult::~QSpatiaLiteResult()
void QSpatiaLiteResult::virtual_hook(int id, void *data)
{
switch (id) {
#if QT_VERSION < 0x050000
case QSqlResult::DetachFromResultSet:
if (d->stmt)
sqlite3_reset(d->stmt);
break;
#endif
default:
QSqlCachedResult::virtual_hook(id, data);
}
Expand Down Expand Up @@ -485,6 +491,14 @@ QSqlRecord QSpatiaLiteResult::record() const
return d->rInf;
}

#if QT_VERSION >= 0x050000
void QSpatiaLiteResult::detachFromResultSet()
{
if (d->stmt)
sqlite3_reset(d->stmt);
}
#endif

QVariant QSpatiaLiteResult::handle() const
{
return QVariant::fromValue(d->stmt);
Expand Down
3 changes: 3 additions & 0 deletions src/providers/spatialite/qspatialite/qsql_spatialite.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class QSpatiaLiteResult : public QSqlCachedResult
int numRowsAffected();
QVariant lastInsertId() const;
QSqlRecord record() const;
#if QT_VERSION >= 0x050000
void detachFromResultSet();
#endif
void virtual_hook(int id, void *data);

private:
Expand Down
5 changes: 5 additions & 0 deletions src/providers/spatialite/qspatialite/smain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE

class QSpatiaLiteDriverPlugin : public QSqlDriverPlugin
{
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.qgis.QSpatiaLiteDriverPlugin")
#endif
public:
QSpatiaLiteDriverPlugin();

Expand Down Expand Up @@ -75,7 +78,9 @@ QStringList QSpatiaLiteDriverPlugin::keys() const
return l;
}

#if QT_VERSION < 0x050000
Q_EXPORT_STATIC_PLUGIN(QSpatiaLiteDriverPlugin)
Q_EXPORT_PLUGIN2(qspatialite, QSpatiaLiteDriverPlugin)
#endif

QT_END_NAMESPACE

0 comments on commit 12853b3

Please sign in to comment.