QSqlDriver: use Q_DECLARE_PUBLIC/Q_DECLARE_PRIVATE

406c8ef6e6 introduced deriving the private SQL driver classes from
QSqlDriverPrivate. However, the drivers continued to keep their own
pointer to the private class, even though QObject provides the same
pointer. Worse yet, the private class is allocated too late and not
even passed to QSqlDriver. The result is that QSqlDriver allocates
a separate instance of QSqlDriverPrivate. This is likely to cause
all kinds of chaos.

The private class needs to be allocated in time pass it to QSqlDriver
which passes it on to QObject.

This commit covers the the base class and drivers:
    ibase
    mysql
    odbc
    psql
    sqlite
    tds

Fixes for the remaining drivers will follow.

Change-Id: Id8e7ec4205b0ca6cd00bd022c9cd24f137089245
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
This commit is contained in:
Mark Brand 2013-04-03 21:44:30 +02:00 committed by The Qt Project
parent 708d39fa31
commit 0bdc86d9ef
15 changed files with 154 additions and 106 deletions

View File

@ -312,11 +312,13 @@ struct QIBaseEventBuffer {
class QIBaseDriverPrivate : public QSqlDriverPrivate class QIBaseDriverPrivate : public QSqlDriverPrivate
{ {
Q_DECLARE_PUBLIC(QIBaseDriver)
public: public:
QIBaseDriverPrivate(QIBaseDriver *d) : QSqlDriverPrivate(), q(d), ibase(0), trans(0), tc(0) { dbmsType = Interbase; } QIBaseDriverPrivate() : QSqlDriverPrivate(), ibase(0), trans(0), tc(0) { dbmsType = Interbase; }
bool isError(const char *msg, QSqlError::ErrorType typ = QSqlError::UnknownError) bool isError(const char *msg, QSqlError::ErrorType typ = QSqlError::UnknownError)
{ {
Q_Q(QIBaseDriver);
QString imsg; QString imsg;
ISC_LONG sqlcode; ISC_LONG sqlcode;
if (!getIBaseError(imsg, status, sqlcode, tc)) if (!getIBaseError(imsg, status, sqlcode, tc))
@ -328,7 +330,6 @@ public:
} }
public: public:
QIBaseDriver* q;
isc_db_handle ibase; isc_db_handle ibase;
isc_tr_handle trans; isc_tr_handle trans;
QTextCodec *tc; QTextCodec *tc;
@ -418,9 +419,9 @@ public:
QIBaseResultPrivate::QIBaseResultPrivate(QIBaseResult *d, const QIBaseDriver *ddb): QIBaseResultPrivate::QIBaseResultPrivate(QIBaseResult *d, const QIBaseDriver *ddb):
q(d), db(ddb), trans(0), stmt(0), ibase(ddb->d->ibase), sqlda(0), inda(0), queryType(-1), tc(ddb->d->tc) q(d), db(ddb), trans(0), stmt(0), ibase(ddb->d_func()->ibase), sqlda(0), inda(0), queryType(-1), tc(ddb->d_func()->tc)
{ {
localTransaction = (ddb->d->ibase == 0); localTransaction = (ddb->d_func()->ibase == 0);
} }
void QIBaseResultPrivate::cleanup() void QIBaseResultPrivate::cleanup()
@ -861,9 +862,9 @@ bool QIBaseResultPrivate::transaction()
{ {
if (trans) if (trans)
return true; return true;
if (db->d->trans) { if (db->d_func()->trans) {
localTransaction = false; localTransaction = false;
trans = db->d->trans; trans = db->d_func()->trans;
return true; return true;
} }
localTransaction = true; localTransaction = true;
@ -1396,15 +1397,14 @@ QVariant QIBaseResult::handle() const
/*********************************/ /*********************************/
QIBaseDriver::QIBaseDriver(QObject * parent) QIBaseDriver::QIBaseDriver(QObject * parent)
: QSqlDriver(parent) : QSqlDriver(*new QIBaseDriverPrivate, parent)
{ {
d = new QIBaseDriverPrivate(this);
} }
QIBaseDriver::QIBaseDriver(isc_db_handle connection, QObject *parent) QIBaseDriver::QIBaseDriver(isc_db_handle connection, QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QIBaseDriverPrivate, parent)
{ {
d = new QIBaseDriverPrivate(this); Q_D(QIBaseDriver);
d->ibase = connection; d->ibase = connection;
setOpen(true); setOpen(true);
setOpenError(false); setOpenError(false);
@ -1444,6 +1444,7 @@ bool QIBaseDriver::open(const QString & db,
int /*port*/, int /*port*/,
const QString & connOpts) const QString & connOpts)
{ {
Q_D(QIBaseDriver);
if (isOpen()) if (isOpen())
close(); close();
@ -1526,6 +1527,7 @@ bool QIBaseDriver::open(const QString & db,
void QIBaseDriver::close() void QIBaseDriver::close()
{ {
Q_D(QIBaseDriver);
if (isOpen()) { if (isOpen()) {
if (d->eventBuffers.size()) { if (d->eventBuffers.size()) {
@ -1562,6 +1564,7 @@ QSqlResult *QIBaseDriver::createResult() const
bool QIBaseDriver::beginTransaction() bool QIBaseDriver::beginTransaction()
{ {
Q_D(QIBaseDriver);
if (!isOpen() || isOpenError()) if (!isOpen() || isOpenError())
return false; return false;
if (d->trans) if (d->trans)
@ -1574,6 +1577,7 @@ bool QIBaseDriver::beginTransaction()
bool QIBaseDriver::commitTransaction() bool QIBaseDriver::commitTransaction()
{ {
Q_D(QIBaseDriver);
if (!isOpen() || isOpenError()) if (!isOpen() || isOpenError())
return false; return false;
if (!d->trans) if (!d->trans)
@ -1587,6 +1591,7 @@ bool QIBaseDriver::commitTransaction()
bool QIBaseDriver::rollbackTransaction() bool QIBaseDriver::rollbackTransaction()
{ {
Q_D(QIBaseDriver);
if (!isOpen() || isOpenError()) if (!isOpen() || isOpenError())
return false; return false;
if (!d->trans) if (!d->trans)
@ -1749,6 +1754,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons
QVariant QIBaseDriver::handle() const QVariant QIBaseDriver::handle() const
{ {
Q_D(const QIBaseDriver);
return QVariant(qRegisterMetaType<isc_db_handle>("isc_db_handle"), &d->ibase); return QVariant(qRegisterMetaType<isc_db_handle>("isc_db_handle"), &d->ibase);
} }
@ -1777,6 +1783,7 @@ static isc_callback qEventCallback(char *result, short length, char *updated)
bool QIBaseDriver::subscribeToNotification(const QString &name) bool QIBaseDriver::subscribeToNotification(const QString &name)
{ {
Q_D(QIBaseDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QIBaseDriver::subscribeFromNotificationImplementation: database not open."); qWarning("QIBaseDriver::subscribeFromNotificationImplementation: database not open.");
return false; return false;
@ -1826,6 +1833,7 @@ bool QIBaseDriver::subscribeToNotification(const QString &name)
bool QIBaseDriver::unsubscribeFromNotification(const QString &name) bool QIBaseDriver::unsubscribeFromNotification(const QString &name)
{ {
Q_D(QIBaseDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QIBaseDriver::unsubscribeFromNotificationImplementation: database not open."); qWarning("QIBaseDriver::unsubscribeFromNotificationImplementation: database not open.");
return false; return false;
@ -1855,11 +1863,13 @@ bool QIBaseDriver::unsubscribeFromNotification(const QString &name)
QStringList QIBaseDriver::subscribedToNotifications() const QStringList QIBaseDriver::subscribedToNotifications() const
{ {
Q_D(const QIBaseDriver);
return QStringList(d->eventBuffers.keys()); return QStringList(d->eventBuffers.keys());
} }
void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer) void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer)
{ {
Q_D(QIBaseDriver);
QMap<QString, QIBaseEventBuffer *>::const_iterator i; QMap<QString, QIBaseEventBuffer *>::const_iterator i;
for (i = d->eventBuffers.constBegin(); i != d->eventBuffers.constEnd(); ++i) { for (i = d->eventBuffers.constBegin(); i != d->eventBuffers.constEnd(); ++i) {
QIBaseEventBuffer* eBuffer = i.value(); QIBaseEventBuffer* eBuffer = i.value();

View File

@ -64,9 +64,9 @@ class QIBaseDriver;
class QIBaseDriver : public QSqlDriver class QIBaseDriver : public QSqlDriver
{ {
Q_OBJECT
friend class QIBaseDriverPrivate;
friend class QIBaseResultPrivate; friend class QIBaseResultPrivate;
Q_DECLARE_PRIVATE(QIBaseDriver)
Q_OBJECT
public: public:
explicit QIBaseDriver(QObject *parent = 0); explicit QIBaseDriver(QObject *parent = 0);
explicit QIBaseDriver(isc_db_handle connection, QObject *parent = 0); explicit QIBaseDriver(isc_db_handle connection, QObject *parent = 0);
@ -104,9 +104,6 @@ public:
private Q_SLOTS: private Q_SLOTS:
void qHandleEventNotification(void* updatedResultBuffer); void qHandleEventNotification(void* updatedResultBuffer);
private:
QIBaseDriverPrivate* d;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -435,8 +435,8 @@ void QMYSQLResult::cleanup()
// must iterate trough leftover result sets from multi-selects or stored procedures // must iterate trough leftover result sets from multi-selects or stored procedures
// if this isn't done subsequent queries will fail with "Commands out of sync" // if this isn't done subsequent queries will fail with "Commands out of sync"
#if MYSQL_VERSION_ID >= 40100 #if MYSQL_VERSION_ID >= 40100
while (d->driver && d->driver->d->mysql && mysql_next_result(d->driver->d->mysql) == 0) { while (d->driver && d->driver->d_func()->mysql && mysql_next_result(d->driver->d_func()->mysql) == 0) {
MYSQL_RES *res = mysql_store_result(d->driver->d->mysql); MYSQL_RES *res = mysql_store_result(d->driver->d_func()->mysql);
if (res) if (res)
mysql_free_result(res); mysql_free_result(res);
} }
@ -606,7 +606,7 @@ QVariant QMYSQLResult::data(int field)
return QVariant(f.type); return QVariant(f.type);
if (f.type != QVariant::ByteArray) if (f.type != QVariant::ByteArray)
val = toUnicode(d->driver->d->tc, f.outField, f.bufLength); val = toUnicode(d->driver->d_func()->tc, f.outField, f.bufLength);
} else { } else {
if (d->row[field] == NULL) { if (d->row[field] == NULL) {
// NULL value // NULL value
@ -614,7 +614,7 @@ QVariant QMYSQLResult::data(int field)
} }
fieldLength = mysql_fetch_lengths(d->result)[field]; fieldLength = mysql_fetch_lengths(d->result)[field];
if (f.type != QVariant::ByteArray) if (f.type != QVariant::ByteArray)
val = toUnicode(d->driver->d->tc, d->row[field], fieldLength); val = toUnicode(d->driver->d_func()->tc, d->row[field], fieldLength);
} }
switch(f.type) { switch(f.type) {
@ -693,22 +693,22 @@ bool QMYSQLResult::reset (const QString& query)
cleanup(); cleanup();
const QByteArray encQuery(fromUnicode(d->driver->d->tc, query)); const QByteArray encQuery(fromUnicode(d->driver->d_func()->tc, query));
if (mysql_real_query(d->driver->d->mysql, encQuery.data(), encQuery.length())) { if (mysql_real_query(d->driver->d_func()->mysql, encQuery.data(), encQuery.length())) {
setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute query"), setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute query"),
QSqlError::StatementError, d->driver->d)); QSqlError::StatementError, d->driver->d_func()));
return false; return false;
} }
d->result = mysql_store_result(d->driver->d->mysql); d->result = mysql_store_result(d->driver->d_func()->mysql);
if (!d->result && mysql_field_count(d->driver->d->mysql) > 0) { if (!d->result && mysql_field_count(d->driver->d_func()->mysql) > 0) {
setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store result"), setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store result"),
QSqlError::StatementError, d->driver->d)); QSqlError::StatementError, d->driver->d_func()));
return false; return false;
} }
int numFields = mysql_field_count(d->driver->d->mysql); int numFields = mysql_field_count(d->driver->d_func()->mysql);
setSelect(numFields != 0); setSelect(numFields != 0);
d->fields.resize(numFields); d->fields.resize(numFields);
d->rowsAffected = mysql_affected_rows(d->driver->d->mysql); d->rowsAffected = mysql_affected_rows(d->driver->d_func()->mysql);
if (isSelect()) { if (isSelect()) {
for(int i = 0; i < numFields; i++) { for(int i = 0; i < numFields; i++) {
@ -753,7 +753,7 @@ QVariant QMYSQLResult::lastInsertId() const
return QVariant(id); return QVariant(id);
#endif #endif
} else { } else {
quint64 id = mysql_insert_id(d->driver->d->mysql); quint64 id = mysql_insert_id(d->driver->d_func()->mysql);
if (id) if (id)
return QVariant(id); return QVariant(id);
} }
@ -773,11 +773,11 @@ QSqlRecord QMYSQLResult::record() const
res = d->result; res = d->result;
#endif #endif
if (!mysql_errno(d->driver->d->mysql)) { if (!mysql_errno(d->driver->d_func()->mysql)) {
mysql_field_seek(res, 0); mysql_field_seek(res, 0);
MYSQL_FIELD* field = mysql_fetch_field(res); MYSQL_FIELD* field = mysql_fetch_field(res);
while(field) { while(field) {
info.append(qToField(field, d->driver->d->tc)); info.append(qToField(field, d->driver->d_func()->tc));
field = mysql_fetch_field(res); field = mysql_fetch_field(res);
} }
} }
@ -802,26 +802,26 @@ bool QMYSQLResult::nextResult()
delete[] d->fields[i].outField; delete[] d->fields[i].outField;
d->fields.clear(); d->fields.clear();
int status = mysql_next_result(d->driver->d->mysql); int status = mysql_next_result(d->driver->d_func()->mysql);
if (status > 0) { if (status > 0) {
setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute next query"), setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to execute next query"),
QSqlError::StatementError, d->driver->d)); QSqlError::StatementError, d->driver->d_func()));
return false; return false;
} else if (status == -1) { } else if (status == -1) {
return false; // No more result sets return false; // No more result sets
} }
d->result = mysql_store_result(d->driver->d->mysql); d->result = mysql_store_result(d->driver->d_func()->mysql);
int numFields = mysql_field_count(d->driver->d->mysql); int numFields = mysql_field_count(d->driver->d_func()->mysql);
if (!d->result && numFields > 0) { if (!d->result && numFields > 0) {
setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store next result"), setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to store next result"),
QSqlError::StatementError, d->driver->d)); QSqlError::StatementError, d->driver->d_func()));
return false; return false;
} }
setSelect(numFields > 0); setSelect(numFields > 0);
d->fields.resize(numFields); d->fields.resize(numFields);
d->rowsAffected = mysql_affected_rows(d->driver->d->mysql); d->rowsAffected = mysql_affected_rows(d->driver->d_func()->mysql);
if (isSelect()) { if (isSelect()) {
for (int i = 0; i < numFields; i++) { for (int i = 0; i < numFields; i++) {
@ -874,7 +874,7 @@ bool QMYSQLResult::prepare(const QString& query)
return false; return false;
#if MYSQL_VERSION_ID >= 40108 #if MYSQL_VERSION_ID >= 40108
cleanup(); cleanup();
if (!d->driver->d->preparedQuerysEnabled) if (!d->driver->d_func()->preparedQuerysEnabled)
return QSqlResult::prepare(query); return QSqlResult::prepare(query);
int r; int r;
@ -883,14 +883,14 @@ bool QMYSQLResult::prepare(const QString& query)
return false; return false;
if (!d->stmt) if (!d->stmt)
d->stmt = mysql_stmt_init(d->driver->d->mysql); d->stmt = mysql_stmt_init(d->driver->d_func()->mysql);
if (!d->stmt) { if (!d->stmt) {
setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to prepare statement"), setLastError(qMakeError(QCoreApplication::translate("QMYSQLResult", "Unable to prepare statement"),
QSqlError::StatementError, d->driver->d)); QSqlError::StatementError, d->driver->d_func()));
return false; return false;
} }
const QByteArray encQuery(fromUnicode(d->driver->d->tc, query)); const QByteArray encQuery(fromUnicode(d->driver->d_func()->tc, query));
r = mysql_stmt_prepare(d->stmt, encQuery.constData(), encQuery.length()); r = mysql_stmt_prepare(d->stmt, encQuery.constData(), encQuery.length());
if (r != 0) { if (r != 0) {
setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult", setLastError(qMakeStmtError(QCoreApplication::translate("QMYSQLResult",
@ -1010,7 +1010,7 @@ bool QMYSQLResult::exec()
break; break;
case QVariant::String: case QVariant::String:
default: { default: {
QByteArray ba = fromUnicode(d->driver->d->tc, val.toString()); QByteArray ba = fromUnicode(d->driver->d_func()->tc, val.toString());
stringVector.append(ba); stringVector.append(ba);
currBind->buffer_type = MYSQL_TYPE_STRING; currBind->buffer_type = MYSQL_TYPE_STRING;
currBind->buffer = const_cast<char *>(ba.constData()); currBind->buffer = const_cast<char *>(ba.constData());
@ -1115,7 +1115,7 @@ static void qLibraryEnd()
} }
QMYSQLDriver::QMYSQLDriver(QObject * parent) QMYSQLDriver::QMYSQLDriver(QObject * parent)
: QSqlDriver(parent) : QSqlDriver(*new QMYSQLDriverPrivate, parent)
{ {
init(); init();
qLibraryInit(); qLibraryInit();
@ -1127,8 +1127,9 @@ QMYSQLDriver::QMYSQLDriver(QObject * parent)
*/ */
QMYSQLDriver::QMYSQLDriver(MYSQL * con, QObject * parent) QMYSQLDriver::QMYSQLDriver(MYSQL * con, QObject * parent)
: QSqlDriver(parent) : QSqlDriver(*new QMYSQLDriverPrivate, parent)
{ {
Q_D(QMYSQLDriver);
init(); init();
if (con) { if (con) {
d->mysql = (MYSQL *) con; d->mysql = (MYSQL *) con;
@ -1146,7 +1147,7 @@ QMYSQLDriver::QMYSQLDriver(MYSQL * con, QObject * parent)
void QMYSQLDriver::init() void QMYSQLDriver::init()
{ {
d = new QMYSQLDriverPrivate(); Q_D(QMYSQLDriver);
d->mysql = 0; d->mysql = 0;
qMySqlConnectionCount++; qMySqlConnectionCount++;
} }
@ -1160,6 +1161,7 @@ QMYSQLDriver::~QMYSQLDriver()
bool QMYSQLDriver::hasFeature(DriverFeature f) const bool QMYSQLDriver::hasFeature(DriverFeature f) const
{ {
Q_D(const QMYSQLDriver);
switch (f) { switch (f) {
case Transactions: case Transactions:
// CLIENT_TRANSACTION should be defined in all recent mysql client libs > 3.23.34 // CLIENT_TRANSACTION should be defined in all recent mysql client libs > 3.23.34
@ -1227,6 +1229,7 @@ bool QMYSQLDriver::open(const QString& db,
int port, int port,
const QString& connOpts) const QString& connOpts)
{ {
Q_D(QMYSQLDriver);
if (isOpen()) if (isOpen())
close(); close();
@ -1328,6 +1331,7 @@ bool QMYSQLDriver::open(const QString& db,
void QMYSQLDriver::close() void QMYSQLDriver::close()
{ {
Q_D(QMYSQLDriver);
if (isOpen()) { if (isOpen()) {
#ifndef QT_NO_THREAD #ifndef QT_NO_THREAD
mysql_thread_end(); mysql_thread_end();
@ -1346,6 +1350,7 @@ QSqlResult *QMYSQLDriver::createResult() const
QStringList QMYSQLDriver::tables(QSql::TableType type) const QStringList QMYSQLDriver::tables(QSql::TableType type) const
{ {
Q_D(const QMYSQLDriver);
QStringList tl; QStringList tl;
#if MYSQL_VERSION_ID >= 40100 #if MYSQL_VERSION_ID >= 40100
if( mysql_get_server_version(d->mysql) < 50000) if( mysql_get_server_version(d->mysql) < 50000)
@ -1413,6 +1418,7 @@ QSqlIndex QMYSQLDriver::primaryIndex(const QString& tablename) const
QSqlRecord QMYSQLDriver::record(const QString& tablename) const QSqlRecord QMYSQLDriver::record(const QString& tablename) const
{ {
Q_D(const QMYSQLDriver);
QString table=tablename; QString table=tablename;
if(isIdentifierEscaped(table, QSqlDriver::TableName)) if(isIdentifierEscaped(table, QSqlDriver::TableName))
table = stripDelimiters(table, QSqlDriver::TableName); table = stripDelimiters(table, QSqlDriver::TableName);
@ -1434,11 +1440,13 @@ QSqlRecord QMYSQLDriver::record(const QString& tablename) const
QVariant QMYSQLDriver::handle() const QVariant QMYSQLDriver::handle() const
{ {
Q_D(const QMYSQLDriver);
return QVariant::fromValue(d->mysql); return QVariant::fromValue(d->mysql);
} }
bool QMYSQLDriver::beginTransaction() bool QMYSQLDriver::beginTransaction()
{ {
Q_D(QMYSQLDriver);
#ifndef CLIENT_TRANSACTIONS #ifndef CLIENT_TRANSACTIONS
return false; return false;
#endif #endif
@ -1456,6 +1464,7 @@ bool QMYSQLDriver::beginTransaction()
bool QMYSQLDriver::commitTransaction() bool QMYSQLDriver::commitTransaction()
{ {
Q_D(QMYSQLDriver);
#ifndef CLIENT_TRANSACTIONS #ifndef CLIENT_TRANSACTIONS
return false; return false;
#endif #endif
@ -1473,6 +1482,7 @@ bool QMYSQLDriver::commitTransaction()
bool QMYSQLDriver::rollbackTransaction() bool QMYSQLDriver::rollbackTransaction()
{ {
Q_D(QMYSQLDriver);
#ifndef CLIENT_TRANSACTIONS #ifndef CLIENT_TRANSACTIONS
return false; return false;
#endif #endif
@ -1490,6 +1500,7 @@ bool QMYSQLDriver::rollbackTransaction()
QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
{ {
Q_D(const QMYSQLDriver);
QString r; QString r;
if (field.isNull()) { if (field.isNull()) {
r = QLatin1String("NULL"); r = QLatin1String("NULL");

View File

@ -110,8 +110,9 @@ private:
class Q_EXPORT_SQLDRIVER_MYSQL QMYSQLDriver : public QSqlDriver class Q_EXPORT_SQLDRIVER_MYSQL QMYSQLDriver : public QSqlDriver
{ {
Q_OBJECT
friend class QMYSQLResult; friend class QMYSQLResult;
Q_DECLARE_PRIVATE(QMYSQLDriver)
Q_OBJECT
public: public:
explicit QMYSQLDriver(QObject *parent=0); explicit QMYSQLDriver(QObject *parent=0);
explicit QMYSQLDriver(MYSQL *con, QObject * parent=0); explicit QMYSQLDriver(MYSQL *con, QObject * parent=0);
@ -141,7 +142,6 @@ protected:
bool rollbackTransaction(); bool rollbackTransaction();
private: private:
void init(); void init();
QMYSQLDriverPrivate* d;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -188,13 +188,13 @@ public:
bool QODBCPrivate::isStmtHandleValid(const QSqlDriver *driver) bool QODBCPrivate::isStmtHandleValid(const QSqlDriver *driver)
{ {
const QODBCDriver *odbcdriver = static_cast<const QODBCDriver*> (driver); const QODBCDriver *odbcdriver = static_cast<const QODBCDriver*> (driver);
return disconnectCount == odbcdriver->d->disconnectCount; return disconnectCount == odbcdriver->d_func()->disconnectCount;
} }
void QODBCPrivate::updateStmtHandleState(const QSqlDriver *driver) void QODBCPrivate::updateStmtHandleState(const QSqlDriver *driver)
{ {
const QODBCDriver *odbcdriver = static_cast<const QODBCDriver*> (driver); const QODBCDriver *odbcdriver = static_cast<const QODBCDriver*> (driver);
disconnectCount = odbcdriver->d->disconnectCount; disconnectCount = odbcdriver->d_func()->disconnectCount;
} }
static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode = 0) static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode = 0)
@ -1767,15 +1767,14 @@ void QODBCResult::setForwardOnly(bool forward)
QODBCDriver::QODBCDriver(QObject *parent) QODBCDriver::QODBCDriver(QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QODBCDriverPrivate, parent)
{ {
init();
} }
QODBCDriver::QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent) QODBCDriver::QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QODBCDriverPrivate, parent)
{ {
init(); Q_D(QODBCDriver);
d->hEnv = env; d->hEnv = env;
d->hDbc = con; d->hDbc = con;
if (env && con) { if (env && con) {
@ -1784,11 +1783,6 @@ QODBCDriver::QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent)
} }
} }
void QODBCDriver::init()
{
d = new QODBCDriverPrivate();
}
QODBCDriver::~QODBCDriver() QODBCDriver::~QODBCDriver()
{ {
cleanup(); cleanup();
@ -1796,6 +1790,7 @@ QODBCDriver::~QODBCDriver()
bool QODBCDriver::hasFeature(DriverFeature f) const bool QODBCDriver::hasFeature(DriverFeature f) const
{ {
Q_D(const QODBCDriver);
switch (f) { switch (f) {
case Transactions: { case Transactions: {
if (!d->hDbc) if (!d->hDbc)
@ -1850,6 +1845,7 @@ bool QODBCDriver::open(const QString & db,
int, int,
const QString& connOpts) const QString& connOpts)
{ {
Q_D(QODBCDriver);
if (isOpen()) if (isOpen())
close(); close();
SQLRETURN r; SQLRETURN r;
@ -1946,9 +1942,8 @@ void QODBCDriver::close()
void QODBCDriver::cleanup() void QODBCDriver::cleanup()
{ {
Q_D(QODBCDriver);
SQLRETURN r; SQLRETURN r;
if (!d)
return;
if(d->hDbc) { if(d->hDbc) {
// Open statements/descriptors handles are automatically cleaned up by SQLDisconnect // Open statements/descriptors handles are automatically cleaned up by SQLDisconnect
@ -2196,11 +2191,13 @@ void QODBCDriverPrivate::checkDateTimePrecision()
QSqlResult *QODBCDriver::createResult() const QSqlResult *QODBCDriver::createResult() const
{ {
return new QODBCResult(this, d); Q_D(const QODBCDriver);
return new QODBCResult(this, const_cast<QODBCDriverPrivate*>(d));
} }
bool QODBCDriver::beginTransaction() bool QODBCDriver::beginTransaction()
{ {
Q_D(QODBCDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning() << "QODBCDriver::beginTransaction: Database not open"; qWarning() << "QODBCDriver::beginTransaction: Database not open";
return false; return false;
@ -2220,6 +2217,7 @@ bool QODBCDriver::beginTransaction()
bool QODBCDriver::commitTransaction() bool QODBCDriver::commitTransaction()
{ {
Q_D(QODBCDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning() << "QODBCDriver::commitTransaction: Database not open"; qWarning() << "QODBCDriver::commitTransaction: Database not open";
return false; return false;
@ -2237,6 +2235,7 @@ bool QODBCDriver::commitTransaction()
bool QODBCDriver::rollbackTransaction() bool QODBCDriver::rollbackTransaction()
{ {
Q_D(QODBCDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning() << "QODBCDriver::rollbackTransaction: Database not open"; qWarning() << "QODBCDriver::rollbackTransaction: Database not open";
return false; return false;
@ -2254,6 +2253,7 @@ bool QODBCDriver::rollbackTransaction()
bool QODBCDriver::endTrans() bool QODBCDriver::endTrans()
{ {
Q_D(QODBCDriver);
SQLUINTEGER ac(SQL_AUTOCOMMIT_ON); SQLUINTEGER ac(SQL_AUTOCOMMIT_ON);
SQLRETURN r = SQLSetConnectAttr(d->hDbc, SQLRETURN r = SQLSetConnectAttr(d->hDbc,
SQL_ATTR_AUTOCOMMIT, SQL_ATTR_AUTOCOMMIT,
@ -2268,6 +2268,7 @@ bool QODBCDriver::endTrans()
QStringList QODBCDriver::tables(QSql::TableType type) const QStringList QODBCDriver::tables(QSql::TableType type) const
{ {
Q_D(const QODBCDriver);
QStringList tl; QStringList tl;
if (!isOpen()) if (!isOpen())
return tl; return tl;
@ -2345,6 +2346,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const
QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
{ {
Q_D(const QODBCDriver);
QSqlIndex index(tablename); QSqlIndex index(tablename);
if (!isOpen()) if (!isOpen())
return index; return index;
@ -2360,7 +2362,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
return index; return index;
} }
QString catalog, schema, table; QString catalog, schema, table;
d->splitTableQualifier(tablename, catalog, schema, table); const_cast<QODBCDriverPrivate*>(d)->splitTableQualifier(tablename, catalog, schema, table);
if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) if (isIdentifierEscaped(catalog, QSqlDriver::TableName))
catalog = stripDelimiters(catalog, QSqlDriver::TableName); catalog = stripDelimiters(catalog, QSqlDriver::TableName);
@ -2472,13 +2474,14 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const
QSqlRecord QODBCDriver::record(const QString& tablename) const QSqlRecord QODBCDriver::record(const QString& tablename) const
{ {
Q_D(const QODBCDriver);
QSqlRecord fil; QSqlRecord fil;
if (!isOpen()) if (!isOpen())
return fil; return fil;
SQLHANDLE hStmt; SQLHANDLE hStmt;
QString catalog, schema, table; QString catalog, schema, table;
d->splitTableQualifier(tablename, catalog, schema, table); const_cast<QODBCDriverPrivate*>(d)->splitTableQualifier(tablename, catalog, schema, table);
if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) if (isIdentifierEscaped(catalog, QSqlDriver::TableName))
catalog = stripDelimiters(catalog, QSqlDriver::TableName); catalog = stripDelimiters(catalog, QSqlDriver::TableName);
@ -2597,12 +2600,14 @@ QString QODBCDriver::formatValue(const QSqlField &field,
QVariant QODBCDriver::handle() const QVariant QODBCDriver::handle() const
{ {
Q_D(const QODBCDriver);
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hDbc); return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hDbc);
} }
QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) const QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) const
{ {
QChar quote = d->quoteChar(); Q_D(const QODBCDriver);
QChar quote = const_cast<QODBCDriverPrivate*>(d)->quoteChar();
QString res = identifier; QString res = identifier;
if(!identifier.isEmpty() && !identifier.startsWith(quote) && !identifier.endsWith(quote) ) { if(!identifier.isEmpty() && !identifier.startsWith(quote) && !identifier.endsWith(quote) ) {
res.replace(quote, QString(quote)+QString(quote)); res.replace(quote, QString(quote)+QString(quote));
@ -2614,7 +2619,8 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType)
bool QODBCDriver::isIdentifierEscaped(const QString &identifier, IdentifierType) const bool QODBCDriver::isIdentifierEscaped(const QString &identifier, IdentifierType) const
{ {
QChar quote = d->quoteChar(); Q_D(const QODBCDriver);
QChar quote = const_cast<QODBCDriverPrivate*>(d)->quoteChar();
return identifier.size() > 2 return identifier.size() > 2
&& identifier.startsWith(quote) //left delimited && identifier.startsWith(quote) //left delimited
&& identifier.endsWith(quote); //right delimited && identifier.endsWith(quote); //right delimited

View File

@ -123,6 +123,7 @@ private:
class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver
{ {
Q_DECLARE_PRIVATE(QODBCDriver)
Q_OBJECT Q_OBJECT
public: public:
explicit QODBCDriver(QObject *parent=0); explicit QODBCDriver(QObject *parent=0);
@ -154,10 +155,8 @@ protected:
bool rollbackTransaction(); bool rollbackTransaction();
private: private:
void init();
bool endTrans(); bool endTrans();
void cleanup(); void cleanup();
QODBCDriverPrivate* d;
friend class QODBCPrivate; friend class QODBCPrivate;
}; };

View File

@ -124,9 +124,9 @@ inline void qPQfreemem(void *buffer)
class QPSQLDriverPrivate : public QSqlDriverPrivate class QPSQLDriverPrivate : public QSqlDriverPrivate
{ {
Q_DECLARE_PUBLIC(QPSQLDriver)
public: public:
QPSQLDriverPrivate(QPSQLDriver *qq) : QSqlDriverPrivate(), QPSQLDriverPrivate() : QSqlDriverPrivate(),
q(qq),
connection(0), connection(0),
isUtf8(false), isUtf8(false),
pro(QPSQLDriver::Version6), pro(QPSQLDriver::Version6),
@ -135,7 +135,6 @@ public:
hasBackslashEscape(false) hasBackslashEscape(false)
{ dbmsType = PostgreSQL; } { dbmsType = PostgreSQL; }
QPSQLDriver *q;
PGconn *connection; PGconn *connection;
bool isUtf8; bool isUtf8;
QPSQLDriver::Protocol pro; QPSQLDriver::Protocol pro;
@ -179,10 +178,11 @@ void QPSQLDriverPrivate::appendTables(QStringList &tl, QSqlQuery &t, QChar type)
PGresult * QPSQLDriverPrivate::exec(const char * stmt) const PGresult * QPSQLDriverPrivate::exec(const char * stmt) const
{ {
Q_Q(const QPSQLDriver);
PGresult *result = PQexec(connection, stmt); PGresult *result = PQexec(connection, stmt);
if (seid.size() && !pendingNotifyCheck) { if (seid.size() && !pendingNotifyCheck) {
pendingNotifyCheck = true; pendingNotifyCheck = true;
QMetaObject::invokeMethod(q, "_q_handleNotification", Qt::QueuedConnection, Q_ARG(int,0)); QMetaObject::invokeMethod(const_cast<QPSQLDriver*>(q), "_q_handleNotification", Qt::QueuedConnection, Q_ARG(int,0));
} }
return result; return result;
} }
@ -205,7 +205,11 @@ public:
QString fieldSerial(int i) const { return QLatin1Char('$') + QString::number(i + 1); } QString fieldSerial(int i) const { return QLatin1Char('$') + QString::number(i + 1); }
void deallocatePreparedStmt(); void deallocatePreparedStmt();
const QPSQLDriverPrivate * privDriver() const {Q_Q(const QPSQLResult); return reinterpret_cast<const QPSQLDriver *>(q->driver())->d; } const QPSQLDriverPrivate * privDriver() const
{
Q_Q(const QPSQLResult);
return reinterpret_cast<const QPSQLDriver *>(q->driver())->d_func();
}
PGresult *result; PGresult *result;
int currentSize; int currentSize;
@ -767,15 +771,14 @@ QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion()
} }
QPSQLDriver::QPSQLDriver(QObject *parent) QPSQLDriver::QPSQLDriver(QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QPSQLDriverPrivate, parent)
{ {
init();
} }
QPSQLDriver::QPSQLDriver(PGconn *conn, QObject *parent) QPSQLDriver::QPSQLDriver(PGconn *conn, QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QPSQLDriverPrivate, parent)
{ {
init(); Q_D(QPSQLDriver);
d->connection = conn; d->connection = conn;
if (conn) { if (conn) {
d->pro = d->getPSQLVersion(); d->pro = d->getPSQLVersion();
@ -785,24 +788,22 @@ QPSQLDriver::QPSQLDriver(PGconn *conn, QObject *parent)
} }
} }
void QPSQLDriver::init()
{
d = new QPSQLDriverPrivate(this);
}
QPSQLDriver::~QPSQLDriver() QPSQLDriver::~QPSQLDriver()
{ {
Q_D(QPSQLDriver);
if (d->connection) if (d->connection)
PQfinish(d->connection); PQfinish(d->connection);
} }
QVariant QPSQLDriver::handle() const QVariant QPSQLDriver::handle() const
{ {
Q_D(const QPSQLDriver);
return QVariant::fromValue(d->connection); return QVariant::fromValue(d->connection);
} }
bool QPSQLDriver::hasFeature(DriverFeature f) const bool QPSQLDriver::hasFeature(DriverFeature f) const
{ {
Q_D(const QPSQLDriver);
switch (f) { switch (f) {
case Transactions: case Transactions:
case QuerySize: case QuerySize:
@ -849,6 +850,7 @@ bool QPSQLDriver::open(const QString & db,
int port, int port,
const QString& connOpts) const QString& connOpts)
{ {
Q_D(QPSQLDriver);
if (isOpen()) if (isOpen())
close(); close();
QString connectString; QString connectString;
@ -891,6 +893,7 @@ bool QPSQLDriver::open(const QString & db,
void QPSQLDriver::close() void QPSQLDriver::close()
{ {
Q_D(QPSQLDriver);
if (isOpen()) { if (isOpen()) {
d->seid.clear(); d->seid.clear();
@ -915,6 +918,7 @@ QSqlResult *QPSQLDriver::createResult() const
bool QPSQLDriver::beginTransaction() bool QPSQLDriver::beginTransaction()
{ {
Q_D(const QPSQLDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QPSQLDriver::beginTransaction: Database not open"); qWarning("QPSQLDriver::beginTransaction: Database not open");
return false; return false;
@ -932,6 +936,7 @@ bool QPSQLDriver::beginTransaction()
bool QPSQLDriver::commitTransaction() bool QPSQLDriver::commitTransaction()
{ {
Q_D(QPSQLDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QPSQLDriver::commitTransaction: Database not open"); qWarning("QPSQLDriver::commitTransaction: Database not open");
return false; return false;
@ -965,6 +970,7 @@ bool QPSQLDriver::commitTransaction()
bool QPSQLDriver::rollbackTransaction() bool QPSQLDriver::rollbackTransaction()
{ {
Q_D(QPSQLDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QPSQLDriver::rollbackTransaction: Database not open"); qWarning("QPSQLDriver::rollbackTransaction: Database not open");
return false; return false;
@ -982,6 +988,7 @@ bool QPSQLDriver::rollbackTransaction()
QStringList QPSQLDriver::tables(QSql::TableType type) const QStringList QPSQLDriver::tables(QSql::TableType type) const
{ {
Q_D(const QPSQLDriver);
QStringList tl; QStringList tl;
if (!isOpen()) if (!isOpen())
return tl; return tl;
@ -989,9 +996,9 @@ QStringList QPSQLDriver::tables(QSql::TableType type) const
t.setForwardOnly(true); t.setForwardOnly(true);
if (type & QSql::Tables) if (type & QSql::Tables)
d->appendTables(tl, t, QLatin1Char('r')); const_cast<QPSQLDriverPrivate*>(d)->appendTables(tl, t, QLatin1Char('r'));
if (type & QSql::Views) if (type & QSql::Views)
d->appendTables(tl, t, QLatin1Char('v')); const_cast<QPSQLDriverPrivate*>(d)->appendTables(tl, t, QLatin1Char('v'));
if (type & QSql::SystemTables) { if (type & QSql::SystemTables) {
t.exec(QLatin1String("select relname from pg_class where (relkind = 'r') " t.exec(QLatin1String("select relname from pg_class where (relkind = 'r') "
"and (relname like 'pg_%') ")); "and (relname like 'pg_%') "));
@ -1013,6 +1020,7 @@ static void qSplitTableName(QString &tablename, QString &schema)
QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const
{ {
Q_D(const QPSQLDriver);
QSqlIndex idx(tablename); QSqlIndex idx(tablename);
if (!isOpen()) if (!isOpen())
return idx; return idx;
@ -1094,6 +1102,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const
QSqlRecord QPSQLDriver::record(const QString& tablename) const QSqlRecord QPSQLDriver::record(const QString& tablename) const
{ {
Q_D(const QPSQLDriver);
QSqlRecord info; QSqlRecord info;
if (!isOpen()) if (!isOpen())
return info; return info;
@ -1231,6 +1240,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const
QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
{ {
Q_D(const QPSQLDriver);
QString r; QString r;
if (field.isNull()) { if (field.isNull()) {
r = QLatin1String("NULL"); r = QLatin1String("NULL");
@ -1326,16 +1336,19 @@ QString QPSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType)
bool QPSQLDriver::isOpen() const bool QPSQLDriver::isOpen() const
{ {
Q_D(const QPSQLDriver);
return PQstatus(d->connection) == CONNECTION_OK; return PQstatus(d->connection) == CONNECTION_OK;
} }
QPSQLDriver::Protocol QPSQLDriver::protocol() const QPSQLDriver::Protocol QPSQLDriver::protocol() const
{ {
Q_D(const QPSQLDriver);
return d->pro; return d->pro;
} }
bool QPSQLDriver::subscribeToNotification(const QString &name) bool QPSQLDriver::subscribeToNotification(const QString &name)
{ {
Q_D(QPSQLDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QPSQLDriver::subscribeToNotificationImplementation: database not open."); qWarning("QPSQLDriver::subscribeToNotificationImplementation: database not open.");
return false; return false;
@ -1373,6 +1386,7 @@ bool QPSQLDriver::subscribeToNotification(const QString &name)
bool QPSQLDriver::unsubscribeFromNotification(const QString &name) bool QPSQLDriver::unsubscribeFromNotification(const QString &name)
{ {
Q_D(QPSQLDriver);
if (!isOpen()) { if (!isOpen()) {
qWarning("QPSQLDriver::unsubscribeFromNotificationImplementation: database not open."); qWarning("QPSQLDriver::unsubscribeFromNotificationImplementation: database not open.");
return false; return false;
@ -1404,11 +1418,13 @@ bool QPSQLDriver::unsubscribeFromNotification(const QString &name)
QStringList QPSQLDriver::subscribedToNotifications() const QStringList QPSQLDriver::subscribedToNotifications() const
{ {
Q_D(const QPSQLDriver);
return d->seid; return d->seid;
} }
void QPSQLDriver::_q_handleNotification(int) void QPSQLDriver::_q_handleNotification(int)
{ {
Q_D(QPSQLDriver);
d->pendingNotifyCheck = false; d->pendingNotifyCheck = false;
PQconsumeInput(d->connection); PQconsumeInput(d->connection);

View File

@ -103,6 +103,7 @@ class QPSQLDriverPrivate;
class Q_EXPORT_SQLDRIVER_PSQL QPSQLDriver : public QSqlDriver class Q_EXPORT_SQLDRIVER_PSQL QPSQLDriver : public QSqlDriver
{ {
friend class QPSQLResultPrivate; friend class QPSQLResultPrivate;
Q_DECLARE_PRIVATE(QPSQLDriver)
Q_OBJECT Q_OBJECT
public: public:
@ -155,10 +156,6 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void _q_handleNotification(int); void _q_handleNotification(int);
private:
void init();
QPSQLDriverPrivate *d;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -346,15 +346,15 @@ QSQLiteResult::QSQLiteResult(const QSQLiteDriver* db)
: QSqlCachedResult(db) : QSqlCachedResult(db)
{ {
d = new QSQLiteResultPrivate(this); d = new QSQLiteResultPrivate(this);
d->access = db->d->access; d->access = db->d_func()->access;
db->d->results.append(this); const_cast<QSQLiteDriverPrivate*>(db->d_func())->results.append(this);
} }
QSQLiteResult::~QSQLiteResult() QSQLiteResult::~QSQLiteResult()
{ {
const QSqlDriver *sqlDriver = driver(); const QSqlDriver *sqlDriver = driver();
if (sqlDriver) if (sqlDriver)
qobject_cast<const QSQLiteDriver *>(sqlDriver)->d->results.removeOne(this); const_cast<QSQLiteDriverPrivate*>(qobject_cast<const QSQLiteDriver *>(sqlDriver)->d_func())->results.removeOne(this);
d->cleanup(); d->cleanup();
delete d; delete d;
} }
@ -530,15 +530,14 @@ QVariant QSQLiteResult::handle() const
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
QSQLiteDriver::QSQLiteDriver(QObject * parent) QSQLiteDriver::QSQLiteDriver(QObject * parent)
: QSqlDriver(parent) : QSqlDriver(*new QSQLiteDriverPrivate, parent)
{ {
d = new QSQLiteDriverPrivate();
} }
QSQLiteDriver::QSQLiteDriver(sqlite3 *connection, QObject *parent) QSQLiteDriver::QSQLiteDriver(sqlite3 *connection, QObject *parent)
: QSqlDriver(parent) : QSqlDriver(*new QSQLiteDriverPrivate, parent)
{ {
d = new QSQLiteDriverPrivate(); Q_D(QSQLiteDriver);
d->access = connection; d->access = connection;
setOpen(true); setOpen(true);
setOpenError(false); setOpenError(false);
@ -579,6 +578,7 @@ bool QSQLiteDriver::hasFeature(DriverFeature f) const
*/ */
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts) bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts)
{ {
Q_D(QSQLiteDriver);
if (isOpen()) if (isOpen())
close(); close();
@ -622,6 +622,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c
void QSQLiteDriver::close() void QSQLiteDriver::close()
{ {
Q_D(QSQLiteDriver);
if (isOpen()) { if (isOpen()) {
foreach (QSQLiteResult *result, d->results) { foreach (QSQLiteResult *result, d->results) {
result->d->finalize(); result->d->finalize();
@ -778,6 +779,7 @@ QSqlRecord QSQLiteDriver::record(const QString &tbl) const
QVariant QSQLiteDriver::handle() const QVariant QSQLiteDriver::handle() const
{ {
Q_D(const QSQLiteDriver);
return QVariant::fromValue(d->access); return QVariant::fromValue(d->access);
} }

View File

@ -71,6 +71,7 @@ class QSQLiteDriver;
class Q_EXPORT_SQLDRIVER_SQLITE QSQLiteDriver : public QSqlDriver class Q_EXPORT_SQLDRIVER_SQLITE QSQLiteDriver : public QSqlDriver
{ {
Q_DECLARE_PRIVATE(QSQLiteDriver)
Q_OBJECT Q_OBJECT
friend class QSQLiteResult; friend class QSQLiteResult;
public: public:
@ -95,9 +96,6 @@ public:
QSqlIndex primaryIndex(const QString &table) const; QSqlIndex primaryIndex(const QString &table) const;
QVariant handle() const; QVariant handle() const;
QString escapeIdentifier(const QString &identifier, IdentifierType) const; QString escapeIdentifier(const QString &identifier, IdentifierType) const;
private:
QSQLiteDriverPrivate* d;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -327,12 +327,12 @@ QTDSResult::QTDSResult(const QTDSDriver* db)
: QSqlCachedResult(db) : QSqlCachedResult(db)
{ {
d = new QTDSResultPrivate(); d = new QTDSResultPrivate();
d->login = db->d->login; d->login = db->d_func()->login;
d->dbproc = dbopen(d->login, const_cast<char*>(db->d->hostName.toLatin1().constData())); d->dbproc = dbopen(d->login, const_cast<char*>(db->d_func()->hostName.toLatin1().constData()));
if (!d->dbproc) if (!d->dbproc)
return; return;
if (dbuse(d->dbproc, const_cast<char*>(db->d->db.toLatin1().constData())) == FAIL) if (dbuse(d->dbproc, const_cast<char*>(db->d_func()->db.toLatin1().constData())) == FAIL)
return; return;
// insert d in error handler dict // insert d in error handler dict
@ -541,14 +541,15 @@ QSqlRecord QTDSResult::record() const
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
QTDSDriver::QTDSDriver(QObject* parent) QTDSDriver::QTDSDriver(QObject* parent)
: QSqlDriver(parent) : QSqlDriver(*new QTDSDriverPrivate, parent)
{ {
init(); init();
} }
QTDSDriver::QTDSDriver(LOGINREC* rec, const QString& host, const QString &db, QObject* parent) QTDSDriver::QTDSDriver(LOGINREC* rec, const QString& host, const QString &db, QObject* parent)
: QSqlDriver(parent) : QSqlDriver(*new QTDSDriverPrivate, parent)
{ {
Q_D(QTDSDriver);
init(); init();
d->login = rec; d->login = rec;
d->hostName = host; d->hostName = host;
@ -561,12 +562,13 @@ QTDSDriver::QTDSDriver(LOGINREC* rec, const QString& host, const QString &db, QO
QVariant QTDSDriver::handle() const QVariant QTDSDriver::handle() const
{ {
Q_D(const QTDSDriver);
return QVariant(qRegisterMetaType<LOGINREC *>("LOGINREC*"), &d->login); return QVariant(qRegisterMetaType<LOGINREC *>("LOGINREC*"), &d->login);
} }
void QTDSDriver::init() void QTDSDriver::init()
{ {
d = new QTDSDriverPrivate(); Q_D(QTDSDriver);
d->initialized = (dbinit() == SUCCEED); d->initialized = (dbinit() == SUCCEED);
// the following two code-lines will fail compilation on some FreeTDS versions // the following two code-lines will fail compilation on some FreeTDS versions
// just comment them out if you have FreeTDS (you won't get any errors and warnings then) // just comment them out if you have FreeTDS (you won't get any errors and warnings then)
@ -606,6 +608,7 @@ bool QTDSDriver::open(const QString & db,
int /*port*/, int /*port*/,
const QString& /*connOpts*/) const QString& /*connOpts*/)
{ {
Q_D(QTDSDriver);
if (isOpen()) if (isOpen())
close(); close();
if (!d->initialized) { if (!d->initialized) {
@ -645,6 +648,7 @@ bool QTDSDriver::open(const QString & db,
void QTDSDriver::close() void QTDSDriver::close()
{ {
Q_D(QTDSDriver);
if (isOpen()) { if (isOpen()) {
#ifdef Q_USE_SYBASE #ifdef Q_USE_SYBASE
dbloginfree(d->login); dbloginfree(d->login);

View File

@ -84,6 +84,7 @@ class QTDSDriver;
class Q_EXPORT_SQLDRIVER_TDS QTDSDriver : public QSqlDriver class Q_EXPORT_SQLDRIVER_TDS QTDSDriver : public QSqlDriver
{ {
Q_DECLARE_PRIVATE(QTDSDriver)
Q_OBJECT Q_OBJECT
friend class QTDSResult; friend class QTDSResult;
public: public:
@ -115,7 +116,6 @@ protected:
bool rollbackTransaction(); bool rollbackTransaction();
private: private:
void init(); void init();
QTDSDriverPrivate *d;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -88,6 +88,13 @@ QSqlDriver::QSqlDriver(QObject *parent)
{ {
} }
/*! \internal
*/
QSqlDriver::QSqlDriver(QSqlDriverPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
}
/*! /*!
Destroys the object and frees any allocated resources. Destroys the object and frees any allocated resources.
*/ */

View File

@ -126,6 +126,7 @@ Q_SIGNALS:
void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload);
protected: protected:
QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = 0);
virtual void setOpen(bool o); virtual void setOpen(bool o);
virtual void setOpenError(bool e); virtual void setOpenError(bool e);
virtual void setLastError(const QSqlError& e); virtual void setLastError(const QSqlError& e);

View File

@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE
class QSqlDriverPrivate : public QObjectPrivate class QSqlDriverPrivate : public QObjectPrivate
{ {
Q_DECLARE_PUBLIC(QSqlDriver)
public: public:
enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase, SQLite, Interbase, DB2}; enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase, SQLite, Interbase, DB2};
@ -72,8 +74,6 @@ public:
dbmsType(UnknownDB) dbmsType(UnknownDB)
{ } { }
// @CHECK: this member is never used. It was named q, which expanded to q_func().
QSqlDriver *q_func();
uint isOpen; uint isOpen;
uint isOpenError; uint isOpenError;
QSqlError error; QSqlError error;