Move the dbmstype to QSqlDriverPrivate so it can be used for all drivers

By moving it to QSqlDriverPrivate we make it easier to check what
database is actually connected which is particularly useful for the
autotests.

Change-Id: I54d1c2c998919c1d54efb1b6ac9303070ece54aa
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
Andy Shaw 2013-03-30 19:55:25 +01:00 committed by The Qt Project
parent dcf9c403ba
commit 406c8ef6e6
23 changed files with 147 additions and 79 deletions

View File

@ -1,4 +1,4 @@
QT = core sql-private
QT = core core-private sql-private
PLUGIN_TYPE = sqldrivers
load(qt_plugin)

View File

@ -40,6 +40,7 @@
****************************************************************************/
#include "qsql_db2_p.h"
#include <QtSql/private/qsqldriver_p.h>
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qsqlfield.h>
@ -70,10 +71,10 @@ QT_BEGIN_NAMESPACE
static const int COLNAMESIZE = 255;
static const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT };
class QDB2DriverPrivate
class QDB2DriverPrivate : public QSqlDriverPrivate
{
public:
QDB2DriverPrivate(): hEnv(0), hDbc(0) {}
QDB2DriverPrivate() : QSqlDriverPrivate(), hEnv(0), hDbc(0) { dbmsType = DB2; }
SQLHANDLE hEnv;
SQLHANDLE hDbc;
QString user;
@ -1151,7 +1152,6 @@ QDB2Driver::QDB2Driver(Qt::HANDLE env, Qt::HANDLE con, QObject* parent)
QDB2Driver::~QDB2Driver()
{
close();
delete d;
}
bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString& host, int port,

View File

@ -48,6 +48,7 @@
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qlist.h>
#include <qvector.h>
#include <qtextcodec.h>
@ -309,10 +310,10 @@ struct QIBaseEventBuffer {
QIBaseSubscriptionState subscriptionState;
};
class QIBaseDriverPrivate
class QIBaseDriverPrivate : public QSqlDriverPrivate
{
public:
QIBaseDriverPrivate(QIBaseDriver *d) : q(d), ibase(0), trans(0), tc(0) {}
QIBaseDriverPrivate(QIBaseDriver *d) : QSqlDriverPrivate(), q(d), ibase(0), trans(0), tc(0) { dbmsType = Interbase; }
bool isError(const char *msg, QSqlError::ErrorType typ = QSqlError::UnknownError)
{
@ -1411,7 +1412,6 @@ QIBaseDriver::QIBaseDriver(isc_db_handle connection, QObject *parent)
QIBaseDriver::~QIBaseDriver()
{
delete d;
}
bool QIBaseDriver::hasFeature(DriverFeature f) const

View File

@ -41,6 +41,7 @@
#include "qsql_mysql_p.h"
#include <QtSql/private/qsqldriver_p.h>
#include <qcoreapplication.h>
#include <qvariant.h>
#include <qdatetime.h>
@ -76,16 +77,16 @@ Q_DECLARE_METATYPE(MYSQL_STMT*)
QT_BEGIN_NAMESPACE
class QMYSQLDriverPrivate
class QMYSQLDriverPrivate : public QSqlDriverPrivate
{
public:
QMYSQLDriverPrivate() : mysql(0),
QMYSQLDriverPrivate() : QSqlDriverPrivate(), mysql(0),
#ifndef QT_NO_TEXTCODEC
tc(QTextCodec::codecForLocale()),
#else
tc(0),
#endif
preparedQuerysEnabled(false) {}
preparedQuerysEnabled(false) { dbmsType = MySqlServer; }
MYSQL *mysql;
QTextCodec *tc;
@ -1155,7 +1156,6 @@ QMYSQLDriver::~QMYSQLDriver()
qMySqlConnectionCount--;
if (qMySqlConnectionCount == 0 && !qMySqlInitHandledByUser)
qLibraryEnd();
delete d;
}
bool QMYSQLDriver::hasFeature(DriverFeature f) const

View File

@ -52,6 +52,7 @@
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qstringlist.h>
#include <qvarlengtharray.h>
#include <qvector.h>
@ -492,8 +493,9 @@ void QOCIResultPrivate::outValues(QVector<QVariant> &values, IndicatorArray &ind
}
struct QOCIDriverPrivate
class QOCIDriverPrivate : public QSqlDriverPrivate
{
public:
QOCIDriverPrivate();
OCIEnv *env;
@ -511,9 +513,10 @@ struct QOCIDriverPrivate
};
QOCIDriverPrivate::QOCIDriverPrivate()
: env(0), svc(0), srvhp(0), authp(0), err(0), transaction(false), serverVersion(-1),
prefetchRows(-1), prefetchMem(QOCI_PREFETCH_MEM)
: QSqlDriverPrivate(), env(0), svc(0), srvhp(0), authp(0), err(0), transaction(false),
serverVersion(-1), prefetchRows(-1), prefetchMem(QOCI_PREFETCH_MEM)
{
dbmsType = Oracle;
}
void QOCIDriverPrivate::allocErrorHandle()
@ -2137,8 +2140,6 @@ QOCIDriver::~QOCIDriver()
r = OCIHandleFree(d->env, OCI_HTYPE_ENV);
if (r != OCI_SUCCESS)
qWarning("Unable to free Environment handle: %d", r);
delete d;
}
bool QOCIDriver::hasFeature(DriverFeature f) const

View File

@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE
class QOCIDriver;
class QOCICols;
struct QOCIDriverPrivate;
class QOCIDriverPrivate;
class Q_EXPORT_SQLDRIVER_OCI QOCIDriver : public QSqlDriver
{

View File

@ -57,6 +57,7 @@
#include <qmath.h>
#include <QDebug>
#include <QSqlQuery>
#include <QtSql/private/qsqldriver_p.h>
QT_BEGIN_NAMESPACE
@ -111,15 +112,13 @@ inline static QVarLengthArray<SQLTCHAR> toSQLTCHAR(const QString &input)
return result;
}
class QODBCDriverPrivate
class QODBCDriverPrivate : public QSqlDriverPrivate
{
public:
enum DefaultCase{Lower, Mixed, Upper, Sensitive};
enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase};
QODBCDriverPrivate()
: hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19),
dbmsType(UnknownDB), isFreeTDSDriver(false), hasSQLFetchScroll(true),
hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
: QSqlDriverPrivate(), hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19),
isFreeTDSDriver(false), hasSQLFetchScroll(true), hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
{
}
@ -130,7 +129,6 @@ public:
bool useSchema;
int disconnectCount;
int datetime_precision;
DBMSType dbmsType;
bool isFreeTDSDriver;
bool hasSQLFetchScroll;
bool hasMultiResultSets;
@ -1794,7 +1792,6 @@ void QODBCDriver::init()
QODBCDriver::~QODBCDriver()
{
cleanup();
delete d;
}
bool QODBCDriver::hasFeature(DriverFeature f) const

