summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/ibase/qsql_ibase.cpp
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2013-04-03 21:44:30 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-04 13:13:37 +0200
commit0bdc86d9ef7be8e27598d245c6ca8026f08aff12 (patch)
tree53d6556f439ebfdd92a5dc24d4dac61daf3f9869 /src/sql/drivers/ibase/qsql_ibase.cpp
parent708d39fa31368f80152440e94e4a361d024b19c1 (diff)
QSqlDriver: use Q_DECLARE_PUBLIC/Q_DECLARE_PRIVATE
406c8ef6e67da 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>
Diffstat (limited to 'src/sql/drivers/ibase/qsql_ibase.cpp')
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp
index 2137514679..bd97db189c 100644
--- a/src/sql/drivers/ibase/qsql_ibase.cpp
+++ b/src/sql/drivers/ibase/qsql_ibase.cpp
@@ -312,11 +312,13 @@ struct QIBaseEventBuffer {
class QIBaseDriverPrivate : public QSqlDriverPrivate
{
+ Q_DECLARE_PUBLIC(QIBaseDriver)
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)
{
+ Q_Q(QIBaseDriver);
QString imsg;
ISC_LONG sqlcode;
if (!getIBaseError(imsg, status, sqlcode, tc))
@@ -328,7 +330,6 @@ public:
}
public:
- QIBaseDriver* q;
isc_db_handle ibase;
isc_tr_handle trans;
QTextCodec *tc;
@@ -418,9 +419,9 @@ public:
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()
@@ -861,9 +862,9 @@ bool QIBaseResultPrivate::transaction()
{
if (trans)
return true;
- if (db->d->trans) {
+ if (db->d_func()->trans) {
localTransaction = false;
- trans = db->d->trans;
+ trans = db->d_func()->trans;
return true;
}
localTransaction = true;
@@ -1396,15 +1397,14 @@ QVariant QIBaseResult::handle() const
/*********************************/
QIBaseDriver::QIBaseDriver(QObject * parent)
- : QSqlDriver(parent)
+ : QSqlDriver(*new QIBaseDriverPrivate, parent)
{
- d = new QIBaseDriverPrivate(this);
}
QIBaseDriver::QIBaseDriver(isc_db_handle connection, QObject *parent)
- : QSqlDriver(parent)
+ : QSqlDriver(*new QIBaseDriverPrivate, parent)
{
- d = new QIBaseDriverPrivate(this);
+ Q_D(QIBaseDriver);
d->ibase = connection;
setOpen(true);
setOpenError(false);
@@ -1444,6 +1444,7 @@ bool QIBaseDriver::open(const QString & db,
int /*port*/,
const QString & connOpts)
{
+ Q_D(QIBaseDriver);
if (isOpen())
close();
@@ -1526,6 +1527,7 @@ bool QIBaseDriver::open(const QString & db,
void QIBaseDriver::close()
{
+ Q_D(QIBaseDriver);
if (isOpen()) {
if (d->eventBuffers.size()) {
@@ -1562,6 +1564,7 @@ QSqlResult *QIBaseDriver::createResult() const
bool QIBaseDriver::beginTransaction()
{
+ Q_D(QIBaseDriver);
if (!isOpen() || isOpenError())
return false;
if (d->trans)
@@ -1574,6 +1577,7 @@ bool QIBaseDriver::beginTransaction()
bool QIBaseDriver::commitTransaction()
{
+ Q_D(QIBaseDriver);
if (!isOpen() || isOpenError())
return false;
if (!d->trans)
@@ -1587,6 +1591,7 @@ bool QIBaseDriver::commitTransaction()
bool QIBaseDriver::rollbackTransaction()
{
+ Q_D(QIBaseDriver);
if (!isOpen() || isOpenError())
return false;
if (!d->trans)
@@ -1749,6 +1754,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons
QVariant QIBaseDriver::handle() const
{
+ Q_D(const QIBaseDriver);
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)
{
+ Q_D(QIBaseDriver);
if (!isOpen()) {
qWarning("QIBaseDriver::subscribeFromNotificationImplementation: database not open.");
return false;
@@ -1826,6 +1833,7 @@ bool QIBaseDriver::subscribeToNotification(const QString &name)
bool QIBaseDriver::unsubscribeFromNotification(const QString &name)
{
+ Q_D(QIBaseDriver);
if (!isOpen()) {
qWarning("QIBaseDriver::unsubscribeFromNotificationImplementation: database not open.");
return false;
@@ -1855,11 +1863,13 @@ bool QIBaseDriver::unsubscribeFromNotification(const QString &name)
QStringList QIBaseDriver::subscribedToNotifications() const
{
+ Q_D(const QIBaseDriver);
return QStringList(d->eventBuffers.keys());
}
void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer)
{
+ Q_D(QIBaseDriver);
QMap<QString, QIBaseEventBuffer *>::const_iterator i;
for (i = d->eventBuffers.constBegin(); i != d->eventBuffers.constEnd(); ++i) {
QIBaseEventBuffer* eBuffer = i.value();