summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/oci/qsql_oci.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sqldrivers/oci/qsql_oci.cpp')
-rw-r--r--src/plugins/sqldrivers/oci/qsql_oci.cpp330
1 files changed, 151 insertions, 179 deletions
diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp
index 324e502f8c..68e303490d 100644
--- a/src/plugins/sqldrivers/oci/qsql_oci.cpp
+++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsql_oci_p.h"
@@ -43,6 +7,7 @@
#include <qdatetime.h>
#include <qdebug.h>
#include <qlist.h>
+#include <qloggingcategory.h>
#include <qmetatype.h>
#if QT_CONFIG(regularexpression)
#include <qregularexpression.h>
@@ -55,7 +20,9 @@
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
#include <qstringlist.h>
+#if QT_CONFIG(timezone)
#include <qtimezone.h>
+#endif
#include <qvariant.h>
#include <qvarlengtharray.h>
@@ -64,14 +31,7 @@
#define _int64 __int64
#endif
-
#include <oci.h>
-#ifdef max
-#undef max
-#endif
-#ifdef min
-#undef min
-#endif
#include <stdlib.h>
@@ -92,6 +52,10 @@ Q_DECLARE_METATYPE(OCIStmt*)
QT_BEGIN_NAMESPACE
+static Q_LOGGING_CATEGORY(lcOci, "qt.sql.oci")
+
+using namespace Qt::StringLiterals;
+
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
enum { QOCIEncoding = 2002 }; // AL16UTF16LE
#else
@@ -172,8 +136,8 @@ QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt)
if (dt.isValid()) {
const QDate date = dt.date();
const QTime time = dt.time();
- // Zone in +hh:mm format (stripping UTC prefix from OffsetName)
- QString timeZone = dt.timeZone().displayName(dt, QTimeZone::OffsetName).mid(3);
+ // Zone in +hh:mm format
+ const QString timeZone = dt.toString("ttt"_L1);
const OraText *tz = reinterpret_cast<const OraText *>(timeZone.utf16());
OCIDateTimeConstruct(env, err, dateTime, date.year(), date.month(), date.day(), time.hour(),
time.minute(), time.second(), time.msec() * 1000000,
@@ -202,7 +166,7 @@ QDateTime QOCIDateTime::fromOCIDateTime(OCIEnv *env, OCIError *err, OCIDateTime
secondsOffset = -secondsOffset;
// OCIDateTimeGetTime gives "fractions of second" as nanoseconds
return QDateTime(QDate(year, month, day), QTime(hour, minute, second, nsec / 1000000),
- Qt::OffsetFromUTC, secondsOffset);
+ QTimeZone::fromSecondsAheadOfUtc(secondsOffset));
}
struct TempStorage {
@@ -228,6 +192,7 @@ public:
OCISession *authp = nullptr;
OCITrans *trans = nullptr;
OCIError *err = nullptr;
+ ub4 authMode = OCI_DEFAULT;
bool transaction = false;
int serverVersion = -1;
int prefetchRows = -1;
@@ -311,7 +276,7 @@ public:
0);
#ifdef QOCI_DEBUG
if (r != 0)
- qWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM.");
+ qCWarning(lcOci, "QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM.");
#endif
#endif
@@ -458,6 +423,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in
break;
}
} // fall through for OUT values
+ Q_FALLTHROUGH();
default: {
if (val.typeId() >= QMetaType::User) {
if (val.canConvert<QOCIRowIdPointer>() && !isOutValue(pos)) {
@@ -470,7 +436,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in
-1,
SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
} else {
- qWarning("Unknown bind variable");
+ qCWarning(lcOci, "Unknown bind variable");
r = OCI_ERROR;
}
} else {
@@ -586,7 +552,7 @@ void QOCIDriverPrivate::allocErrorHandle()
OCI_HTYPE_ERROR,
0, nullptr);
if (r != OCI_SUCCESS)
- qWarning("QOCIDriver: unable to allocate error handle");
+ qCWarning(lcOci, "QOCIDriver: unable to allocate error handle");
}
struct OraFieldInfo
@@ -622,12 +588,7 @@ QString qOraWarn(OCIError *err, int *errorCode)
void qOraWarning(const char* msg, OCIError *err)
{
-#ifdef QOCI_DEBUG
- qWarning("%s %s", msg, qPrintable(qOraWarn(err)));
-#else
- Q_UNUSED(msg);
- Q_UNUSED(err);
-#endif
+ qCWarning(lcOci, "%s %ls", msg, qUtf16Printable(qOraWarn(err)));
}
static int qOraErrorNumber(OCIError *err)
@@ -654,15 +615,15 @@ QSqlError qMakeError(const QString& errString, QSqlError::ErrorType type, OCIErr
QMetaType qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy precisionPolicy)
{
int type = QMetaType::UnknownType;
- if (ocitype == QLatin1String("VARCHAR2") || ocitype == QLatin1String("VARCHAR")
- || ocitype.startsWith(QLatin1String("INTERVAL"))
- || ocitype == QLatin1String("CHAR") || ocitype == QLatin1String("NVARCHAR2")
- || ocitype == QLatin1String("NCHAR"))
+ if (ocitype == "VARCHAR2"_L1 || ocitype == "VARCHAR"_L1
+ || ocitype.startsWith("INTERVAL"_L1)
+ || ocitype == "CHAR"_L1 || ocitype == "NVARCHAR2"_L1
+ || ocitype == "NCHAR"_L1)
type = QMetaType::QString;
- else if (ocitype == QLatin1String("NUMBER")
- || ocitype == QLatin1String("FLOAT")
- || ocitype == QLatin1String("BINARY_FLOAT")
- || ocitype == QLatin1String("BINARY_DOUBLE")) {
+ else if (ocitype == "NUMBER"_L1
+ || ocitype == "FLOAT"_L1
+ || ocitype == "BINARY_FLOAT"_L1
+ || ocitype == "BINARY_DOUBLE"_L1) {
switch(precisionPolicy) {
case QSql::LowPrecisionInt32:
type = QMetaType::Int;
@@ -679,19 +640,18 @@ QMetaType qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy
break;
}
}
- else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB")
- || ocitype == QLatin1String("CLOB"))
+ else if (ocitype == "LONG"_L1 || ocitype == "NCLOB"_L1 || ocitype == "CLOB"_L1)
type = QMetaType::QByteArray;
- else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW")
- || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB")
- || ocitype == QLatin1String("CFILE") || ocitype == QLatin1String("BFILE"))
+ else if (ocitype == "RAW"_L1 || ocitype == "LONG RAW"_L1
+ || ocitype == "ROWID"_L1 || ocitype == "BLOB"_L1
+ || ocitype == "CFILE"_L1 || ocitype == "BFILE"_L1)
type = QMetaType::QByteArray;
- else if (ocitype == QLatin1String("DATE") || ocitype.startsWith(QLatin1String("TIME")))
+ else if (ocitype == "DATE"_L1 || ocitype.startsWith("TIME"_L1))
type = QMetaType::QDateTime;
- else if (ocitype == QLatin1String("UNDEFINED"))
+ else if (ocitype == "UNDEFINED"_L1)
type = QMetaType::UnknownType;
if (type == QMetaType::UnknownType)
- qWarning("qDecodeOCIType: unknown type: %s", ocitype.toLocal8Bit().constData());
+ qCWarning(lcOci, "qDecodeOCIType: unknown type: %ls", qUtf16Printable(ocitype));
return QMetaType(type);
}
@@ -759,7 +719,7 @@ QMetaType qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precisionPo
type = QMetaType::QDateTime;
break;
default:
- qWarning("qDecodeOCIType: unknown OCI datatype: %d", ocitype);
+ qCWarning(lcOci, "qDecodeOCIType: unknown OCI datatype: %d", ocitype);
break;
}
return QMetaType(type);
@@ -776,7 +736,6 @@ static QSqlField qFromOraInf(const OraFieldInfo &ofi)
f.setLength(ofi.oraPrecision == 0 ? 38 : int(ofi.oraPrecision));
f.setPrecision(ofi.oraScale);
- f.setSqlType(int(ofi.oraType));
return f;
}
@@ -875,7 +834,7 @@ QOCICols::OraFieldInf::~OraFieldInf()
if (lob) {
int r = OCIDescriptorFree(lob, OCI_DTYPE_LOB);
if (r != 0)
- qWarning("QOCICols: Cannot free LOB descriptor");
+ qCWarning(lcOci, "QOCICols: Cannot free LOB descriptor");
}
if (dataPtr) {
switch (typ.id()) {
@@ -884,7 +843,7 @@ QOCICols::OraFieldInf::~OraFieldInf()
case QMetaType::QDateTime: {
int r = OCIDescriptorFree(dataPtr, OCI_DTYPE_TIMESTAMP_TZ);
if (r != OCI_SUCCESS)
- qWarning("QOCICols: Cannot free OCIDateTime descriptor");
+ qCWarning(lcOci, "QOCICols: Cannot free OCIDateTime descriptor");
break;
}
default:
@@ -939,7 +898,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp)
case QMetaType::QDateTime:
r = OCIDescriptorAlloc(d->env, (void **)&fieldInf[idx].dataPtr, OCI_DTYPE_TIMESTAMP_TZ, 0, 0);
if (r != OCI_SUCCESS) {
- qWarning("QOCICols: Unable to allocate the OCIDateTime descriptor");
+ qCWarning(lcOci, "QOCICols: Unable to allocate the OCIDateTime descriptor");
break;
}
r = OCIDefineByPos(d->sql,
@@ -1110,7 +1069,7 @@ OCILobLocator **QOCICols::createLobLocator(int position, OCIEnv* env)
0,
0);
if (r != 0) {
- qWarning("QOCICols: Cannot create LOB locator");
+ qCWarning(lcOci, "QOCICols: Cannot create LOB locator");
lob = 0;
}
return &lob;
@@ -1348,7 +1307,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
return false;
#ifdef QOCI_DEBUG
- qDebug() << "columnCount:" << columnCount << boundValues;
+ qCDebug(lcOci) << "columnCount:" << columnCount << boundValues;
#endif
int i;
@@ -1467,7 +1426,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
// we may now populate column with data
for (uint row = 0; row < col.recordCount; ++row) {
- const QVariant &val = boundValues.at(i).toList().at(row);
+ const QVariant val = boundValues.at(i).toList().at(row);
if (QSqlResultPrivate::isVariantNull(val) && !d->isOutValue(i)) {
columns[i].indicators[row] = -1;
@@ -1545,13 +1504,13 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
QOCIBatchColumn &bindColumn = columns[i];
#ifdef QOCI_DEBUG
- qDebug("OCIBindByPos(%p, %p, %p, %d, %p, %d, %d, %p, %p, 0, %d, %p, OCI_DEFAULT)",
+ qCDebug(lcOci, "OCIBindByPos(%p, %p, %p, %d, %p, %d, %d, %p, %p, 0, %d, %p, OCI_DEFAULT)",
d->sql, &bindColumn.bindh, d->err, i + 1, bindColumn.data,
bindColumn.maxLen, bindColumn.bindAs, bindColumn.indicators, bindColumn.lengths,
arrayBind ? bindColumn.maxarr_len : 0, arrayBind ? &bindColumn.curelep : 0);
for (int ii = 0; ii < (int)bindColumn.recordCount; ++ii) {
- qDebug(" record %d: indicator %d, length %d", ii, bindColumn.indicators[ii],
+ qCDebug(lcOci, " record %d: indicator %d, length %d", ii, bindColumn.indicators[ii],
bindColumn.lengths[ii]);
}
#endif
@@ -1571,7 +1530,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
OCI_DEFAULT);
#ifdef QOCI_DEBUG
- qDebug("After OCIBindByPos: r = %d, bindh = %p", r, bindColumn.bindh);
+ qCDebug(lcOci, "After OCIBindByPos: r = %d, bindh = %p", r, bindColumn.bindh);
#endif
if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
@@ -1598,7 +1557,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
}
}
- //finaly we can execute
+ //finally we can execute
r = OCIStmtExecute(d->svc, d->sql, d->err,
arrayBind ? 1 : columns[0].recordCount,
0, NULL, NULL,
@@ -1831,7 +1790,7 @@ void QOCICols::getValues(QVariantList &v, int index)
v[index + i] = QVariant(QMetaType(QMetaType::QByteArray));
break;
default:
- qWarning("QOCICols::value: unknown data type");
+ qCWarning(lcOci, "QOCICols::value: unknown data type");
break;
}
}
@@ -1852,7 +1811,7 @@ QOCIResultPrivate::QOCIResultPrivate(QOCIResult *q, const QOCIDriver *drv)
OCI_HTYPE_ERROR,
0, nullptr);
if (r != OCI_SUCCESS)
- qWarning("QOCIResult: unable to alloc error handle");
+ qCWarning(lcOci, "QOCIResult: unable to alloc error handle");
}
QOCIResultPrivate::~QOCIResultPrivate()
@@ -1860,10 +1819,10 @@ QOCIResultPrivate::~QOCIResultPrivate()
delete cols;
if (sql && OCIHandleFree(sql, OCI_HTYPE_STMT) != OCI_SUCCESS)
- qWarning("~QOCIResult: unable to free statement handle");
+ qCWarning(lcOci, "~QOCIResult: unable to free statement handle");
if (OCIHandleFree(err, OCI_HTYPE_ERROR) != OCI_SUCCESS)
- qWarning("~QOCIResult: unable to free error report handle");
+ qCWarning(lcOci, "~QOCIResult: unable to free error report handle");
}
@@ -1920,7 +1879,7 @@ bool QOCIResult::gotoNext(QSqlCachedResult::ValueCache &values, int index)
break;
case OCI_ERROR:
if (qOraErrorNumber(d->err) == 1406) {
- qWarning("QOCI Warning: data truncated for %s", lastQuery().toLocal8Bit().constData());
+ qCWarning(lcOci, "QOCI Warning: data truncated for %ls", qUtf16Printable(lastQuery()));
r = OCI_SUCCESS; /* ignore it */
break;
}
@@ -2034,7 +1993,7 @@ bool QOCIResult::exec()
setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
"Unable to get statement type"), QSqlError::StatementError, d->err));
#ifdef QOCI_DEBUG
- qDebug() << "lastQuery()" << lastQuery();
+ qCDebug(lcOci) << "lastQuery()" << lastQuery();
#endif
return false;
}
@@ -2049,7 +2008,7 @@ bool QOCIResult::exec()
setLastError(qMakeError(QCoreApplication::translate("QOCIResult", "Unable to bind value"),
QSqlError::StatementError, d->err));
#ifdef QOCI_DEBUG
- qDebug() << "lastQuery()" << lastQuery();
+ qCDebug(lcOci) << "lastQuery()" << lastQuery();
#endif
return false;
}
@@ -2068,7 +2027,7 @@ bool QOCIResult::exec()
setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
"Unable to execute statement"), QSqlError::StatementError, d->err));
#ifdef QOCI_DEBUG
- qDebug() << "lastQuery()" << lastQuery();
+ qCDebug(lcOci) << "lastQuery()" << lastQuery();
#endif
return false;
}
@@ -2160,7 +2119,7 @@ QOCIDriver::QOCIDriver(QObject* parent)
0,
NULL);
if (r != 0) {
- qWarning("QOCIDriver: unable to create environment");
+ qCWarning(lcOci, "QOCIDriver: unable to create environment");
setLastError(qMakeError(tr("Unable to initialize", "QOCIDriver"),
QSqlError::ConnectionError, d->err));
return;
@@ -2191,10 +2150,10 @@ QOCIDriver::~QOCIDriver()
close();
int r = OCIHandleFree(d->err, OCI_HTYPE_ERROR);
if (r != OCI_SUCCESS)
- qWarning("Unable to free Error handle: %d", r);
+ qCWarning(lcOci, "Unable to free Error handle: %d", r);
r = OCIHandleFree(d->env, OCI_HTYPE_ENV);
if (r != OCI_SUCCESS)
- qWarning("Unable to free Environment handle: %d", r);
+ qCWarning(lcOci, "Unable to free Environment handle: %d", r);
}
bool QOCIDriver::hasFeature(DriverFeature f) const
@@ -2225,29 +2184,37 @@ bool QOCIDriver::hasFeature(DriverFeature f) const
static void qParseOpts(const QString &options, QOCIDriverPrivate *d)
{
- const QStringList opts(options.split(QLatin1Char(';'), Qt::SkipEmptyParts));
- for (int i = 0; i < opts.count(); ++i) {
- const QString tmp(opts.at(i));
- int idx;
- if ((idx = tmp.indexOf(QLatin1Char('='))) == -1) {
- qWarning("QOCIDriver::parseArgs: Invalid parameter: '%s'",
- tmp.toLocal8Bit().constData());
+ const QVector<QStringView> opts(QStringView(options).split(u';', Qt::SkipEmptyParts));
+ for (const auto tmp : opts) {
+ qsizetype idx;
+ if ((idx = tmp.indexOf(u'=')) == -1) {
+ qCWarning(lcOci, "QOCIDriver::parseArgs: Invalid parameter: '%ls'",
+ qUtf16Printable(tmp.toString()));
continue;
}
- const QString opt = tmp.left(idx);
- const QString val = tmp.mid(idx + 1).simplified();
+ const QStringView opt = tmp.left(idx);
+ const QStringView val = tmp.mid(idx + 1).trimmed();
bool ok;
- if (opt == QLatin1String("OCI_ATTR_PREFETCH_ROWS")) {
+ if (opt == "OCI_ATTR_PREFETCH_ROWS"_L1) {
d->prefetchRows = val.toInt(&ok);
if (!ok)
d->prefetchRows = -1;
- } else if (opt == QLatin1String("OCI_ATTR_PREFETCH_MEMORY")) {
+ } else if (opt == "OCI_ATTR_PREFETCH_MEMORY"_L1) {
d->prefetchMem = val.toInt(&ok);
if (!ok)
d->prefetchMem = -1;
+ } else if (opt == "OCI_AUTH_MODE"_L1) {
+ if (val == "OCI_SYSDBA"_L1) {
+ d->authMode = OCI_SYSDBA;
+ } else if (val == "OCI_SYSOPER"_L1) {
+ d->authMode = OCI_SYSOPER;
+ } else if (val != "OCI_DEFAULT"_L1) {
+ qCWarning(lcOci, "QOCIDriver::parseArgs: Unsupported value for OCI_AUTH_MODE: '%ls'",
+ qUtf16Printable(val.toString()));
+ }
} else {
- qWarning ("QOCIDriver::parseArgs: Invalid parameter: '%s'",
- opt.toLocal8Bit().constData());
+ qCWarning(lcOci, "QOCIDriver::parseArgs: Invalid parameter: '%ls'",
+ qUtf16Printable(opt.toString()));
}
}
}
@@ -2311,9 +2278,9 @@ bool QOCIDriver::open(const QString & db,
if (r == OCI_SUCCESS) {
if (user.isEmpty() && password.isEmpty())
- r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_EXT, OCI_DEFAULT);
+ r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_EXT, d->authMode);
else
- r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_RDBMS, OCI_DEFAULT);
+ r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_RDBMS, d->authMode);
}
if (r == OCI_SUCCESS || r == OCI_SUCCESS_WITH_INFO)
r = OCIAttrSet(d->svc, OCI_HTYPE_SVCCTX, d->authp, 0, OCI_ATTR_SESSION, d->err);
@@ -2344,12 +2311,12 @@ bool QOCIDriver::open(const QString & db,
sizeof(vertxt),
OCI_HTYPE_SVCCTX);
if (r != 0) {
- qWarning("QOCIDriver::open: could not get Oracle server version.");
+ qCWarning(lcOci, "QOCIDriver::open: could not get Oracle server version.");
} else {
QString versionStr;
versionStr = QString(reinterpret_cast<const QChar *>(vertxt));
#if QT_CONFIG(regularexpression)
- auto match = QRegularExpression(QLatin1String("([0-9]+)\\.[0-9\\.]+[0-9]")).match(versionStr);
+ auto match = QRegularExpression("([0-9]+)\\.[0-9\\.]+[0-9]"_L1).match(versionStr);
if (match.hasMatch())
d->serverVersion = match.captured(1).toInt();
#endif
@@ -2393,7 +2360,7 @@ bool QOCIDriver::beginTransaction()
{
Q_D(QOCIDriver);
if (!isOpen()) {
- qWarning("QOCIDriver::beginTransaction: Database not open");
+ qCWarning(lcOci, "QOCIDriver::beginTransaction: Database not open");
return false;
}
int r = OCITransStart(d->svc,
@@ -2414,7 +2381,7 @@ bool QOCIDriver::commitTransaction()
{
Q_D(QOCIDriver);
if (!isOpen()) {
- qWarning("QOCIDriver::commitTransaction: Database not open");
+ qCWarning(lcOci, "QOCIDriver::commitTransaction: Database not open");
return false;
}
int r = OCITransCommit(d->svc,
@@ -2434,7 +2401,7 @@ bool QOCIDriver::rollbackTransaction()
{
Q_D(QOCIDriver);
if (!isOpen()) {
- qWarning("QOCIDriver::rollbackTransaction: Database not open");
+ qCWarning(lcOci, "QOCIDriver::rollbackTransaction: Database not open");
return false;
}
int r = OCITransRollback(d->svc,
@@ -2467,18 +2434,18 @@ static QString make_where_clause(const QString &user, Expression e)
"WMSYS",
};
static const char joinC[][4] = { "or" , "and" };
- static constexpr QLatin1Char bang[] = { QLatin1Char(' '), QLatin1Char('!') };
+ static constexpr char16_t bang[] = { u' ', u'!' };
- const QLatin1String join(joinC[e]);
+ const QLatin1StringView join(joinC[e]);
QString result;
result.reserve(sizeof sysUsers / sizeof *sysUsers *
// max-sizeof(owner != <sysuser> and )
(9 + sizeof *sysUsers + 5));
for (const auto &sysUser : sysUsers) {
- const QLatin1String l1(sysUser);
+ const QLatin1StringView l1(sysUser);
if (l1 != user)
- result += QLatin1String("owner ") + bang[e] + QLatin1String("= '") + l1 + QLatin1String("' ") + join + QLatin1Char(' ');
+ result += "owner "_L1 + bang[e] + "= '"_L1 + l1 + "' "_L1 + join + u' ';
}
result.chop(join.size() + 2); // remove final " <join> "
@@ -2503,58 +2470,58 @@ QStringList QOCIDriver::tables(QSql::TableType type) const
QSqlQuery t(createResult());
t.setForwardOnly(true);
if (type & QSql::Tables) {
- const QLatin1String tableQuery("select owner, table_name from all_tables where ");
+ const auto tableQuery = "select owner, table_name from all_tables where "_L1;
const QString where = make_where_clause(user, AndExpression);
t.exec(tableQuery + where);
while (t.next()) {
if (t.value(0).toString().toUpper() != user.toUpper())
- tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
+ tl.append(t.value(0).toString() + u'.' + t.value(1).toString());
else
tl.append(t.value(1).toString());
}
// list all table synonyms as well
- const QLatin1String synonymQuery("select owner, synonym_name from all_synonyms where ");
+ const auto synonymQuery = "select owner, synonym_name from all_synonyms where "_L1;
t.exec(synonymQuery + where);
while (t.next()) {
if (t.value(0).toString() != d->user)
- tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
+ tl.append(t.value(0).toString() + u'.' + t.value(1).toString());
else
tl.append(t.value(1).toString());
}
}
if (type & QSql::Views) {
- const QLatin1String query("select owner, view_name from all_views where ");
+ const auto query = "select owner, view_name from all_views where "_L1;
const QString where = make_where_clause(user, AndExpression);
t.exec(query + where);
while (t.next()) {
if (t.value(0).toString().toUpper() != d->user.toUpper())
- tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
+ tl.append(t.value(0).toString() + u'.' + t.value(1).toString());
else
tl.append(t.value(1).toString());
}
}
if (type & QSql::SystemTables) {
- t.exec(QLatin1String("select table_name from dictionary"));
+ t.exec("select table_name from dictionary"_L1);
while (t.next()) {
tl.append(t.value(0).toString());
}
- const QLatin1String tableQuery("select owner, table_name from all_tables where ");
+ const auto tableQuery = "select owner, table_name from all_tables where "_L1;
const QString where = make_where_clause(user, OrExpression);
t.exec(tableQuery + where);
while (t.next()) {
if (t.value(0).toString().toUpper() != user.toUpper())
- tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
+ tl.append(t.value(0).toString() + u'.' + t.value(1).toString());
else
tl.append(t.value(1).toString());
}
// list all table synonyms as well
- const QLatin1String synonymQuery("select owner, synonym_name from all_synonyms where ");
+ const auto synonymQuery = "select owner, synonym_name from all_synonyms where "_L1;
t.exec(synonymQuery + where);
while (t.next()) {
if (t.value(0).toString() != d->user)
- tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
+ tl.append(t.value(0).toString() + u'.' + t.value(1).toString());
else
tl.append(t.value(1).toString());
}
@@ -2565,7 +2532,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const
void qSplitTableAndOwner(const QString & tname, QString * tbl,
QString * owner)
{
- int i = tname.indexOf(QLatin1Char('.')); // prefixed with owner?
+ qsizetype i = tname.indexOf(u'.'); // prefixed with owner?
if (i != -1) {
*tbl = tname.right(tname.length() - i - 1);
*owner = tname.left(i);
@@ -2584,14 +2551,13 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const
QSqlQuery t(createResult());
// using two separate queries for this is A LOT faster than using
// eg. a sub-query on the sys.synonyms table
- QString stmt(QLatin1String("select column_name, data_type, data_length, "
+ QString stmt("select column_name, data_type, data_length, "
"data_precision, data_scale, nullable, data_default%1"
- "from all_tab_columns a "
- "where a.table_name=%2"));
+ "from all_tab_columns a "_L1);
if (d->serverVersion >= 9)
- stmt = stmt.arg(QLatin1String(", char_length "));
+ stmt = stmt.arg(", char_length "_L1);
else
- stmt = stmt.arg(QLatin1String(" "));
+ stmt = stmt.arg(" "_L1);
bool buildRecordInfo = false;
QString table, owner, tmpStmt;
qSplitTableAndOwner(tablename, &table, &owner);
@@ -2601,7 +2567,7 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const
else
table = table.toUpper();
- tmpStmt = stmt.arg(QLatin1Char('\'') + table + QLatin1Char('\''));
+ tmpStmt = stmt + "where a.table_name='"_L1 + table + u'\'';
if (owner.isEmpty()) {
owner = d->user;
}
@@ -2611,15 +2577,12 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const
else
owner = owner.toUpper();
- tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\'');
+ tmpStmt += " and a.owner='"_L1 + owner + u'\'';
t.setForwardOnly(true);
t.exec(tmpStmt);
if (!t.next()) { // try and see if the tablename is a synonym
- stmt = stmt + QLatin1String(" join all_synonyms b "
- "on a.owner=b.table_owner and a.table_name=b.table_name "
- "where b.owner='") + owner +
- QLatin1String("' and b.synonym_name='") + table +
- QLatin1Char('\'');
+ stmt = stmt + " join all_synonyms b on a.owner=b.table_owner and a.table_name=b.table_name "
+ "where b.owner='"_L1 + owner + "' and b.synonym_name='"_L1 + table + u'\'';
t.setForwardOnly(true);
t.exec(stmt);
if (t.next())
@@ -2627,13 +2590,13 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const
} else {
buildRecordInfo = true;
}
- QStringList keywords = QStringList() << QLatin1String("NUMBER") << QLatin1String("FLOAT") << QLatin1String("BINARY_FLOAT")
- << QLatin1String("BINARY_DOUBLE");
+ QStringList keywords = QStringList() << "NUMBER"_L1 << "FLOAT"_L1 << "BINARY_FLOAT"_L1
+ << "BINARY_DOUBLE"_L1;
if (buildRecordInfo) {
do {
QMetaType ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy());
QSqlField f(t.value(0).toString(), ty);
- f.setRequired(t.value(5).toString() == QLatin1String("N"));
+ f.setRequired(t.value(5).toString() == "N"_L1);
f.setPrecision(t.value(4).toInt());
if (d->serverVersion >= 9 && (ty.id() == QMetaType::QString) && !t.isNull(3) && !keywords.contains(t.value(1).toString())) {
// Oracle9: data_length == size in bytes, char_length == amount of characters
@@ -2655,11 +2618,11 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
if (!isOpen())
return idx;
QSqlQuery t(createResult());
- QString stmt(QLatin1String("select b.column_name, b.index_name, a.table_name, a.owner "
+ QString stmt("select b.column_name, b.index_name, a.table_name, a.owner "
"from all_constraints a, all_ind_columns b "
"where a.constraint_type='P' "
"and b.index_name = a.index_name "
- "and b.index_owner = a.owner"));
+ "and b.index_owner = a.owner"_L1);
bool buildIndex = false;
QString table, owner, tmpStmt;
@@ -2670,7 +2633,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
else
table = table.toUpper();
- tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1Char('\'');
+ tmpStmt = stmt + " and a.table_name='"_L1 + table + u'\'';
if (owner.isEmpty()) {
owner = d->user;
}
@@ -2680,13 +2643,13 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
else
owner = owner.toUpper();
- tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\'');
+ tmpStmt += " and a.owner='"_L1 + owner + u'\'';
t.setForwardOnly(true);
t.exec(tmpStmt);
if (!t.next()) {
- stmt += QLatin1String(" and a.table_name=(select tname from sys.synonyms "
- "where sname='") + table + QLatin1String("' and creator=a.owner)");
+ stmt += " and a.table_name=(select tname from sys.synonyms where sname='"_L1
+ + table + "' and creator=a.owner)"_L1;
t.setForwardOnly(true);
t.exec(stmt);
if (t.next()) {
@@ -2701,10 +2664,10 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
tt.setForwardOnly(true);
idx.setName(t.value(1).toString());
do {
- tt.exec(QLatin1String("select data_type from all_tab_columns where table_name='") +
- t.value(2).toString() + QLatin1String("' and column_name='") +
- t.value(0).toString() + QLatin1String("' and owner='") +
- owner + QLatin1Char('\''));
+ tt.exec("select data_type from all_tab_columns where table_name='"_L1 +
+ t.value(2).toString() + "' and column_name='"_L1 +
+ t.value(0).toString() + "' and owner='"_L1 +
+ owner + u'\'');
if (!tt.next()) {
return QSqlIndex();
}
@@ -2718,21 +2681,21 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const
{
- switch (field.typeID()) {
+ switch (field.metaType().id()) {
case QMetaType::QDateTime: {
QDateTime datetime = field.value().toDateTime();
QString datestring;
if (datetime.isValid()) {
- datestring = QLatin1String("TO_DATE('") + QString::number(datetime.date().year())
- + QLatin1Char('-')
- + QString::number(datetime.date().month()) + QLatin1Char('-')
- + QString::number(datetime.date().day()) + QLatin1Char(' ')
- + QString::number(datetime.time().hour()) + QLatin1Char(':')
- + QString::number(datetime.time().minute()) + QLatin1Char(':')
+ datestring = "TO_DATE('"_L1 + QString::number(datetime.date().year())
+ + u'-'
+ + QString::number(datetime.date().month()) + u'-'
+ + QString::number(datetime.date().day()) + u' '
+ + QString::number(datetime.time().hour()) + u':'
+ + QString::number(datetime.time().minute()) + u':'
+ QString::number(datetime.time().second())
- + QLatin1String("','YYYY-MM-DD HH24:MI:SS')");
+ + "','YYYY-MM-DD HH24:MI:SS')"_L1;
} else {
- datestring = QLatin1String("NULL");
+ datestring = "NULL"_L1;
}
return datestring;
}
@@ -2740,13 +2703,13 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const
QDateTime datetime = field.value().toDateTime();
QString datestring;
if (datetime.isValid()) {
- datestring = QLatin1String("TO_DATE('")
- + QString::number(datetime.time().hour()) + QLatin1Char(':')
- + QString::number(datetime.time().minute()) + QLatin1Char(':')
+ datestring = "TO_DATE('"_L1
+ + QString::number(datetime.time().hour()) + u':'
+ + QString::number(datetime.time().minute()) + u':'
+ QString::number(datetime.time().second())
- + QLatin1String("','HH24:MI:SS')");
+ + "','HH24:MI:SS')"_L1;
} else {
- datestring = QLatin1String("NULL");
+ datestring = "NULL"_L1;
}
return datestring;
}
@@ -2754,12 +2717,12 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const
QDate date = field.value().toDate();
QString datestring;
if (date.isValid()) {
- datestring = QLatin1String("TO_DATE('") + QString::number(date.year()) +
- QLatin1Char('-') +
- QString::number(date.month()) + QLatin1Char('-') +
- QString::number(date.day()) + QLatin1String("','YYYY-MM-DD')");
+ datestring = "TO_DATE('"_L1 + QString::number(date.year()) +
+ u'-' +
+ QString::number(date.month()) + u'-' +
+ QString::number(date.day()) + "','YYYY-MM-DD')"_L1;
} else {
- datestring = QLatin1String("NULL");
+ datestring = "NULL"_L1;
}
return datestring;
}
@@ -2779,11 +2742,20 @@ QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType t
{
QString res = identifier;
if (!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) {
- res.replace(QLatin1Char('"'), QLatin1String("\"\""));
- res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
- res.replace(QLatin1Char('.'), QLatin1String("\".\""));
+ res.replace(u'"', "\"\""_L1);
+ res.replace(u'.', "\".\""_L1);
+ res = u'"' + res + u'"';
}
return res;
}
+int QOCIDriver::maximumIdentifierLength(IdentifierType type) const
+{
+ Q_D(const QOCIDriver);
+ Q_UNUSED(type);
+ return d->serverVersion > 12 ? 128 : 30;
+}
+
QT_END_NAMESPACE
+
+#include "moc_qsql_oci_p.cpp"