View File

@ -54,6 +54,7 @@
#include <qstringlist.h>
#include <qmutex.h>
#include <QtSql/private/qsqlresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <libpq-fe.h>
#include <pg_config.h>
@ -121,18 +122,18 @@ inline void qPQfreemem(void *buffer)
PQfreemem(buffer);
}
class QPSQLDriverPrivate
class QPSQLDriverPrivate : public QSqlDriverPrivate
{
public:
QPSQLDriverPrivate(QPSQLDriver *qq)
: q(qq),
QPSQLDriverPrivate(QPSQLDriver *qq) : QSqlDriverPrivate(),
q(qq),
connection(0),
isUtf8(false),
pro(QPSQLDriver::Version6),
sn(0),
pendingNotifyCheck(false),
hasBackslashEscape(false)
{ }
{ dbmsType = PostgreSQL; }
QPSQLDriver *q;
PGconn *connection;
@ -793,7 +794,6 @@ QPSQLDriver::~QPSQLDriver()
{
if (d->connection)
PQfinish(d->connection);
delete d;
}
QVariant QPSQLDriver::handle() const

View File

@ -48,6 +48,7 @@
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qstringlist.h>
#include <qvector.h>
#include <qdebug.h>
@ -134,10 +135,10 @@ private:
QSQLiteResultPrivate* d;
};
class QSQLiteDriverPrivate
class QSQLiteDriverPrivate : public QSqlDriverPrivate
{
public:
inline QSQLiteDriverPrivate() : access(0) {}
inline QSQLiteDriverPrivate() : QSqlDriverPrivate(), access(0) { dbmsType = SQLite; }
sqlite3 *access;
QList <QSQLiteResult *> results;
};
@ -546,7 +547,6 @@ QSQLiteDriver::QSQLiteDriver(sqlite3 *connection, QObject *parent)
QSQLiteDriver::~QSQLiteDriver()
{
delete d;
}
bool QSQLiteDriver::hasFeature(DriverFeature f) const

View File

@ -51,6 +51,7 @@
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qstringlist.h>
#include <qvector.h>
@ -82,7 +83,7 @@ static QVariant::Type nameToType(const QString& typeName)
return QVariant::String;
}
class QSQLite2DriverPrivate
class QSQLite2DriverPrivate : public QSqlDriverPrivate
{
public:
QSQLite2DriverPrivate();
@ -90,9 +91,10 @@ public:
bool utf8;
};
QSQLite2DriverPrivate::QSQLite2DriverPrivate() : access(0)
QSQLite2DriverPrivate::QSQLite2DriverPrivate() : QSqlDriverPrivate(), access(0)
{
utf8 = (qstrcmp(sqlite_encoding, "UTF-8") == 0);
dbmsType = SQLite;
}
class QSQLite2ResultPrivate;
@ -392,7 +394,6 @@ QSQLite2Driver::QSQLite2Driver(sqlite *connection, QObject *parent)
QSQLite2Driver::~QSQLite2Driver()
{
delete d;
}
bool QSQLite2Driver::hasFeature(DriverFeature f) const

View File

@ -59,6 +59,7 @@
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qstringlist.h>
#include <qvector.h>
@ -136,10 +137,10 @@ QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, int errNo =
return QSqlError(QLatin1String("QTDS: ") + err, QString(), type, errNo);
}
class QTDSDriverPrivate
class QTDSDriverPrivate : public QSqlDriverPrivate
{
public:
QTDSDriverPrivate(): login(0), initialized(false) {}
QTDSDriverPrivate() : QSqlDriverPrivate(), login(0), initialized(false) { dbmsType = Sybase; }
LOGINREC* login; // login information
QString hostName;
QString db;
@ -579,7 +580,6 @@ QTDSDriver::~QTDSDriver()
dbmsghandle(0);
// dbexit also calls dbclose if necessary
dbexit();
delete d;
}
bool QTDSDriver::hasFeature(DriverFeature f) const

View File

@ -4,6 +4,7 @@ HEADERS += kernel/qsql.h \
kernel/qsqlfield.h \
kernel/qsqlrecord.h \
kernel/qsqldriver.h \
kernel/qsqldriver_p.h \
kernel/qsqlnulldriver_p.h \
kernel/qsqldriverplugin.h \
kernel/qsqlerror.h \

View File

