Skip to content
Permalink
Browse files

Add support for Qt5 to qspatialite provider.

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 12853b37fb06569994aff81238143351eeb2a1af
@@ -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*)

@@ -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);
}
@@ -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);
@@ -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:
@@ -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();

@@ -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.
You can’t perform that action at this time.