diff options
Diffstat (limited to 'src/sql/kernel/qsqlresult.cpp')
-rw-r--r-- | src/sql/kernel/qsqlresult.cpp | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index 1b7daa8d0f..59e9879cf0 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -37,6 +37,9 @@ static bool qIsAlnum(QChar ch) QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const { + if (!positionalBindingEnabled) + return query; + const qsizetype n = query.size(); QString result; @@ -92,6 +95,7 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) int count = 0; qsizetype i = 0; bool ignoreBraces = (sqldriver->dbmsType() == QSqlDriver::PostgreSQL); + const bool qmarkNotationSupported = (sqldriver->dbmsType() != QSqlDriver::PostgreSQL); while (i < n) { QChar ch = query.at(i); @@ -115,10 +119,16 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) int pos = i + 2; while (pos < n && qIsAlnum(query.at(pos))) ++pos; + // if question mark notation is not supported we have to use + // the native binding. fieldSerial() should be renamed + // to toNativeBinding() and used unconditionally here + if (qmarkNotationSupported) + result += u'?'; + else + result += fieldSerial(count); QString holder(query.mid(i, pos - i)); indexes[holder].append(count++); holders.append(QHolder(holder, i)); - result += u'?'; i = pos; } else { if (ch == u'\'' || ch == u'"' || ch == u'`') @@ -784,17 +794,32 @@ int QSqlResult::boundValueCount() const } /*! - Returns a vector of the result's bound values for the current + Returns a list of the result's bound values for the current record (row). \sa boundValueCount() */ -QList<QVariant> &QSqlResult::boundValues() const +QVariantList QSqlResult::boundValues(QT6_IMPL_NEW_OVERLOAD) const { Q_D(const QSqlResult); - return const_cast<QSqlResultPrivate *>(d)->values; + return d->values; +} + +/*! + \overload + + Returns a mutable reference to the list of the result's bound values + for the current record (row). + + \sa boundValueCount() +*/ +QVariantList &QSqlResult::boundValues(QT6_IMPL_NEW_OVERLOAD) +{ + Q_D(QSqlResult); + return d->values; } + /*! Returns the binding syntax used by prepared queries. */ @@ -921,8 +946,6 @@ void QSqlResult::virtual_hook(int, void *) } /*! \internal - \since 4.2 - Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch execution using bindValue() and exec(). QSqlDriver::hasFeature() can be used to find out whether a driver @@ -990,6 +1013,23 @@ QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy() const } /*! \internal + */ +void QSqlResult::setPositionalBindingEnabled(bool enable) +{ + Q_D(QSqlResult); + d->positionalBindingEnabled = enable; +} + +/*! \internal + */ +bool QSqlResult::isPositionalBindingEnabled() const +{ + Q_D(const QSqlResult); + return d->positionalBindingEnabled; +} + + +/*! \internal */ bool QSqlResult::nextResult() { |