@ -46,6 +46,7 @@
#include "qsqlfield.h"
#include "qsqlindex.h"
#include "private/qobject_p.h"
#include "private/qsqldriver_p.h"
QT_BEGIN_NAMESPACE
@ -60,30 +61,6 @@ static QString prepareIdentifier(const QString &identifier,
return ret;
}
class QSqlDriverPrivate : public QObjectPrivate
{
public:
QSqlDriverPrivate();
virtual ~QSqlDriverPrivate();
public:
// @CHECK: this member is never used. It was named q, which expanded to q_func().
QSqlDriver *q_func();
uint isOpen : 1;
uint isOpenError : 1;
QSqlError error;
QSql::NumericalPrecisionPolicy precisionPolicy;
};
inline QSqlDriverPrivate::QSqlDriverPrivate()
: QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble)
{
}
QSqlDriverPrivate::~QSqlDriverPrivate()
{
}
/*!
\class QSqlDriver
\brief The QSqlDriver class is an abstract base class for accessing

View File

@ -0,0 +1,91 @@
/****************************************************************************
**
** 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 "private/qobject_p.h"
#include "qsqldriver.h"
#include "qsqlerror.h"
QT_BEGIN_NAMESPACE
class QSqlDriverPrivate : public QObjectPrivate
{
public:
enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase, SQLite, Interbase, DB2};
QSqlDriverPrivate();
virtual ~QSqlDriverPrivate();
public:
// @CHECK: this member is never used. It was named q, which expanded to q_func().
QSqlDriver *q_func();
uint isOpen : 1;
uint isOpenError : 1;
QSqlError error;
QSql::NumericalPrecisionPolicy precisionPolicy;
DBMSType dbmsType;
};
inline QSqlDriverPrivate::QSqlDriverPrivate()
: QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble),
dbmsType(UnknownDB)
{
}
QSqlDriverPrivate::~QSqlDriverPrivate()
{
}
QT_END_NAMESPACE
#endif // QSQLDRIVER_P_H

View File

@ -3,7 +3,7 @@ CONFIG += parallel_test
TARGET = tst_qsql
SOURCES += tst_qsql.cpp
QT += sql sql-private gui testlib
QT += sql sql-private gui testlib core-private
wince*: {
DEPLOYMENT_PLUGIN += qsqlite

View File

@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qsqldatabase
SOURCES += tst_qsqldatabase.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
win32: {
!wince*: LIBS += -lws2_32

View File

@ -52,7 +52,7 @@
#include <QVariant>
#include <QDebug>
#include <QSqlTableModel>
#include <QtSql/private/qsqldriver_p.h>
#include <QtTest/QtTest>
#if defined (Q_OS_WIN) || defined (Q_OS_WIN32)
@ -510,11 +510,8 @@ public:
static bool isSqlServer( QSqlDatabase db )
{
return db.databaseName().contains( "sql server", Qt::CaseInsensitive )
|| db.databaseName().contains( "sqlserver", Qt::CaseInsensitive )
|| db.databaseName().contains( "sql native client", Qt::CaseInsensitive )
|| db.databaseName().contains( "bq-winserv", Qt::CaseInsensitive )
|| db.hostName().contains( "bq-winserv", Qt::CaseInsensitive );
QSqlDriverPrivate *d = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(db.driver()));
return d->dbmsType == QSqlDriverPrivate::MSSqlServer;
}
static bool isMSAccess( QSqlDatabase db )
@ -524,16 +521,19 @@ public:
static bool isPostgreSQL( QSqlDatabase db )
{
return db.driverName().startsWith("QPSQL") || (db.driverName().startsWith("QODBC") && ( db.databaseName().contains("PostgreSQL", Qt::CaseInsensitive) || db.databaseName().contains("pgsql", Qt::CaseInsensitive) ) );
QSqlDriverPrivate *d = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(db.driver()));
return d->dbmsType == QSqlDriverPrivate::PostgreSQL;
}
static bool isMySQL( QSqlDatabase db )
{
return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL", Qt::CaseInsensitive) );
QSqlDriverPrivate *d = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(db.driver()));
return d->dbmsType == QSqlDriverPrivate::MySqlServer;
}
static bool isDB2( QSqlDatabase db )
{
return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2", Qt::CaseInsensitive) );
QSqlDriverPrivate *d = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(db.driver()));
return d->dbmsType == QSqlDriverPrivate::DB2;
}
// -1 on fail, else Oracle version

View File

@ -3,7 +3,7 @@ CONFIG += parallel_test
TARGET = tst_qsqldriver
SOURCES += tst_qsqldriver.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
wince*: {
plugFiles.files = ../../../plugins/sqldrivers

View File

@ -3,7 +3,7 @@ CONFIG += testcase
SOURCES += tst_qsqlquery.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
!wince*:win32:LIBS += -lws2_32

View File

@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qsqlthread
SOURCES += tst_qsqlthread.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
wince*: {

View File

@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qsqlquerymodel
SOURCES += tst_qsqlquerymodel.cpp
QT += widgets sql testlib
QT += widgets sql testlib core-private sql-private
wince*: {
DEPLOYMENT_PLUGIN += qsqlite

View File

@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qsqlrelationaltablemodel
SOURCES += tst_qsqlrelationaltablemodel.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
wince*: {
plugFiles.files = ../../../plugins/sqldrivers

View File

@ -2,6 +2,6 @@ TARGET = tst_bench_qsqlquery
SOURCES += main.cpp
QT = core sql testlib
QT = core sql testlib core-private sql-private
win32: LIBS += -lws2_32
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0