Commit 068c0bd5 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

QSqlite3: fix build with Qt 5.7

Use ${QtSql_PRIVATE_INCLUDE_DIRS} to include the private headers
directly from current Qt install instead of carrying a local copy.
parent 0af638c6
......@@ -33,7 +33,13 @@ ecm_setup_version(${AKONADI_VERSION}
SOVERSION 5)
# Find packages
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED DBus Gui Network Sql Test Widgets Xml)
find_package(Qt5Core ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Private)
find_package(Qt5Sql ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Private)
find_package(Qt5DBus ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Network ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Test ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Widgets ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Xml ${QT_REQUIRED_VERSION} REQUIRED)
find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Config ${KF5_VERSION} CONFIG REQUIRED)
......@@ -129,7 +135,7 @@ else()
set(SQLITE_TYPE "OPTIONAL")
endif()
if(AKONADI_BUILD_QSQLITE AND Qt5Core_VERSION VERSION_LESS 5.7.0) # API change in 5.7 breaks our sqlite driver
if(AKONADI_BUILD_QSQLITE)
set(SQLITE_MIN_VERSION 3.6.23)
find_package(Sqlite ${SQLITE_MIN_VERSION})
set_package_properties(Sqlite PROPERTIES
......
......@@ -9,6 +9,8 @@ message(STATUS "Building QSQLITE3 driver")
set(QSQLITE_INSTALL_PREFIX "${PLUGIN_INSTALL_DIR}/sqldrivers")
include_directories(
${Qt5Core_PRIVATE_INCLUDE_DIRS}
${Qt5Sql_PRIVATE_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/src
${SQLITE_INCLUDE_DIR}
)
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtSql module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSQLCACHEDRESULT_P_H
#define QSQLCACHEDRESULT_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "QtSql/qsqlresult.h"
QT_BEGIN_NAMESPACE
class QVariant;
template <typename T> class QVector;
class QSqlCachedResultPrivate;
class Q_SQL_EXPORT QSqlCachedResult: public QSqlResult
{
public:
virtual ~QSqlCachedResult();
typedef QVector<QVariant> ValueCache;
protected:
QSqlCachedResult(const QSqlDriver * db);
void init(int colCount);
void cleanup();
void clearValues();
virtual bool gotoNext(ValueCache &values, int index) = 0;
QVariant data(int i);
bool isNull(int i);
bool fetch(int i);
bool fetchNext();
bool fetchPrevious();
bool fetchFirst();
bool fetchLast();
int colCount() const;
ValueCache &cache();
void virtual_hook(int id, void *data);
private:
bool cacheNext();
QSqlCachedResultPrivate *d;
};
QT_END_NAMESPACE
#endif // QSQLCACHEDRESULT_P_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSql module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSQLDRIVER_P_H
#define QSQLDRIVER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the QtSQL module. This header file may change from version to version
// without notice, or even be removed.
//
// We mean it.
//
#include "qobject_p.h"
#include "qsqldriver.h"
#include "qsqlerror.h"
QT_BEGIN_NAMESPACE
class QSqlDriverPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QSqlDriver)
public:
enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase, SQLite, Interbase, DB2};
QSqlDriverPrivate()
: QObjectPrivate(),
isOpen(false),
isOpenError(false),
precisionPolicy(QSql::LowPrecisionDouble),
dbmsType(UnknownDB)
{ }
uint isOpen;
uint isOpenError;
QSqlError error;
QSql::NumericalPrecisionPolicy precisionPolicy;
DBMSType dbmsType;
};
QT_END_NAMESPACE
#endif // QSQLDRIVER_P_H
......@@ -51,8 +51,8 @@
#include <qvector.h>
#include <qdebug.h>
#include "QtSql/private/qsqldriver_p.h"
#include "QtSql/private/qsqlcachedresult_p.h"
#include <QtSql/private/qsqldriver_p.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#if defined Q_OS_WIN
# include <qt_windows.h>
......@@ -136,7 +136,10 @@ protected:
void virtual_hook(int id, void *data);
private:
QSQLiteResultPrivate* d;
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
QSQLiteResultPrivate* d_ptr;
#endif
Q_DECLARE_PRIVATE(QSQLiteResult)
};
......@@ -144,24 +147,33 @@ class QSQLiteDriverPrivate : public QSqlDriverPrivate
{
public:
inline QSQLiteDriverPrivate() : access(0) {
dbmsType = SQLite;
dbmsType = QSqlDriver::SQLite;
}
sqlite3 *access;
QList<QSQLiteResult *> results;
};
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
class QSQLiteResultPrivate : public QSqlCachedResultPrivate
#else
class QSQLiteResultPrivate
#endif
{
public:
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
QSQLiteResultPrivate(QSQLiteResult *res, const QSQLiteDriver *drv);
#else
QSQLiteResultPrivate(QSQLiteResult *res);
QSQLiteResult* q_ptr;
#endif
void cleanup();
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
// initializes the recordInfo and the cache
void initColumns(bool emptyResultset);
void finalize();
QSQLiteResult* q;
sqlite3 *access;
sqlite3_stmt *stmt;
......@@ -170,15 +182,27 @@ public:
bool skipRow; // skip the next fetchNext()?
QSqlRecord rInf;
QVector<QVariant> firstRow;
Q_DECLARE_PUBLIC(QSQLiteResult)
};
QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult* res) : q(res), access(0),
stmt(0), skippedStatus(false), skipRow(false)
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult *res, const QSQLiteDriver *drv)
: QSqlCachedResultPrivate(res, drv)
#else
QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult* res)
: q_ptr(res)
#endif
, access(0)
, stmt(0)
, skippedStatus(false)
, skipRow(false)
{
}
void QSQLiteResultPrivate::cleanup()
{
Q_Q(QSQLiteResult);
finalize();
rInf.clear();
skippedStatus = false;
......@@ -199,6 +223,7 @@ void QSQLiteResultPrivate::finalize()
void QSQLiteResultPrivate::initColumns(bool emptyResultset)
{
Q_Q(QSQLiteResult);
int nCols = sqlite3_column_count(stmt);
if (nCols <= 0)
return;
......@@ -251,6 +276,8 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset)
bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
{
Q_Q(QSQLiteResult);
int res;
int i;
......@@ -351,20 +378,28 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
}
QSQLiteResult::QSQLiteResult(const QSQLiteDriver* db)
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
: QSqlCachedResult(*new QSQLiteResultPrivate(this, db))
#else
: QSqlCachedResult(db)
, d_ptr(new QSQLiteResultPrivate(this))
#endif
{
d = new QSQLiteResultPrivate(this);
Q_D(QSQLiteResult);
d->access = db->d_func()->access;
const_cast<QSQLiteDriverPrivate*>(db->d_func())->results.append(this);
}
QSQLiteResult::~QSQLiteResult()
{
Q_D(QSQLiteResult);
const QSqlDriver *sqlDriver = driver();
if (sqlDriver)
const_cast<QSQLiteDriverPrivate*>(qobject_cast<const QSQLiteDriver *>(sqlDriver)->d_func())->results.removeOne(this);
d->cleanup();
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
delete d;
#endif
}
void QSQLiteResult::virtual_hook(int id, void *data)
......@@ -381,6 +416,8 @@ bool QSQLiteResult::reset(const QString &query)
bool QSQLiteResult::prepare(const QString &query)
{
Q_D(QSQLiteResult);
if (!driver() || !driver()->isOpen() || driver()->isOpenError())
return false;
......@@ -416,6 +453,7 @@ bool QSQLiteResult::prepare(const QString &query)
bool QSQLiteResult::exec()
{
Q_D(QSQLiteResult);
const QVector<QVariant> values = boundValues();
d->skippedStatus = false;
......@@ -510,7 +548,7 @@ bool QSQLiteResult::exec()
bool QSQLiteResult::gotoNext(QSqlCachedResult::ValueCache& row, int idx)
{
return d->fetchNext(row, idx, false);
return d_func()->fetchNext(row, idx, false);
}
int QSQLiteResult::size()
......@@ -520,13 +558,13 @@ int QSQLiteResult::size()
int QSQLiteResult::numRowsAffected()
{
return sqlite3_changes(d->access);
return sqlite3_changes(d_func()->access);
}
QVariant QSQLiteResult::lastInsertId() const
{
if (isActive()) {
qint64 id = sqlite3_last_insert_rowid(d->access);
qint64 id = sqlite3_last_insert_rowid(d_func()->access);
if (id)
return id;
}
......@@ -537,18 +575,18 @@ QSqlRecord QSQLiteResult::record() const
{
if (!isActive() || !isSelect())
return QSqlRecord();
return d->rInf;
return d_func()->rInf;
}
void QSQLiteResult::detachFromResultSet()
{
if (d->stmt)
sqlite3_reset(d->stmt);
if (d_func()->stmt)
sqlite3_reset(d_func()->stmt);
}
QVariant QSQLiteResult::handle() const
{
return qVariantFromValue(d->stmt);
return qVariantFromValue(d_func()->stmt);
}
/////////////////////////////////////////////////////////
......@@ -660,7 +698,7 @@ void QSQLiteDriver::close()
if (isOpen()) {
Q_FOREACH (QSQLiteResult *result, d->results) {
result->d->finalize();
result->d_func()->finalize();
}
if (sqlite3_close(d->access) != SQLITE_OK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment