QSqlDriver functions made virtual

Certain QSqlDriver functions were marked to be made virtual in Qt5.
subscribeToNotification, unsubscribeFromNotification,
subscribedToNotifications, isIdentifierEscaped, and stripDelimiters.

This patch makes them virtual and removes the no longer needed
Implementation counterpart functions. It also updates the relevant
drivers. This patch has no regressions on the tests in
tests/auto/sql/kernel/, tested with sqlite and postgres.

Change-Id: Ia2e1c18dfb803531523a456eb4e710031048e594
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
Matt Newell 2012-03-22 13:27:26 -07:00 committed by Qt by Nokia
parent 6aded68111
commit ccf25f1d28
11 changed files with 58 additions and 207 deletions

10
dist/changes-5.0.0 vendored
View File

@ -248,6 +248,10 @@ information about a particular change.
- QSqlQueryModel::indexInQuery() is now virtual. See note below under QSql.
- QSqlDriver::subscribeToNotification, unsubscribeFromNotification,
subscribedToNotifications, isIdentifierEscaped, and stripDelimiters
are now virtual. See note below under QtSql.
- qMacVersion() has been removed. Use QSysInfo::macVersion() or
QSysInfo::MacintoshVersion instead.
@ -488,6 +492,12 @@ changes. insertRows() and insertRecord() also respect the edit strategy.
* QSqlTableModel::setData() and setRecord() in OnRowChange no longer have the
side effect of submitting the cached row when invoked on a different row.
* QSqlDriver::subscribeToNotification, unsubscribeFromNotification,
subscribedToNotifications, isIdentifierEscaped, and stripDelimiters
are now virtual. Their xxxImplemenation counterparts have been removed
now that QSqlDriver subclasses can reimplement these directly.
****************************************************************************
* Database Drivers *
****************************************************************************

View File

@ -1749,7 +1749,7 @@ static isc_callback qEventCallback(char *result, short length, char *updated)
return 0;
}
bool QIBaseDriver::subscribeToNotificationImplementation(const QString &name)
bool QIBaseDriver::subscribeToNotification(const QString &name)
{
if (!isOpen()) {
qWarning("QIBaseDriver::subscribeFromNotificationImplementation: database not open.");
@ -1798,7 +1798,7 @@ bool QIBaseDriver::subscribeToNotificationImplementation(const QString &name)
return true;
}
bool QIBaseDriver::unsubscribeFromNotificationImplementation(const QString &name)
bool QIBaseDriver::unsubscribeFromNotification(const QString &name)
{
if (!isOpen()) {
qWarning("QIBaseDriver::unsubscribeFromNotificationImplementation: database not open.");
@ -1827,7 +1827,7 @@ bool QIBaseDriver::unsubscribeFromNotificationImplementation(const QString &name
return true;
}
QStringList QIBaseDriver::subscribedToNotificationsImplementation() const
QStringList QIBaseDriver::subscribedToNotifications() const
{
return QStringList(d->eventBuffers.keys());
}

View File

@ -113,10 +113,9 @@ public:
QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
protected Q_SLOTS:
bool subscribeToNotificationImplementation(const QString &name);
bool unsubscribeFromNotificationImplementation(const QString &name);
QStringList subscribedToNotificationsImplementation() const;
bool subscribeToNotification(const QString &name);
bool unsubscribeFromNotification(const QString &name);
QStringList subscribedToNotifications() const;
private Q_SLOTS:
void qHandleEventNotification(void* updatedResultBuffer);

View File

@ -1534,7 +1534,7 @@ QString QMYSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType
return res;
}
bool QMYSQLDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const
bool QMYSQLDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const
{
Q_UNUSED(type);
return identifier.size() > 2

View File

@ -124,8 +124,7 @@ public:
QVariant handle() const;
QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
protected Q_SLOTS:
bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const;
protected:
bool beginTransaction();

View File

@ -2540,7 +2540,7 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType)
return res;
}
bool QODBCDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType) const
bool QODBCDriver::isIdentifierEscaped(const QString &identifier, IdentifierType) const
{
QChar quote = d->quoteChar();
return identifier.size() > 2

View File

@ -135,8 +135,7 @@ public:
QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
protected Q_SLOTS:
bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const;
protected:
bool beginTransaction();

View File

@ -1283,7 +1283,7 @@ QPSQLDriver::Protocol QPSQLDriver::protocol() const
return d->pro;
}
bool QPSQLDriver::subscribeToNotificationImplementation(const QString &name)
bool QPSQLDriver::subscribeToNotification(const QString &name)
{
if (!isOpen()) {
qWarning("QPSQLDriver::subscribeToNotificationImplementation: database not open.");
@ -1317,7 +1317,7 @@ bool QPSQLDriver::subscribeToNotificationImplementation(const QString &name)
return true;
}
bool QPSQLDriver::unsubscribeFromNotificationImplementation(const QString &name)
bool QPSQLDriver::unsubscribeFromNotification(const QString &name)
{
if (!isOpen()) {
qWarning("QPSQLDriver::unsubscribeFromNotificationImplementation: database not open.");
@ -1350,7 +1350,7 @@ bool QPSQLDriver::unsubscribeFromNotificationImplementation(const QString &name)
return true;
}
QStringList QPSQLDriver::subscribedToNotificationsImplementation() const
QStringList QPSQLDriver::subscribedToNotifications() const
{
return d->seid;
}

View File

@ -134,16 +134,15 @@ public:
QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
QString formatValue(const QSqlField &field, bool trimStrings) const;
bool subscribeToNotification(const QString &name);
bool unsubscribeFromNotification(const QString &name);
QStringList subscribedToNotifications() const;
protected:
bool beginTransaction();
bool commitTransaction();
bool rollbackTransaction();
protected Q_SLOTS:
bool subscribeToNotificationImplementation(const QString &name);
bool unsubscribeFromNotificationImplementation(const QString &name);
QStringList subscribedToNotificationsImplementation() const;
private Q_SLOTS:
void _q_handleNotification(int);

View File

@ -417,22 +417,17 @@ QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType)
\a identifier can either be a table name or field name, dependent
on \a type.
\warning Because of binary compatibility constraints, this function is not virtual.
If you want to provide your own implementation in your QSqlDriver subclass,
reimplement the isIdentifierEscapedImplementation() slot in your subclass instead.
The isIdentifierEscapedFunction() will dynamically detect the slot and call it.
Reimplement this function if you want to provide your own implementation in your
QSqlDriver subclass,
\sa stripDelimiters(), escapeIdentifier()
*/
bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const
{
bool result;
QMetaObject::invokeMethod(const_cast<QSqlDriver*>(this),
"isIdentifierEscapedImplementation", Qt::DirectConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(QString, identifier),
Q_ARG(IdentifierType, type));
return result;
Q_UNUSED(type);
return identifier.size() > 2
&& identifier.startsWith(QLatin1Char('"')) //left delimited
&& identifier.endsWith(QLatin1Char('"')); //right delimited
}
/*!
@ -442,23 +437,22 @@ bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType t
and trailing delimiter characters, \a identifier is returned without
modification.
\warning Because of binary compatibility constraints, this function is not virtual,
If you want to provide your own implementation in your QSqlDriver subclass,
reimplement the stripDelimitersImplementation() slot in your subclass instead.
The stripDelimiters() function will dynamically detect the slot and call it.
Reimplement this function if you want to provide your own implementation in your
QSqlDriver subclass,
\since 4.5
\sa isIdentifierEscaped()
*/
QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const
{
QString result;
QMetaObject::invokeMethod(const_cast<QSqlDriver*>(this),
"stripDelimitersImplementation", Qt::DirectConnection,
Q_RETURN_ARG(QString, result),
Q_ARG(QString, identifier),
Q_ARG(IdentifierType, type));
return result;
QString ret;
if (isIdentifierEscaped(identifier, type)) {
ret = identifier.mid(1);
ret.chop(1);
} else {
ret = identifier;
}
return ret;
}
/*!
@ -744,22 +738,16 @@ QVariant QSqlDriver::handle() const
When an event notification identified by \a name is posted by the database the
notification() signal is emitted.
\warning Because of binary compatibility constraints, this function is not virtual.
If you want to provide event notification support in your own QSqlDriver subclass,
reimplement the subscribeToNotificationImplementation() slot in your subclass instead.
The subscribeToNotification() function will dynamically detect the slot and call it.
Reimplement this function if you want to provide event notification support in your
own QSqlDriver subclass,
\since 4.4
\sa unsubscribeFromNotification() subscribedToNotifications() QSqlDriver::hasFeature()
*/
bool QSqlDriver::subscribeToNotification(const QString &name)
{
bool result;
QMetaObject::invokeMethod(const_cast<QSqlDriver *>(this),
"subscribeToNotificationImplementation", Qt::DirectConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(QString, name));
return result;
Q_UNUSED(name);
return false;
}
/*!
@ -774,168 +762,32 @@ bool QSqlDriver::subscribeToNotification(const QString &name)
After calling \e this function the notification() signal will no longer be emitted
when an event notification identified by \a name is posted by the database.
\warning Because of binary compatibility constraints, this function is not virtual.
If you want to provide event notification support in your own QSqlDriver subclass,
reimplement the unsubscribeFromNotificationImplementation() slot in your subclass instead.
The unsubscribeFromNotification() function will dynamically detect the slot and call it.
Reimplement this function if you want to provide event notification support in your
own QSqlDriver subclass,
\since 4.4
\sa subscribeToNotification() subscribedToNotifications()
*/
bool QSqlDriver::unsubscribeFromNotification(const QString &name)
{
bool result;
QMetaObject::invokeMethod(const_cast<QSqlDriver *>(this),
"unsubscribeFromNotificationImplementation", Qt::DirectConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(QString, name));
return result;
Q_UNUSED(name);
return false;
}
/*!
Returns a list of the names of the event notifications that are currently subscribed to.
\warning Because of binary compatibility constraints, this function is not virtual.
If you want to provide event notification support in your own QSqlDriver subclass,
reimplement the subscribedToNotificationsImplementation() slot in your subclass instead.
The subscribedToNotifications() function will dynamically detect the slot and call it.
Reimplement this function if you want to provide event notification support in your
own QSqlDriver subclass,
\since 4.4
\sa subscribeToNotification() unsubscribeFromNotification()
*/
QStringList QSqlDriver::subscribedToNotifications() const
{
QStringList result;
QMetaObject::invokeMethod(const_cast<QSqlDriver *>(this),
"subscribedToNotificationsImplementation", Qt::DirectConnection,
Q_RETURN_ARG(QStringList, result));
return result;
}
/*!
This slot is called to subscribe to event notifications from the database.
\a name identifies the event notification.
If successful, return true, otherwise return false.
The database must be open when this \e slot is called. When the database is closed
by calling close() all subscribed event notifications are automatically unsubscribed.
Note that calling open() on an already open database may implicitly cause close() to
be called, which will cause the driver to unsubscribe from all event notifications.
When an event notification identified by \a name is posted by the database the
notification() signal is emitted.
Reimplement this slot to provide your own QSqlDriver subclass with event notification
support; because of binary compatibility constraints, the subscribeToNotification()
function (introduced in Qt 4.4) is not virtual. Instead, subscribeToNotification()
will dynamically detect and call \e this slot. The default implementation does nothing
and returns false.
\since 4.4
\sa subscribeToNotification()
*/
bool QSqlDriver::subscribeToNotificationImplementation(const QString &name)
{
Q_UNUSED(name);
return false;
}
/*!
This slot is called to unsubscribe from event notifications from the database.
\a name identifies the event notification.
If successful, return true, otherwise return false.
The database must be open when \e this slot is called. All subscribed event
notifications are automatically unsubscribed from when the close() function is called.
After calling \e this slot the notification() signal will no longer be emitted
when an event notification identified by \a name is posted by the database.
Reimplement this slot to provide your own QSqlDriver subclass with event notification
support; because of binary compatibility constraints, the unsubscribeFromNotification()
function (introduced in Qt 4.4) is not virtual. Instead, unsubscribeFromNotification()
will dynamically detect and call \e this slot. The default implementation does nothing
and returns false.
\since 4.4
\sa unsubscribeFromNotification()
*/
bool QSqlDriver::unsubscribeFromNotificationImplementation(const QString &name)
{
Q_UNUSED(name);
return false;
}
/*!
Returns a list of the names of the event notifications that are currently subscribed to.
Reimplement this slot to provide your own QSqlDriver subclass with event notification
support; because of binary compatibility constraints, the subscribedToNotifications()
function (introduced in Qt 4.4) is not virtual. Instead, subscribedToNotifications()
will dynamically detect and call \e this slot. The default implementation simply
returns an empty QStringList.
\since 4.4
\sa subscribedToNotifications()
*/
QStringList QSqlDriver::subscribedToNotificationsImplementation() const
{
return QStringList();
}
/*!
\since 4.6
This slot returns whether \a identifier is escaped according to the database rules.
\a identifier can either be a table name or field name, dependent
on \a type.
Because of binary compatibility constraints, isIdentifierEscaped() function
(introduced in Qt 4.5) is not virtual. Instead, isIdentifierEscaped() will
dynamically detect and call \e this slot. The default implementation
assumes the escape/delimiter character is a double quote. Reimplement this
slot in your own QSqlDriver if your database engine uses a different
delimiter character.
\sa isIdentifierEscaped()
*/
bool QSqlDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const
{
Q_UNUSED(type);
return identifier.size() > 2
&& identifier.startsWith(QLatin1Char('"')) //left delimited
&& identifier.endsWith(QLatin1Char('"')); //right delimited
}
/*!
\since 4.6
This slot returns \a identifier with the leading and trailing delimiters removed,
\a identifier can either be a tablename or field name, dependent on \a type.
If \a identifier does not have leading and trailing delimiter characters, \a
identifier is returned without modification.
Because of binary compatibility constraints, the stripDelimiters() function
(introduced in Qt 4.5) is not virtual. Instead, stripDelimiters() will
dynamically detect and call \e this slot. It generally unnecessary
to reimplement this slot.
\sa stripDelimiters()
*/
QString QSqlDriver::stripDelimitersImplementation(const QString &identifier, IdentifierType type) const
{
QString ret;
if (this->isIdentifierEscaped(identifier, type)) {
ret = identifier.mid(1);
ret.chop(1);
} else {
ret = identifier;
}
return ret;
}
/*!
\since 4.6

View File

@ -110,12 +110,12 @@ public:
const QString& host = QString(),
int port = -1,
const QString& connOpts = QString()) = 0;
bool subscribeToNotification(const QString &name); // ### Qt 5: make virtual
bool unsubscribeFromNotification(const QString &name); // ### Qt 5: make virtual
QStringList subscribedToNotifications() const; // ### Qt 5: make virtual
virtual bool subscribeToNotification(const QString &name);
virtual bool unsubscribeFromNotification(const QString &name);
virtual QStringList subscribedToNotifications() const;
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; // ### Qt 5: make virtual
QString stripDelimiters(const QString &identifier, IdentifierType type) const; // ### Qt 5: make virtual
virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const;
virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const;
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
@ -129,13 +129,6 @@ protected:
virtual void setOpenError(bool e);
virtual void setLastError(const QSqlError& e);
protected Q_SLOTS:
bool subscribeToNotificationImplementation(const QString &name); // ### Qt 5: eliminate, see subscribeToNotification()
bool unsubscribeFromNotificationImplementation(const QString &name); // ### Qt 5: eliminate, see unsubscribeFromNotification()
QStringList subscribedToNotificationsImplementation() const; // ### Qt 5: eliminate, see subscribedNotifications()
bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; // ### Qt 5: eliminate, see isIdentifierEscaped()
QString stripDelimitersImplementation(const QString &identifier, IdentifierType type) const; // ### Qt 5: eliminate, see stripDelimiters()
private:
Q_DISABLE_COPY(QSqlDriver)