summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/CMakeLists.txt66
-rw-r--r--src/sql/compat/removed_api.cpp52
-rw-r--r--src/sql/configure.cmake27
-rw-r--r--src/sql/configure.json22
-rw-r--r--src/sql/doc/qtsql.qdocconf15
-rw-r--r--src/sql/doc/snippets/CMakeLists.txt7
-rw-r--r--src/sql/doc/snippets/code/CMakeLists.txt16
-rw-r--r--src/sql/doc/snippets/code/code.pro3
-rw-r--r--src/sql/doc/snippets/code/doc_src_qtsql.cpp53
-rw-r--r--src/sql/doc/snippets/code/doc_src_qtsql.pro3
-rw-r--r--src/sql/doc/snippets/code/doc_src_sql-driver.cpp149
-rw-r--r--src/sql/doc/snippets/code/doc_src_sql-driver.qdoc317
-rw-r--r--src/sql/doc/snippets/code/doc_src_sql-driver_snippet.cpp19
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp126
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase_snippet.cpp22
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp77
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp59
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp77
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqlquery_snippet.cpp11
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp86
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqlresult_snippet.cpp18
-rw-r--r--src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp61
-rw-r--r--src/sql/doc/snippets/sqldatabase/CMakeLists.txt11
-rw-r--r--src/sql/doc/snippets/sqldatabase/sqldatabase.cpp133
-rw-r--r--src/sql/doc/snippets/sqldatabase/sqldatabase_snippet.cpp84
-rw-r--r--src/sql/doc/src/dontdocument.qdoc28
-rw-r--r--src/sql/doc/src/qsqldatatype-table.qdoc222
-rw-r--r--src/sql/doc/src/qt6-changes.qdoc44
-rw-r--r--src/sql/doc/src/qtsql.qdoc103
-rw-r--r--src/sql/doc/src/sql-driver.qdoc597
-rw-r--r--src/sql/doc/src/sql-programming.qdoc45
-rw-r--r--src/sql/kernel/kernel.pri27
-rw-r--r--src/sql/kernel/qsql.qdoc28
-rw-r--r--src/sql/kernel/qsqlcachedresult.cpp46
-rw-r--r--src/sql/kernel/qsqlcachedresult_p.h44
-rw-r--r--src/sql/kernel/qsqldatabase.cpp472
-rw-r--r--src/sql/kernel/qsqldatabase.h59
-rw-r--r--src/sql/kernel/qsqldriver.cpp212
-rw-r--r--src/sql/kernel/qsqldriver.h48
-rw-r--r--src/sql/kernel/qsqldriver_p.h48
-rw-r--r--src/sql/kernel/qsqldriverplugin.cpp42
-rw-r--r--src/sql/kernel/qsqldriverplugin.h40
-rw-r--r--src/sql/kernel/qsqlerror.cpp221
-rw-r--r--src/sql/kernel/qsqlerror.h86
-rw-r--r--src/sql/kernel/qsqlfield.cpp379
-rw-r--r--src/sql/kernel/qsqlfield.h99
-rw-r--r--src/sql/kernel/qsqlindex.cpp114
-rw-r--r--src/sql/kernel/qsqlindex.h67
-rw-r--r--src/sql/kernel/qsqlnulldriver_p.h44
-rw-r--r--src/sql/kernel/qsqlquery.cpp326
-rw-r--r--src/sql/kernel/qsqlquery.h82
-rw-r--r--src/sql/kernel/qsqlrecord.cpp278
-rw-r--r--src/sql/kernel/qsqlrecord.h86
-rw-r--r--src/sql/kernel/qsqlresult.cpp268
-rw-r--r--src/sql/kernel/qsqlresult.h58
-rw-r--r--src/sql/kernel/qsqlresult_p.h56
-rw-r--r--src/sql/kernel/qtsqlglobal.h55
-rw-r--r--src/sql/kernel/qtsqlglobal_p.h40
-rw-r--r--src/sql/models/models.pri12
-rw-r--r--src/sql/models/qsqlquerymodel.cpp92
-rw-r--r--src/sql/models/qsqlquerymodel.h47
-rw-r--r--src/sql/models/qsqlquerymodel_p.h74
-rw-r--r--src/sql/models/qsqlrelationaldelegate.cpp40
-rw-r--r--src/sql/models/qsqlrelationaldelegate.h97
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp104
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.h48
-rw-r--r--src/sql/models/qsqltablemodel.cpp120
-rw-r--r--src/sql/models/qsqltablemodel.h45
-rw-r--r--src/sql/models/qsqltablemodel_p.h42
-rw-r--r--src/sql/qt_cmdline.cmake0
-rw-r--r--src/sql/sql.pro18
71 files changed, 2771 insertions, 3846 deletions
diff --git a/src/sql/CMakeLists.txt b/src/sql/CMakeLists.txt
new file mode 100644
index 0000000000..0a51f62c4b
--- /dev/null
+++ b/src/sql/CMakeLists.txt
@@ -0,0 +1,66 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## Sql Module:
+#####################################################################
+
+qt_internal_add_module(Sql
+ PLUGIN_TYPES sqldrivers
+ SOURCES
+ compat/removed_api.cpp
+ kernel/qsqlcachedresult.cpp kernel/qsqlcachedresult_p.h
+ kernel/qsqldatabase.cpp kernel/qsqldatabase.h
+ kernel/qsqldriver.cpp kernel/qsqldriver.h kernel/qsqldriver_p.h
+ kernel/qsqldriverplugin.cpp kernel/qsqldriverplugin.h
+ kernel/qsqlerror.cpp kernel/qsqlerror.h
+ kernel/qsqlfield.cpp kernel/qsqlfield.h
+ kernel/qsqlindex.cpp kernel/qsqlindex.h
+ kernel/qsqlnulldriver_p.h
+ kernel/qsqlquery.cpp kernel/qsqlquery.h
+ kernel/qsqlrecord.cpp kernel/qsqlrecord.h
+ kernel/qsqlresult.cpp kernel/qsqlresult.h kernel/qsqlresult_p.h
+ kernel/qtsqlglobal.h kernel/qtsqlglobal_p.h
+ DEFINES
+ QT_NO_CAST_FROM_ASCII
+ QT_NO_CONTEXTLESS_CONNECT
+ QT_NO_FOREACH
+ QT_NO_USING_NAMESPACE
+ QT_USE_NODISCARD_FILE_OPEN
+ LIBRARIES
+ Qt::CorePrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ PRIVATE_MODULE_INTERFACE
+ Qt::CorePrivate
+ NO_PCH_SOURCES
+ "compat/removed_api.cpp"
+ PRECOMPILED_HEADER
+ "../corelib/global/qt_pch.h"
+ GENERATE_CPP_EXPORTS
+)
+
+## Scopes:
+#####################################################################
+
+qt_internal_extend_target(Sql CONDITION MSVC AND (TEST_architecture_arch STREQUAL "i386")
+ LINK_OPTIONS
+ "/BASE:0x62000000"
+)
+
+qt_internal_extend_target(Sql CONDITION QT_FEATURE_sqlmodel
+ SOURCES
+ models/qsqlquerymodel.cpp models/qsqlquerymodel.h models/qsqlquerymodel_p.h
+ models/qsqlrelationaldelegate.cpp models/qsqlrelationaldelegate.h
+ models/qsqlrelationaltablemodel.cpp models/qsqlrelationaltablemodel.h
+ models/qsqltablemodel.cpp models/qsqltablemodel.h models/qsqltablemodel_p.h
+)
+qt_internal_add_docs(Sql
+ doc/qtsql.qdocconf
+)
+
+# include the snippet projects for developer-builds
+if(QT_FEATURE_private_tests)
+ add_subdirectory(doc/snippets/code)
+ add_subdirectory(doc/snippets/sqldatabase)
+endif()
diff --git a/src/sql/compat/removed_api.cpp b/src/sql/compat/removed_api.cpp
new file mode 100644
index 0000000000..9da60eceda
--- /dev/null
+++ b/src/sql/compat/removed_api.cpp
@@ -0,0 +1,52 @@
+// Copyright (C) 2022 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
+
+#define QT_SQL_BUILD_REMOVED_API
+
+#include "qtsqlglobal.h"
+
+QT_USE_NAMESPACE
+
+#if QT_SQL_REMOVED_SINCE(6, 4)
+
+#endif // QT_SQL_REMOVED_SINCE(6, 4)
+
+#if QT_SQL_REMOVED_SINCE(6, 5)
+
+#if QT_CONFIG(sqlmodel)
+
+#include "qsqlquerymodel.h"
+#include "qsqlquery.h"
+
+QSqlQuery QSqlQueryModel::query() const
+{
+ QT_IGNORE_DEPRECATIONS(return query(QT6_CALL_NEW_OVERLOAD);)
+}
+
+#include "qsqltablemodel.h"
+
+void QSqlTableModel::setQuery(const QSqlQuery &query)
+{
+ QT_IGNORE_DEPRECATIONS(QSqlQueryModel::setQuery(query);)
+}
+
+#endif // QT_CONFIG(sqlmodel)
+
+#endif // QT_SQL_REMOVED_SINCE(6, 5)
+
+#if QT_SQL_REMOVED_SINCE(6, 6)
+
+#include "qsqlresult.h"
+#include <QtSql/private/qsqlresult_p.h>
+
+// #include <qotherheader.h>
+// // implement removed functions from qotherheader.h
+// order sections alphabetically to reduce chances of merge conflicts
+
+QList<QVariant> &QSqlResult::boundValues() const
+{
+ Q_D(const QSqlResult);
+ return const_cast<QSqlResultPrivate *>(d)->values;
+}
+
+#endif // QT_SQL_REMOVED_SINCE(6, 6)
diff --git a/src/sql/configure.cmake b/src/sql/configure.cmake
new file mode 100644
index 0000000000..f8a0c087d5
--- /dev/null
+++ b/src/sql/configure.cmake
@@ -0,0 +1,27 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+
+#### Inputs
+
+
+
+#### Libraries
+
+
+
+#### Tests
+
+
+
+#### Features
+
+qt_feature("sqlmodel" PUBLIC
+ LABEL "SQL item models"
+ PURPOSE "Provides item model classes backed by SQL databases."
+ CONDITION QT_FEATURE_itemmodel
+)
+qt_configure_add_summary_section(NAME "Qt Sql")
+qt_configure_add_summary_entry(ARGS "sqlmodel")
+qt_configure_end_summary_section() # end of "Qt Sql" section
diff --git a/src/sql/configure.json b/src/sql/configure.json
deleted file mode 100644
index 8fdc27e3a2..0000000000
--- a/src/sql/configure.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "module": "sql",
- "depends": [
- "core"
- ],
-
- "features": {
- "sqlmodel": {
- "label": "SQL item models",
- "purpose": "Provides item model classes backed by SQL databases.",
- "condition": "features.itemmodel",
- "output": [ "publicFeature" ]
- }
- },
-
- "summary": [
- {
- "section": "Qt Sql",
- "entries": [ "sqlmodel" ]
- }
- ]
-}
diff --git a/src/sql/doc/qtsql.qdocconf b/src/sql/doc/qtsql.qdocconf
index f353a11e8b..9f6e1a31e0 100644
--- a/src/sql/doc/qtsql.qdocconf
+++ b/src/sql/doc/qtsql.qdocconf
@@ -15,10 +15,6 @@ qhp.QtSql.virtualFolder = qtsql
qhp.QtSql.indexTitle = Qt SQL
qhp.QtSql.indexRoot =
-qhp.QtSql.filterAttributes = qtsql $QT_VERSION qtrefdoc
-qhp.QtSql.customFilters.Qt.name = QtSql $QT_VERSION
-qhp.QtSql.customFilters.Qt.filterAttributes = qtsql $QT_VERSION
-
qhp.QtSql.subprojects = classes
qhp.QtSql.subprojects.classes.title = C++ Classes
qhp.QtSql.subprojects.classes.indexTitle = Qt SQL C++ Classes
@@ -26,7 +22,7 @@ qhp.QtSql.subprojects.classes.selectors = class fake:headerfile
qhp.QtSql.subprojects.classes.sortPages = true
tagfile = ../../../doc/qtsql/qtsql.tags
-depends += qtcore qtwidgets qtdoc qmake
+depends += qtcore qtwidgets qtdoc qmake qtcmake
headerdirs += ..
@@ -35,6 +31,7 @@ sourcedirs += .. \
exampledirs += ../../../examples/sql \
../ \
+ . \ \
snippets
imagedirs += images \
@@ -42,3 +39,11 @@ imagedirs += images \
navigation.landingpage = "Qt SQL"
navigation.cppclassespage = "Qt SQL C++ Classes"
+
+# Highlighted examples in Data Processing & IO category
+manifestmeta.highlighted.names = \
+ "QtSql/Master Detail Example" \
+ "QtSql/SQL Browser"
+
+# Enforce zero documentation warnings
+warninglimit = 0
diff --git a/src/sql/doc/snippets/CMakeLists.txt b/src/sql/doc/snippets/CMakeLists.txt
new file mode 100644
index 0000000000..a5c34d5688
--- /dev/null
+++ b/src/sql/doc/snippets/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#! [cmake_use]
+find_package(Qt6 REQUIRED COMPONENTS Sql)
+target_link_libraries(mytarget PRIVATE Qt6::Sql)
+#! [cmake_use]
diff --git a/src/sql/doc/snippets/code/CMakeLists.txt b/src/sql/doc/snippets/code/CMakeLists.txt
new file mode 100644
index 0000000000..b6899137fe
--- /dev/null
+++ b/src/sql/doc/snippets/code/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+add_library(code_snippets OBJECT
+ doc_src_sql-driver.cpp
+ src_sql_kernel_qsqldatabase.cpp
+ src_sql_kernel_qsqlerror.cpp
+ src_sql_kernel_qsqlresult.cpp
+ src_sql_kernel_qsqldriver.cpp
+ src_sql_models_qsqlquerymodel.cpp
+)
+
+target_link_libraries(code_snippets PRIVATE
+ Qt::Core
+ Qt::Sql
+)
diff --git a/src/sql/doc/snippets/code/code.pro b/src/sql/doc/snippets/code/code.pro
new file mode 100644
index 0000000000..d088ce94e3
--- /dev/null
+++ b/src/sql/doc/snippets/code/code.pro
@@ -0,0 +1,3 @@
+#! [qmake_use]
+QT += sql
+#! [qmake_use]
diff --git a/src/sql/doc/snippets/code/doc_src_qtsql.cpp b/src/sql/doc/snippets/code/doc_src_qtsql.cpp
deleted file mode 100644
index 48b70755f2..0000000000
--- a/src/sql/doc/snippets/code/doc_src_qtsql.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-#include <QtSql>
-//! [0]
diff --git a/src/sql/doc/snippets/code/doc_src_qtsql.pro b/src/sql/doc/snippets/code/doc_src_qtsql.pro
deleted file mode 100644
index 1fb8e4dea3..0000000000
--- a/src/sql/doc/snippets/code/doc_src_qtsql.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-#! [1]
-QT += sql
-#! [1]
diff --git a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
index 54576733bf..efcb45c98e 100644
--- a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
+++ b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp
@@ -1,141 +1,92 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QSqlResult>
+#include <QVariant>
+#include <QDebug>
+
+void testProc()
+{
//! [2]
QSqlQuery q;
q.exec("call qtestproc (@outval1, @outval2)");
q.exec("select @outval1, @outval2");
-q.next();
-qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
+if (q.next())
+ qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
//! [2]
+}
-
+void callStoredProc()
+{
//! [10]
// STORED_PROC uses the return statement or returns multiple result sets
QSqlQuery query;
query.setForwardOnly(true);
query.exec("{call STORED_PROC}");
//! [10]
+}
-
+void setHost()
+{
//! [24]
+QSqlDatabase db;
db.setHostName("MyServer");
db.setDatabaseName("C:\\test.gdb");
//! [24]
+}
-
-//! [25]
-// connect to database using the Latin-1 character set
-db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
-db.open();
-//! [25]
-
-
+void exProc()
+{
//! [26]
QSqlQuery q;
q.exec("execute procedure my_procedure");
-q.next();
-qDebug() << q.value(0); // outputs the first RETURN/OUT value
+if (q.next())
+ qDebug() << q.value(0); // outputs the first RETURN/OUT value
//! [26]
+qDebug( \
+"QSqlDatabase: QMYSQL driver not loaded \
+QSqlDatabase: available drivers: QMYSQL" \
+);
-//! [31]
-QSqlDatabase: QMYSQL driver not loaded
-QSqlDatabase: available drivers: QMYSQL
-//! [31]
-
-
+/* Commented because the following line is not compilable
//! [34]
column.contains(QRegularExpression("pattern"));
//! [34]
-
-
-//! [36]
-QSqlQuery query(db);
-query.setForwardOnly(true);
-query.exec("SELECT * FROM table");
-while (query.next()) {
- // Handle changes in every iteration of the loop
- QVariant v = query.result()->handle();
- if (qstrcmp(v.typeName(), "PGresult*") == 0) {
- PGresult *handle = *static_cast<PGresult **>(v.data());
- if (handle) {
- // Do something...
- }
- }
+*/
}
-//! [36]
+
+void updTable2()
+{
+QSqlDatabase db;
//! [37]
int value;
-QSqlQuery query1(db);
+QSqlQuery query1;
query1.setForwardOnly(true);
query1.exec("select * FROM table1");
while (query1.next()) {
value = query1.value(0).toInt();
if (value == 1) {
- QSqlQuery query2(db);
+ QSqlQuery query2;
query2.exec("update table2 set col=2"); // WRONG: This will discard all results of
} // query1, and cause the loop to quit
}
//! [37]
+}
-
-//! [39]
-QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
-QString connectString = QStringLiteral(
- "DRIVER=/path/to/installation/libodbcHDB.so;"
- "SERVERNODE=hostname:port;"
- "UID=USER;"
- "PWD=PASSWORD;"
- "SCROLLABLERESULT=true");
-db.setDatabaseName(connectString);
-//! [39]
+void callOutProc()
+{
+//! [40]
+ QSqlDatabase db;
+ QSqlQuery query;
+ int i1 = 10, i2 = 0;
+ query.prepare("call qtestproc(?, ?)");
+ query.bindValue(0, i1, QSql::InOut);
+ query.bindValue(1, i2, QSql::Out);
+ query.exec();
+//! [40]
+}
diff --git a/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc b/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
index b869b309b7..896839a1d9 100644
--- a/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
+++ b/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [0]
[...]
@@ -54,9 +7,9 @@
Database options:
-sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers:
- db2 ibase mysql oci odbc psql sqlite2 sqlite tds
+ db2 ibase mysql oci odbc psql sqlite
[all auto]
- -sqlite .............. Select used sqlite3 [system/qt]
+ -sqlite .............. Select used sqlite [system/qt]
[...]
//! [0]
@@ -70,172 +23,177 @@ BEGIN
END
//! [1]
+
//! [3]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- MYSQL_PREFIX=/usr/local
-make sub-mysql
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
+cmake --build .
+cmake --install .
//! [3]
-//! [4]
-cd $QTDIR/qtbase/src/plugins/sqldrivers/mysql
-make install
-//! [4]
-
-
//! [5]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- MYSQL_INCDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
-nmake sub-mysql
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
+cmake --build .
+cmake --install .
//! [5]
-//! [6]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- OCI_INCDIR="$ORACLE_HOME/rdbms/public" OCI_LIBDIR="$ORACLE_HOME/lib" OCI_LIBS="-lclntsh -lwtc9"
-make sub-oci
-//! [6]
-
-
//! [7]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- OCI_INCDIR=/usr/include/oracle/10.1.0.3/client OCI_LIBDIR=/usr/lib/oracle/10.1.0.3/client/lib
-make sub-oci
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DOracle_INCLUDE_DIR="/usr/include/oracle/21/client64" -DOracle_LIBRARY="/usr/lib/oracle/21/client64/lib/libclntsh.<so|dylib>"
+cmake --build .
+cmake --install .
//! [7]
//! [8]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- OCI_INCDIR=c:/oracle/oci/include OCI_LIBDIR=c:/oracle/oci/lib/msvc
-nmake sub-oci
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DOracle_INCLUDE_DIR="C:\oracle\sdk\include" -DOracle_LIBRARY="C:\oracle\oci.lib"
+cmake --build .
+cmake --install .
//! [8]
//! [9]
-set PATH=%PATH%;c:\oracle\bin
+set PATH=%PATH%;C:\oracle
//! [9]
//! [11]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- ODBC_PREFIX=/usr/local/unixODBC
-make sub-odbc
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DODBC_INCLUDE_DIR="/usr/local/unixODBC/include" -DODBC_LIBRARY="/usr/local/unixODBC/lib/libodbc.<so|dylib>"
+cmake --build .
+cmake --install .
//! [11]
//! [12]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake
-nmake sub-odbc
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform>
+cmake --build .
+cmake --install .
//! [12]
//! [13]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- PSQL_INCDIR=/usr/include/pgsql
-make sub-psql
+mkdir build-psql-driver
+cd build-psql-driver
+
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers-DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DCMAKE_INCLUDE_PATH="/usr/local/pgsql/include" -DCMAKE_LIBRARY_PATH="/usr/local/pgsql/lib"
+cmake --build .
+cmake --install .
//! [13]
//! [15]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- PSQL_INCDIR=C:/psql/include PSQL_LIBDIR=C:/psql/lib/ms
-nmake sub-psql
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DCMAKE_INCLUDE_PATH="C:\pgsql\include" -DCMAKE_LIBRARY_PATH="C:\pgsql\lib"
+cmake --build .
+cmake --install .
//! [15]
-//! [16]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- TDS_PREFIX=$SYBASE
-make sub-tds
-//! [16]
-
-
-//! [17]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake
-nmake sub-tds
-nmake install
-//! [17]
-
-
//! [18]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- DB2_PREFIX=$DB2DIR
-make sub-db2
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DDB2_INCLUDE_DIR="/usr/local/db2/include" -DDB2_LIBRARY="/usr/local/db2/lib/libdb2.<so|dylib>"
+cmake --build .
+cmake --install .
//! [18]
//! [20]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- DB2_PREFIX="<DB2 home>/sqllib"
-nmake sub-db2
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DDB2_INCLUDE_DIR="C:\db2\include" -DDB2_LIBRARY="C:\db2\lib\db2.lib"
+cmake --build .
+cmake --install .
//! [20]
//! [21]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- -system-sqlite SQLITE3_PREFIX=$SQLITE
-make sub-sqlite
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH="$SQLITE/include" -DCMAKE_LIBRARY_PATH="$SQLITE/lib"
+cmake --build .
+cmake --install .
//! [21]
//! [23]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- -system-sqlite SQLITE3_PREFIX=C:/SQLITE
-nmake sub-sqlite
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH="C:\SQLITE\include" -DCMAKE_LIBRARY_PATH="C:\SQLITE\lib"
+cmake --build .
+cmake --install .
//! [23]
//! [27]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- IBASE_PREFIX=/opt/interbase
-make sub-ibase
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libgds.<so|dylib>"
+cmake --build .
+cmake --install .
//! [27]
//! [28]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- IBASE_PREFIX=/opt/interbase IBASE_LIBS=-lfbclient
-make sub-ibase
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_source_directory>/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DInterbase_INCLUDE_DIR="/opt/interbase/include" -DInterbase_LIBRARY="/opt/interbase/lib/libfbclient.<so|dylib>"
+cmake --build .
+cmake --install .
//! [28]
//! [29]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- IBASE_INCDIR=C:/interbase/include
-nmake sub-ibase
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DInterbase_INCLUDE_DIR="C:\interbase\include" -DInterbase_LIBRARY="C:\interbase\gds.lib"
+cmake --build .
+cmake --install .
//! [29]
//! [30]
-cd %QTDIR%\qtbase\src\plugins\sqldrivers
-qmake -- IBASE_INCDIR=C:/interbase/include IBASE_LIBS=-lfbclient
-nmake sub-ibase
-nmake install
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DInterbase_INCLUDE_DIR="C:\interbase\include" -DInterbase_LIBRARY="C:\interbase\lib\fbclient_ms.lib"
+cmake --build .
+cmake --install .
//! [30]
+//! [31]
+mkdir build-sqldrivers
+cd build-sqldrivers
-//! [32]
-configure OCI_INCDIR=/usr/include/oracle/10.1.0.3/client OCI_LIBDIR=/usr/lib/oracle/10.1.0.3/client/lib -R /usr/lib/oracle/10.1.0.3/client/lib OCI_LIBS="-lclntsh -lnnz10"
-make
-//! [32]
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMimer_INCLUDE_DIR="/usr/include" -DMimer_LIBRARIES="/usr/lib/libmimer.so"
+cmake --build .
+cmake --install .
+//! [31]
-//! [33]
-cd $QTDIR/qtbase/src/plugins/sqldrivers
-qmake -- OCI_INCDIR=/usr/include/oracle/10.1.0.3/client OCI_LIBDIR=/usr/lib/oracle/10.1.0.3/client/lib OCI_LIBS="-Wl,-rpath,/usr/lib/oracle/10.1.0.3/client/lib -lclntsh -lnnz10"
-make sub-oci
-//! [33]
+//! [32]
+mkdir build-sqldrivers
+cd build-sqldrivers
+qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMimer_INCLUDE_DIR="C:\Program Files\Mimer SQL Experience 11.0\dev\include" -DMimer_LIBRARIES="C:\Program Files\Mimer SQL Experience 11.0\dev\lib\amd64\mimapi64.lib|C:\Program Files\Mimer SQL Experience 11.0\dev\lib\x86\mimapi32.lib"
+cmake --build .
+cmake --install .
+//! [32]
//! [35]
QSqlDatabase: QPSQL driver not loaded
-QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QMARIADB QODBC QODBC3 QPSQL QPSQL7
+QSqlDatabase: available drivers: QSQLITE QMYSQL QMARIADB QODBC QPSQL
Could not create database object
//! [35]
@@ -258,40 +216,65 @@ QSqlRecord rec = database.record(tableString.toLower());
//! [40]
//! [41]
-C:\Qt5\5.13.2\Src\qtbase\src\plugins\sqldrivers>qmake -version
-QMake version 3.1
-Using Qt version 5.13.2 in C:/Qt5/5.13.2/mingw73_64/lib
-C:\Qt5\5.13.2\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
-Info: creating stash file C:\Qt5\5.13.2\Src\qtbase\src\plugins\sqldrivers\.qmake.stash
-
-Running configuration tests...
-Checking for DB2 (IBM)... no
-Checking for InterBase... no
-Checking for MySQL... yes
-Checking for OCI (Oracle)... no
-Checking for ODBC... yes
-Checking for PostgreSQL... no
-Checking for SQLite (version 2)... no
-Checking for TDS (Sybase)... no
-Done running configuration tests.
+C:\Qt\6.0.0\mingw81_64\bin\qt-cmake -G Ninja C:\Qt\6.0.0\Src\qtbase\src\plugins\sqldrivers -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.0.0\mingw81_64"
+Configure summary:
+Qt Sql Drivers:
+ DB2 (IBM) .............................. no
+ InterBase .............................. no
+ Mimer SQL .............................. yes
+ MySql .................................. yes
+ OCI (Oracle) ........................... no
+ ODBC ................................... yes
+ PostgreSQL ............................. no
+ SQLite ................................. yes
+ Using system provided SQLite ......... no
+
+-- Configuring done
+-- Generating done
+-- Build files have been written to: C:/build-qt6-sqldrivers
+//! [41]
+
+//! [42]
+C:\Qt\6.0.0\Src\configure.bat -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
Configure summary:
+...
Qt Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
+ Mimer SQL .............................. yes
MySql .................................. yes
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
- SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
- TDS (Sybase) ........................... no
+...
+//! [42]
-Qt is now configured for building. Just run 'mingw32-make'.
-Once everything is built, you must run 'mingw32-make install'.
-Qt will be installed into 'C:\Qt5\5.13.2\mingw73_64'.
+//! [43]
+C:\Qt\6.0.0\Src\configure.bat -sql-mysql -- -DCMAKE_INCLUDE_PATH="C:\mysql-8.0.22-winx64\include" -DCMAKE_LIBRARY_PATH="C:\mysql-8.0.22-winx64\lib"
+Configure summary:
-Prior to reconfiguration, make sure you remove any leftovers from the previous build.
-//! [41]
+...
+Qt Sql Drivers:
+ DB2 (IBM) .............................. no
+ InterBase .............................. no
+ Mimer SQL .............................. yes
+ MySql .................................. yes
+ OCI (Oracle) ........................... no
+ ODBC ................................... yes
+ PostgreSQL ............................. no
+ SQLite ................................. yes
+ Using system provided SQLite ......... no
+...
+//! [43]
+
+//! [44]
+create procedure inout_proc (INOUT param1 INT, OUT param2 INT)
+BEGIN
+ set param1 = param1 * 2;
+ set param2 = param1 * param1;
+END
+//! [44]
diff --git a/src/sql/doc/snippets/code/doc_src_sql-driver_snippet.cpp b/src/sql/doc/snippets/code/doc_src_sql-driver_snippet.cpp
new file mode 100644
index 0000000000..22820063e4
--- /dev/null
+++ b/src/sql/doc/snippets/code/doc_src_sql-driver_snippet.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [36]
+QSqlQuery query;
+QVariant v;
+query.setForwardOnly(true);
+query.exec("SELECT * FROM table");
+while (query.next()) {
+ // Handle changes in every iteration of the loop
+ v = query.result()->handle();
+
+ if (qstrcmp(v.typeName(), "PGresult*") == 0) {
+ PGresult *handle = *static_cast<PGresult **>(v.data());
+ if (handle) {
+ // Do something...
+ }
+ }
+}
+//! [36]
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp
index f09315435e..d892ad7567 100644
--- a/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp
@@ -1,64 +1,24 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QDebug>
+
+void openDatabase()
+{
//! [0]
// WRONG
QSqlDatabase db = QSqlDatabase::database("sales");
QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
QSqlDatabase::removeDatabase("sales"); // will output a warning
-
// "db" is now a dangling invalid database connection,
// "query" contains an invalid result set
//! [0]
+}
-
+void removeDatabase()
+{
//! [1]
{
QSqlDatabase db = QSqlDatabase::database("sales");
@@ -67,72 +27,51 @@ QSqlDatabase::removeDatabase("sales"); // will output a warning
// Both "db" and "query" are destroyed because they are out of scope
QSqlDatabase::removeDatabase("sales"); // correct
//! [1]
+}
-
-//! [2]
-QSqlDatabase::registerSqlDriver("MYDRIVER",
- new QSqlDriverCreator<MyDatabaseDriver>);
-QSqlDatabase db = QSqlDatabase::addDatabase("MYDRIVER");
-//! [2]
-
-
+void setmyDatabase()
+{
//! [3]
-...
-db = QSqlDatabase::addDatabase("QODBC");
+// ...
+QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
if (db.open()) {
// success!
}
-...
+// ...
//! [3]
+}
-
-//! [4]
-...
+// ...
// MySQL connection
+void dbConnect()
+{
+QSqlDatabase db;
+//! [4]
db.setConnectOptions("SSL_KEY=client-key.pem;SSL_CERT=client-cert.pem;SSL_CA=ca-cert.pem;CLIENT_IGNORE_SPACE=1"); // use an SSL connection to the server
if (!db.open()) {
db.setConnectOptions(); // clears the connect option string
- ...
+ // ...
}
-...
+// ...
// PostgreSQL connection
db.setConnectOptions("requiressl=1"); // enable PostgreSQL SSL connections
if (!db.open()) {
db.setConnectOptions(); // clear options
- ...
+ // ...
}
-...
+// ...
// ODBC connection
db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON"); // set ODBC options
if (!db.open()) {
db.setConnectOptions(); // don't try to set this option
- ...
+ // ...
+}
}
//! [4]
-
-//! [5]
-#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"
-//! [5]
-
-
-//! [6]
-PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
-QPSQLDriver *drv = new QPSQLDriver(con);
-QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
-QSqlQuery query;
-query.exec("SELECT NAME, ID FROM STAFF");
-...
-//! [6]
-
-
-//! [7]
-unix:LIBS += -lpq
-win32:LIBS += libpqdll.lib
-//! [7]
-
-
+void dbQdebug()
+{
//! [8]
QSqlDatabase db;
qDebug() << db.isValid(); // Returns false
@@ -143,3 +82,4 @@ qDebug() << db.isValid(); // Returns \c true if "sales" connection exists
QSqlDatabase::removeDatabase("sales");
qDebug() << db.isValid(); // Returns false
//! [8]
+}
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase_snippet.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase_snippet.cpp
new file mode 100644
index 0000000000..b321ad121b
--- /dev/null
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase_snippet.cpp
@@ -0,0 +1,22 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [2]
+QSqlDatabase::registerSqlDriver("MYDRIVER", new QSqlDriverCreator<QSqlDriver>);
+QVERIFY(QSqlDatabase::drivers().contains("MYDRIVER"));
+QSqlDatabase db = QSqlDatabase::addDatabase("MYDRIVER");
+QVERIFY(db.isValid());
+//! [2]
+//! [6]
+PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
+QPSQLDriver *drv = new QPSQLDriver(con);
+QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
+QSqlQuery query;
+query.exec("SELECT NAME, ID FROM STAFF");
+//! [6]
+
+//! [7]
+unix:LIBS += -lpq
+win32:LIBS += libpqdll.lib
+//! [7]
+
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
index a13cf86d3f..3d955cbac9 100644
--- a/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
@@ -1,74 +1,41 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QVariant>
+void checkHandle()
+{
+//dummy definitions
+typedef void sqlite3;
+typedef void PGconn;
+typedef void MYSQL;
//! [0]
-QSqlDatabase db = ...;
+QSqlDatabase db = QSqlDatabase::database();
QVariant v = db.driver()->handle();
-if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
+if (v.isValid() && (qstrcmp(v.typeName(), "sqlite3*") == 0)) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle) {
- ...
+ // ...
}
}
//! [0]
-
//! [1]
if (qstrcmp(v.typeName(), "PGconn*") == 0) {
PGconn *handle = *static_cast<PGconn **>(v.data());
- if (handle) ...
+ if (handle) {
+ // ...
+ }
}
if (qstrcmp(v.typeName(), "MYSQL*") == 0) {
MYSQL *handle = *static_cast<MYSQL **>(v.data());
- if (handle) ...
+ if (handle) {
+ // ...
+ }
}
//! [1]
+}
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp
index 9f6c5da57c..85a0ca6665 100644
--- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp
@@ -1,56 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlQueryModel>
+#include <QSqlError>
+#include <QDebug>
+void checkSqlQueryModel()
+{
//! [0]
QSqlQueryModel model;
model.setQuery("select * from myTable");
if (model.lastError().isValid())
qDebug() << model.lastError();
//! [0]
+}
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp
index b99745c749..b62d5065ce 100644
--- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp
@@ -1,58 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-SELECT forename, surname FROM people;
-//! [0]
-
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QDebug>
+
+void selectEmployees()
+{
//! [1]
QSqlQuery q("select * from employees");
QSqlRecord rec = q.record();
@@ -63,8 +17,6 @@ int nameCol = rec.indexOf("name"); // index of the field "name"
while (q.next())
qDebug() << q.value(nameCol).toString(); // output all names
//! [1]
-
-
//! [2]
QSqlQuery q;
q.prepare("insert into myTable values (?, ?)");
@@ -74,17 +26,10 @@ ints << 1 << 2 << 3 << 4;
q.addBindValue(ints);
QVariantList names;
-names << "Harald" << "Boris" << "Trond" << QVariant(QVariant::String);
+names << "Harald" << "Boris" << "Trond" << QVariant(QMetaType::fromType<QString>());
q.addBindValue(names);
if (!q.execBatch())
qDebug() << q.lastError();
//! [2]
-
-
-//! [3]
-1 Harald
-2 Boris
-3 Trond
-4 NULL
-//! [3]
+}
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery_snippet.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery_snippet.cpp
new file mode 100644
index 0000000000..477f6ad629
--- /dev/null
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery_snippet.cpp
@@ -0,0 +1,11 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [0]
+SELECT forename, surname FROM people;
+//! [0]
+//! [3]
+1 Harald
+2 Boris
+3 Trond
+4 NULL
+//! [3]
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp
index 8ab2baf2a1..a5e135aaf3 100644
--- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp
@@ -1,53 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QSqlError>
+#include <QSqlResult>
+#include <QDebug>
+
+// dummy typedef
+typedef void *sqlite3_stmt;
+
+void insertVariants()
+{
//! [0]
QSqlQuery q;
q.prepare("insert into test (i1, i2, s) values (?, ?, ?)");
@@ -67,29 +31,21 @@ q.bindValue(2, col3);
if (!q.execBatch())
qDebug() << q.lastError();
//! [0]
+}
-
+void querySqlite()
+{
//! [1]
-QSqlQuery query = ...
+QSqlDatabase db = QSqlDatabase::database("sales");
+QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
+
QVariant v = query.result()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*") == 0) {
// v.data() returns a pointer to the handle
sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
if (handle) {
- ...
+ // ...
}
}
//! [1]
-
-
-//! [2]
-if (qstrcmp(v.typeName(), "PGresult*") == 0) {
- PGresult *handle = *static_cast<PGresult **>(v.data());
- if (handle) ...
-}
-
-if (qstrcmp(v.typeName(), "MYSQL_STMT*") == 0) {
- MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
- if (handle) ...
}
-//! [2]
diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult_snippet.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult_snippet.cpp
new file mode 100644
index 0000000000..e17977bf54
--- /dev/null
+++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult_snippet.cpp
@@ -0,0 +1,18 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [2]
+if (qstrcmp(v.typeName(), "PGresult*") == 0) {
+ PGresult *handle = *static_cast<PGresult **>(v.data());
+ if (handle) {
+ // ...
+ }
+}
+
+if (qstrcmp(v.typeName(), "MYSQL_STMT*") == 0) {
+ MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
+ if (handle) {
+ // ...
+ }
+ }
+//! [2]
diff --git a/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp b/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp
index b3a43537a1..6577c02f40 100644
--- a/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp
+++ b/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp
@@ -1,62 +1,23 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QSqlDriver>
+#include <QVariant>
+#include "../sqldatabase/sqldatabase.cpp"
+void MyModel::fetchModel()
+{
+MyModel *myModel = new MyModel;
//! [0]
while (myModel->canFetchMore())
myModel->fetchMore();
//! [0]
-
//! [1]
QSqlQueryModel model;
model.setQuery("select * from MyTable");
if (model.lastError().isValid())
qDebug() << model.lastError();
//! [1]
+}
diff --git a/src/sql/doc/snippets/sqldatabase/CMakeLists.txt b/src/sql/doc/snippets/sqldatabase/CMakeLists.txt
new file mode 100644
index 0000000000..5179c694d0
--- /dev/null
+++ b/src/sql/doc/snippets/sqldatabase/CMakeLists.txt
@@ -0,0 +1,11 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+add_library(sqldatabase_snippets OBJECT
+ sqldatabase.cpp
+)
+
+target_link_libraries(sqldatabase_snippets PRIVATE
+ Qt::Core
+ Qt::Sql
+)
diff --git a/src/sql/doc/snippets/sqldatabase/sqldatabase.cpp b/src/sql/doc/snippets/sqldatabase/sqldatabase.cpp
index bba0487452..5702116365 100644
--- a/src/sql/doc/snippets/sqldatabase/sqldatabase.cpp
+++ b/src/sql/doc/snippets/sqldatabase/sqldatabase.cpp
@@ -1,65 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtGui>
-#include <QtSql>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QCoreApplication>
+#include <QtSql>
#include <iostream>
using namespace std;
-QString tr(const char *text)
-{
- return QApplication::translate(text, text);
-}
-
void QSqlDatabase_snippets()
{
{
@@ -86,7 +33,7 @@ void QSqlField_snippets()
#if 0
{
//! [2]
- QSqlField field("age", QVariant::Int);
+ QSqlField field("age", QMetaType::fromType<int>());
field.setValue(QPixmap()); // WRONG
//! [2]
}
@@ -94,7 +41,7 @@ void QSqlField_snippets()
{
//! [3]
- QSqlField field("age", QVariant::Int);
+ QSqlField field("age", QMetaType::fromType<int>());
field.setValue(QString("123")); // casts QString to int
//! [3]
}
@@ -207,58 +154,28 @@ void QSqlQuery_snippets()
QSqlQuery query;
{
- // examine with named binding
+ // examine with named or positional binding
//! [14]
- QMapIterator<QString, QVariant> i(query.boundValues());
- while (i.hasNext()) {
- i.next();
- cout << i.key().toUtf8().data() << ": "
- << i.value().toString().toUtf8().data() << Qt::endl;
- }
+ const QVariantList list = query.boundValues();
+ for (qsizetype i = 0; i < list.size(); ++i)
+ qDebug() << i << ":" << list.at(i).toString();
//! [14]
}
-
- {
- // examine with positional binding
-//! [15]
- QList<QVariant> list = query.boundValues().values();
- for (int i = 0; i < list.size(); ++i)
- cout << i << ": " << list.at(i).toString().toUtf8().data() << Qt::endl;
-//! [15]
- }
}
void QSqlQueryModel_snippets()
{
- {
-//! [16]
- QSqlQueryModel *model = new QSqlQueryModel;
- model->setQuery("SELECT name, salary FROM employee");
- model->setHeaderData(0, Qt::Horizontal, tr("Name"));
- model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
-
-//! [17]
- QTableView *view = new QTableView;
-//! [17] //! [18]
- view->setModel(model);
-//! [18] //! [19]
- view->show();
-//! [16] //! [19] //! [20]
- view->setEditTriggers(QAbstractItemView::NoEditTriggers);
-//! [20]
- }
//! [21]
- QSqlTableModel model;
- model.setTable("employee");
- model.select();
+ QSqlQueryModel model;
+ model.setQuery("SELECT name, salary FROM employee");
int salary = model.record(4).value("salary").toInt();
//! [21]
Q_UNUSED(salary);
{
//! [22]
- int salary = model.data(model.index(4, 2)).toInt();
+ int salary = model.data(model.index(4, 1)).toInt();
//! [22]
Q_UNUSED(salary);
}
@@ -274,6 +191,7 @@ class MyModel : public QSqlQueryModel
{
public:
QVariant data(const QModelIndex &item, int role) const override;
+ void fetchModel();
int m_specialColumnNo;
};
@@ -290,26 +208,14 @@ QVariant MyModel::data(const QModelIndex &item, int role) const
void QSqlTableModel_snippets()
{
-//! [24]
- QSqlTableModel *model = new QSqlTableModel(parentObject, database);
- model->setTable("employee");
- model->setEditStrategy(QSqlTableModel::OnManualSubmit);
- model->select();
- model->setHeaderData(0, Qt::Horizontal, tr("Name"));
- model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
-
- QTableView *view = new QTableView;
- view->setModel(model);
- view->hideColumn(0); // don't show the ID
- view->show();
-//! [24]
-
{
//! [25]
QSqlTableModel model;
model.setTable("employee");
- QString name = model.record(4).value("name").toString();
+ model.select();
+ int salary = model.record(4).value("salary").toInt();
//! [25]
+ Q_UNUSED(salary);
}
}
@@ -376,6 +282,7 @@ void sql_intro_snippets()
numRows = query.at() + 1;
}
//! [33]
+ Q_UNUSED(numRows);
}
{
@@ -550,14 +457,14 @@ public:
const QString & /* password */, const QString & /* host */,
int /* port */, const QString & /* options */) override
{ return false; }
- void close() {}
+ void close() override {}
QSqlResult *createResult() const override { return new XyzResult(this); }
};
//! [48]
int main(int argc, char **argv)
{
- QApplication app(argc, argv);
+ QCoreApplication app(argc, argv);
QSqlDatabase_snippets();
QSqlField_snippets();
diff --git a/src/sql/doc/snippets/sqldatabase/sqldatabase_snippet.cpp b/src/sql/doc/snippets/sqldatabase/sqldatabase_snippet.cpp
new file mode 100644
index 0000000000..48382bfee9
--- /dev/null
+++ b/src/sql/doc/snippets/sqldatabase/sqldatabase_snippet.cpp
@@ -0,0 +1,84 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [16]
+ QSqlQueryModel *model = new QSqlQueryModel;
+ model->setQuery("SELECT name, salary FROM employee");
+ model->setHeaderData(0, Qt::Horizontal, tr("Name"));
+ model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
+//! [17]
+ QTableView *view = new QTableView;
+//! [17] //! [18]
+ view->setModel(model);
+//! [18] //! [19]
+ view->show();
+//! [16] //! [19] //! [20]
+ view->setEditTriggers(QAbstractItemView::NoEditTriggers);
+//! [20]
+ }
+
+ QSqlQueryModel model;
+ model.setQuery("SELECT name, salary FROM employee");
+ int salary = model.record(4).value("salary").toInt();
+ Q_UNUSED(salary);
+
+ {
+ int salary = model.data(model.index(4, 1)).toInt();
+ Q_UNUSED(salary);
+ }
+
+ for (int row = 0; row < model.rowCount(); ++row) {
+ for (int col = 0; col < model.columnCount(); ++col) {
+ qDebug() << model.data(model.index(row, col));
+ }
+ }
+}
+
+class MyModel : public QSqlQueryModel
+{
+public:
+ QVariant data(const QModelIndex &item, int role) const override;
+ void fetchModel();
+
+ int m_specialColumnNo;
+};
+
+QVariant MyModel::data(const QModelIndex &item, int role) const
+{
+ if (item.column() == m_specialColumnNo) {
+ // handle column separately
+ }
+ return QSqlQueryModel::data(item, role);
+}
+
+void QSqlTableModel_snippets()
+{
+//! [24]
+ QSqlTableModel *model = new QSqlTableModel;
+ model->setTable("employee");
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+ model->select();
+ model->setHeaderData(0, Qt::Horizontal, tr("Name"));
+ model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
+
+ QTableView *view = new QTableView;
+ view->setModel(model);
+ view->hideColumn(0); // don't show the ID
+ view->show();
+//! [24]
+}
+
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QSqlDatabase_snippets();
+ QSqlField_snippets();
+ QSqlQuery_snippets();
+ QSqlQueryModel_snippets();
+ QSqlTableModel_snippets();
+
+ XyzDriver driver;
+ XyzResult result(&driver);
+}
diff --git a/src/sql/doc/src/dontdocument.qdoc b/src/sql/doc/src/dontdocument.qdoc
index 0193ace4b4..3601a9841a 100644
--- a/src/sql/doc/src/dontdocument.qdoc
+++ b/src/sql/doc/src/dontdocument.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\dontdocument (QTypeInfo)
diff --git a/src/sql/doc/src/qsqldatatype-table.qdoc b/src/sql/doc/src/qsqldatatype-table.qdoc
index aafbed6096..77aa56d21a 100644
--- a/src/sql/doc/src/qsqldatatype-table.qdoc
+++ b/src/sql/doc/src/qsqldatatype-table.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page sql-types.html
@@ -64,15 +40,15 @@
\row
\li REAL
\li 32-bit Single-precision floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE PRECISION
\li 64-bit Double-precision floating point
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li FLOAT
\li 64-bit Double-precision floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li CHAR
\li Fixed-length, null-terminated character string
@@ -139,19 +115,19 @@
\row
\li REAL FLOAT
\li 32-bit floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li FLOAT
\li 64-bit floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE
\li 64-bit floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE PRECISION
\li 64-bit Double-precision floating point
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li VARCHAR STRING
\li Character string, Unicode
@@ -212,11 +188,11 @@
\row
\li FLOAT
\li 32-bit Floating Point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE
\li 64-bit Floating Point
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li CHAR
\li Character string
@@ -285,7 +261,7 @@
\row
\li NUMBER
\li FLOAT, DOUBLE, PRECISIONc REAL
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li NUMBER(38)
\li INTEGER INT SMALLINT
@@ -293,7 +269,7 @@
\row
\li NUMBER(p,s)
\li NUMERIC(p,s) DECIMAL(p,s)a
- \li By default mapping to QString
+ \li Mapped to QString
\row
\li NVARCHAR2(n)
\li Character string (NATIONAL CHARACTER VARYING(n) NATIONAL
@@ -353,15 +329,15 @@
\row
\li REAL
\li 32-bit Single-precision floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li FLOAT
\li 64-bit Double floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE
\li 64-bit Double floating point
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li CHAR
\li Character string
@@ -418,19 +394,19 @@
\row
\li REAL
\li 32-bit variable-precision floating point
- \li By default mapping to QString
+ \li typedef qreal
\row
\li DOUBLE PRECISION
\li 64-bit variable-precision floating point
- \li By default mapping to QString
+ \li Mapped to QString for high precision doubles, otherwise qreal
\row
\li DECIMAL VARIABLE
\li user-specified precision, exact
- \li Mapped to QString
+ \li typedef qreal
\row
\li NUMERIC VARIABLE
\li user-specified precision, exact
- \li Mapped to QString
+ \li typedef qreal
\row
\li VARCHAR
\li variable-length character string
@@ -488,7 +464,7 @@
\row
\li REAL
\li 64-bit floating point value.
- \li By default mapping to QString
+ \li typedef qreal
\row
\li TEXT
\li Character string (UTF-8, UTF-16BE or UTF-16-LE).
@@ -503,66 +479,156 @@
\li Mapped to QByteArray
\endtable
- \section2 Sybase Adaptive Server Data Types
+ \section2 Mimer SQL Data Types
\table 90%
\header
- \li Sybase Adaptive Server data type
+ \li Mimer SQL type
\li SQL type description
\li Recommended input (C++ or Qt data type)
\row
- \li BINARY
- \li Describes a fixed-length binary value up to 255 bytes in size.
- \li Mapped to QByteArray
+ \li SMALLINT
+ \li 16-bit signed integer
+ \li typedef qint16
\row
- \li CHAR
- \li Character String
+ \li INTEGER
+ \li 32-bit signed integer
+ \li typedef qint32
+ \row
+ \li INTEGER(n)
+ \li Integer with up to 45 digits precision
\li Mapped to QString
\row
- \li DATETIME
- \li Date and time. Range: 1753-01-01 00:00:00 through 9999-12-31 23:59:59.
- \li Mapped to QDateTime
+ \li BIGINT
+ \li 64-bit signed integer
+ \li typedef qint64
\row
- \li NCHAR
- \li Character String of fixed length
+ \li REAL
+ \li 32-bit Single-precision IEEE floating point
+ \li typedef float
+ \row
+ \li DOUBLE PRECISION
+ \li 64-bit Double-precision IEEE floating point
+ \li Mapped to QString for high precision doubles, otherwise qreal
+ \row
+ \li FLOAT
+ \li 64-bit Double-precision IEEE floating point
+ \li Mapped to QString for high precision doubles, otherwise qreal
+ \row
+ \li FLOAT(n)
+ \li Floating point with up to 45 digits precision
+ \li Mapped to QString
+ \row
+ \li DECIMAL(p,s)
+ \li Decimal with up to 45 digits precision and scale
\li Mapped to QString
\row
- \li NVARACHAR
- \li Character String of variable length
+ \li CHAR
+ \li Fixed-length character Latin-1 string (CHAR or character)
\li Mapped to QString
\row
\li VARCHAR
- \li Character String of fixed length
+ \li Variable length Latin-1 string (VARCHAR or CHARACTER VARYING)
+ \li Mapped to QString
+ \row
+ \li NCHAR
+ \li Fixed-length Unicode string (NCHAR or NATIONAL CHARACTER)
\li Mapped to QString
\row
+ \li NVARCHAR
+ \li Variable length Unicode string (NVARCHAR or NATIONAL CHARACTER VARYING)
+ \li Mapped to QString
+ \row
+ \li BINARY
+ \li Fixed length binary data
+ \li Mapped to QByteArray
+ \row
+ \li VARBINARY
+ \li Variable length binary data (VARBINARY or BINARY VARYING)
+ \li Mapped to QByteArray
+ \row
+ \li BLOB
+ \li Binary large object (BLOB or BINARY LARGE OBJECT)
+ \li Mapped to QByteArray
+ \row
\li CLOB
- \li Character large string object
+ \li Latin-1 character large object (CLOB or CHARACTER LARGE OBJECT)
\li Mapped to QString
\row
- \li TIMESTAMP
- \li A unique number within a database
+ \li NCLOB
+ \li Unicode character large object (NCLOB or NATIONAL CHARACTER LARGE OBJECT)
\li Mapped to QString
\row
- \li SMALLDATETIME
- \li Date and time. Range: 1900-01-01 00:00 through 2079-12-31 23:59
+ \li DATE
+ \li Date consisting of year, month, and day
+ \li Mapped to QDate
+ \row
+ \li TIME
+ \li Time consisting of hours, minute, seconds with optional fractional seconds
+ \li Mapped to QTime
+ \row
+ \li TIMESTAMP
+ \li Date and time with optional fractional seconds
\li Mapped to QDateTime
\row
- \li UNICHAR
- \li Character String of fixed length.(Unicode)
+ \li BUILTIN.UUID
+ \li Universally unique identifier
+ \li Mapped to QUuid
+ \row
+ \li BOOLEAN
+ \li Boolean
+ \li bool
+ \row
+ \li INTERVAL YEAR(7)
+ \li Year, format '±yyyyyyy' (max precision)
\li Mapped to QString
\row
- \li UNIVARCHAR
- \li Character String of variable length.(Unicode)
+ \li INTERVAL YEAR(7) TO MONTH
+ \li Year to month, format '±yyyyyyy-mm' (max precision)
\li Mapped to QString
\row
- \li VARBINARY
- \li Describes a variable-length binary value up to 255 bytes in size
- \li Mapped to QByteArray
+ \li INTERVAL MONTH(7)
+ \li Month, format '±mmmmmmm' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL DAY(7)
+ \li Day, format '±ddddddd' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL DAY(7) TO HOUR
+ \li Day to hour, format '±ddddddd hh' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL DAY(7) TO MINUTE
+ \li Day to minute, format '±ddddddd hh:mm' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL DAY(7) TO SECOND(9)
+ \li Day to second, format '±ddddddd hh:mm:ss[.fffffffff]' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL HOUR(8)
+ \li Hour, format '±hhhhhhhh' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL HOUR(8) TO MINUTE
+ \li Hour to minute, format '±hhhhhhhh:mm' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL HOUR(8) TO SECOND(9)
+ \li Hour to second, format '±hhhhhhhh:mm:ss[.fffffffff]' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL MINUTE(10)
+ \li Minute, format '±mmmmmmmmmm' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL MINUTE(10) TO SECOND(9)
+ \li Minute to second, format '±mmmmmmmmmm:ss[.fffffffff]' (max precision)
+ \li Mapped to QString
+ \row
+ \li INTERVAL SECOND(12,9)
+ \li Second, format '±ssssssssssss[.fffffffff]' (max precision)
+ \li Mapped to QString
\endtable
-
- \section2 SQLite Version 2
-
- SQLite version 2 is "typeless". This means that you can store any kind of
- data you want in any column of any table, regardless of the declared
- data type of that column. We recommend that you map the data to QString.
*/
diff --git a/src/sql/doc/src/qt6-changes.qdoc b/src/sql/doc/src/qt6-changes.qdoc
new file mode 100644
index 0000000000..28c4664fdd
--- /dev/null
+++ b/src/sql/doc/src/qt6-changes.qdoc
@@ -0,0 +1,44 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtsql-changes-qt6.html
+ \title Changes to Qt SQL
+ \ingroup changes-qt-5-to-6
+ \brief The return type for boundValues() has been changed in QSqlQuery class.
+
+ Qt 6 is a result of the conscious effort to make the framework more
+ efficient and easy to use.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+ In this topic we summarize those changes in Qt SQL, and provide guidance
+ to handle them.
+
+ \section1 The QSqlQuery class
+
+ \section2 boundValues() Signature
+
+ The return type for boundValues() has been changed from QMap<QString, QVariant>
+ to a QVariantList. The order can be relied upon so it will be in the order of the
+ binding in the prepared query. Change code like the following:
+
+ \code
+ QMap<QString, QVariant> values = boundValues();
+ int id = values[":id"].value().toInt();
+ \endcode
+
+ \code
+ QList<QVariant> values = boundValues().values();
+ int id = values.at(0).toInt();
+ \endcode
+
+ to:
+
+ \code
+ QList<QVariant> values = boundValues().values();
+ int id = values.at(0).toInt();
+ \endcode
+*/
diff --git a/src/sql/doc/src/qtsql.qdoc b/src/sql/doc/src/qtsql.qdoc
index 39c0e44187..78acaf1fd0 100644
--- a/src/sql/doc/src/qtsql.qdoc
+++ b/src/sql/doc/src/qtsql.qdoc
@@ -1,37 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtsql-index.html
\title Qt SQL
\brief Provides a driver layer, SQL API layer, and a user
interface layer for SQL databases
- Qt SQL is an essential module which provides support for SQL databases. Qt
- SQL's APIs are divided into different layers:
+ The Qt SQL module provides support for SQL databases. Qt SQL's APIs are
+ divided into different layers:
\list
\li Driver layer
@@ -41,22 +17,45 @@
The \l{SQL Programming} guide contains information about development using
Qt SQL.
- \section1 Getting Started
- To enable Qt SQL in a project, add this directive into the C++ files:
- \code
- #include <QtSql>
- \endcode
- To link against the Qt SQL module, add this line to the project file:
- \code
- QT += sql
- \endcode
+ \section1 Using the Module
+
+ \include {module-use.qdocinc} {using the c++ api}
+
+ \section2 Building with CMake
+
+ \include {module-use.qdocinc} {building with cmake} {Sql}
+
+ \section2 Building with qmake
+
+ \include {module-use.qdocinc} {building_with_qmake} {sql}
+
+ \section1 Articles and Guides
+
+ \list
+ \li \l {SQL Programming} {Qt SQL Programming Guide}
+ \endlist
+
+ \section1 Examples
+
+ \list
+ \li \l {SQL Examples}
+ \endlist
+
+ \section1 Reference
+
+ \list
+ \li \l {Qt SQL C++ Classes} {C++ Classes}
+ \endlist
+
+ \section1 Module Evolution
+ \l{Changes to Qt SQL} lists important changes in the module API
+ and functionality that were done for the Qt 6 series of Qt.
\section1 Licenses and Attributions
Qt SQL is available under commercial licenses from \l{The Qt Company}.
- In addition, it is available under free software licenses. Since Qt 5.4,
- these free software licenses are
- \l{GNU Lesser General Public License, version 3}, or
+ In addition, it is available under free software licenses:
+ The \l{GNU Lesser General Public License, version 3}, or
the \l{GNU General Public License, version 2}.
See \l{Qt Licensing} for further details.
@@ -64,36 +63,16 @@
modules under following permissive licenses:
\generatelist{groupsbymodule attributions-qtsql}
-
- \section1 Related Information
-
- These are links to the API reference materials and related pages.
- \list
- \li \l{Qt SQL C++ Classes}{C++ Classes}
- \li \l{SQL Examples}
- \endlist
*/
/*!
\module QtSql
\title Qt SQL C++ Classes
\ingroup modules
+ \qtcmakepackage Sql
\qtvariable sql
\brief Provides a driver layer, SQL API layer, and a user
interface layer for SQL databases.
- To include the definitions of the module's classes, use the
- following directive:
-
- \snippet code/doc_src_qtsql.cpp 0
-
- \if !defined(qtforpython)
- To link against the module, add this line to your \l qmake \c
- .pro file:
-
- \snippet code/doc_src_qtsql.pro 1
- \endif
-
- See the \l{SQL Programming} guide for information about using this
- module in your applications.
+ The \l{Qt SQL} page contains information about how to use the module.
*/
diff --git a/src/sql/doc/src/sql-driver.qdoc b/src/sql/doc/src/sql-driver.qdoc
index 4d6df63749..4cc5b0d050 100644
--- a/src/sql/doc/src/sql-driver.qdoc
+++ b/src/sql/doc/src/sql-driver.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page sql-driver.html
@@ -47,16 +23,15 @@
\table
\header \li Driver name \li DBMS
\row \li \l{#QDB2}{QDB2} \li IBM DB2 (version 7.1 and above)
- \row \li \l{#QIBASE}{QIBASE} \li Borland InterBase
- \row \li \l{#QMYSQL}{QMYSQL / MARIADB} \li MySQL or MariaDB (version 5.0 and above)
- \row \li \l{#QOCI}{QOCI} \li Oracle Call Interface Driver
+ \row \li \l{#QIBASE}{QIBASE} \li Borland InterBase / Firebird
+ \row \li \l{#QMYSQL}{QMYSQL / MARIADB} \li MySQL or MariaDB (version 5.6 and above)
+ \row \li \l{#QOCI}{QOCI} \li Oracle Call Interface Driver (version 12.1 and above)
\row \li \l{#QODBC}{QODBC}
\li Open Database Connectivity (ODBC) - Microsoft SQL Server and other
ODBC-compliant databases
\row \li \l{#QPSQL}{QPSQL} \li PostgreSQL (versions 7.3 and above)
- \row \li \l{#QSQLITE2}{QSQLITE2} \li SQLite version 2 \note obsolete since Qt 5.14
\row \li \l{#QSQLITE}{QSQLITE} \li SQLite version 3
- \row \li \l{#QTDS}{QTDS} \li Sybase Adaptive Server \note obsolete since Qt 4.7
+ \row \li \l{#QMIMER}{QMIMER} \li Mimer SQL (version 11 and above)
\endtable
SQLite is the in-process database system with the best test coverage
@@ -65,7 +40,7 @@
Linux. The completeness of the support for other systems depends on the
availability and quality of client libraries.
- \b{Note:} To build a driver plugin you need to have the appropriate
+ \note To build a driver plugin you need to have the appropriate
client library for your Database Management System (DBMS). This provides
access to the API exposed by the DBMS, and is typically shipped with it.
Most installation programs also allow you to install "development
@@ -79,6 +54,8 @@
\target building
\section1 Building the Drivers
+ \target DriverWithQt
+ \section2 Compile Qt with a specific driver
The Qt \c configure script tries to
automatically detect the available client libraries on your
@@ -89,41 +66,58 @@
The \c configure script cannot detect the necessary libraries
and include files if they are not in the standard paths, so it
- may be necessary to specify these paths using the \c *_INCDIR=,
- \c *_LIBDIR=, or \c *_PREFIX= command-line options. For example,
- if your MySQL files are installed in \c /usr/local/mysql (or in
- \c{C:/Program Files/MySQL/MySQL Connector C 6.1} on Windows), then pass the
- following parameter to configure: \c MYSQL_PREFIX=/usr/local/mysql
- (or \c{MYSQL_PREFIX="C:/Program Files/MySQL/MySQL Connector C 6.1"} for Windows).
+ may be necessary to specify these paths using either
+ driver-specific include and library path variables or \c CMAKE_INCLUDE_PATH
+ and \c CMAKE_LIBRARY_PATH. For example, if your MySQL files are
+ installed in \c{C:\mysql-connector-c-6.1.11-winx64} on Windows, then pass
+ the following parameter to double-dash part of configure line:
+ \snippet code/doc_src_sql-driver.qdoc 42
+ When you configure drivers in the manner described above, CMake skips any
+ dependency checks and uses the provided paths as is. This is especially
+ useful if the package provides its own set of system libraries that
+ should not be recognized by the build routine.
+
+ In some cases it's more convenient to use \c CMAKE_INCLUDE_PATH
+ and \c CMAKE_LIBRARY_PATH variables to locate required libraries.
+ You should prefer this method if module needs to set properties
+ for the provided target libraries (e.g. this is required for PostgreSQL
+ and SQLite).
+ For example, you can do this as follows, to locate MySQL:
+ \snippet code/doc_src_sql-driver.qdoc 43
+
The particulars for each driver are explained below.
- If something goes wrong and you want qmake to recheck your
- available drivers, you must remove \e{config.cache} in
- \e{<QTDIR>/qtbase/src/plugins/sqldrivers} - otherwise qmake will not
- search for the available drivers again. If you encounter an error during
- the qmake stage, open \e{config.log} to see what went wrong.
+ \note If something goes wrong and you want CMake to recheck your
+ available drivers, you might need to remove \e{CMakeCache.txt} from the build
+ directory.
+
+ \target DriverStandalone
+ \section2 Compile only a specific sql driver
- A typical qmake run (in this case to configure for MySQL) looks like this:
+ A typical \c qt-cmake run (in this case to configure for MySQL) looks like this:
\snippet code/doc_src_sql-driver.qdoc 41
+ \note As mentioned in \l{#DriverWithQt}{Compile Qt with a specific driver},
+ if the driver could not be found or is not enabled, start over by removing
+ \e{CMakeCache.txt}.
Due to the practicalities of dealing with external dependencies,
- only the SQLite3 plugin is shipped with binary builds of Qt.
+ only the SQLite plugin is shipped with binary builds of Qt.
+ Binary builds of Qt for Windows also include the ODBC plugin.
To be able to add additional drivers to the Qt installation
without re-building all of Qt, it is possible to configure
and build the \c qtbase/src/plugins/sqldrivers directory outside
of a full Qt build directory. Note that it is not possible to
\e configure each driver separately, only all of them at once.
Drivers can be \e built separately, though.
- If the Qt build is configured with \c{-prefix}, it is necessary to
- install the plugins after building them, too. For example:
- \snippet code/doc_src_sql-driver.qdoc 4
+ \note You need to specify \c{CMAKE_INSTALL_PREFIX}, if you want to install
+ plugins after the build is finished.
\section1 Driver Specifics
\target QMYSQL
- \section2 QMYSQL for MySQL or MariaDB 5 and higher
+ \section2 QMYSQL for MySQL or MariaDB 5.6 and higher
MariaDB is a fork of MySQL intended to remain free and open-source software
under the GNU General Public License. MariaDB intended to maintain high
@@ -133,7 +127,7 @@
\section3 QMYSQL Stored Procedure Support
- MySQL 5 has stored procedure support at the SQL level, but no
+ MySQL has stored procedure support at the SQL level, but no
API to control IN, OUT, and INOUT parameters. Therefore, parameters
have to be set and read using SQL commands instead of QSqlQuery::bindValue().
@@ -145,7 +139,7 @@
\snippet code/doc_src_sql-driver.cpp 2
- \b{Note:} \c{@outval1} and \c{@outval2} are variables local to the current
+ \note \c{@outval1} and \c{@outval2} are variables local to the current
connection and will not be affected by queries sent from another host
or connection.
@@ -157,33 +151,123 @@
To use the embedded MySQL server, simply link the Qt plugin to \c
libmysqld instead of \c libmysqlclient. This can be done by adding
- \c MYSQL_LIBS=-lmysqld to the configure command line.
+ \c{-DMySQL_LIBRARY=<path/to/mysqld/>libmysqld.<so|lib|dylib>} to the configure command line.
Please refer to the MySQL documentation, chapter "libmysqld, the Embedded
MySQL Server Library" for more information about the MySQL embedded server.
+ \section3 Connection options
+ The Qt MySQL/MariaDB plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li CLIENT_COMPRESS
+ \li If set, switches to compressed protocol after successful authentication
+ \row
+ \li CLIENT_FOUND_ROWS
+ \li If set, send found rows instead of affected rows
+ \row
+ \li CLIENT_IGNORE_SPACE
+ \li If set, ignore spaces before '('
+ \row
+ \li CLIENT_NO_SCHEMA
+ \li If set, don't allow database.table.column
+ \row
+ \li CLIENT_INTERACTIVE
+ \li If set, client is treated as interactive
+ \row
+ \li MYSQL_OPT_PROTOCOL
+ \li explicitly specify the protocol to use:\br
+ MYSQL_PROTOCOL_TCP: use tcp connection (ip/hostname specified through setHostname())
+ MYSQL_PROTOCOL_SOCKET: connect through a socket specified in UNIX_SOCKET
+ MYSQL_PROTOCOL_PIPE: connect through a named pipe specified in UNIX_SOCKET
+ MYSQL_PROTOCOL_MEMORY: connect through shared memory specified in MYSQL_SHARED_MEMORY_BASE_NAME
+ \row
+ \li UNIX_SOCKET
+ \li Specifies the socket or named pipe to use, even it's called UNIX_SOCKET it
+ can also be used on windows
+ \row
+ \li MYSQL_SHARED_MEMORY_BASE_NAME
+ \li Specified the shared memory segment name to use
+ \row
+ \li MYSQL_OPT_RECONNECT
+ \li TRUE or 1: Automatically reconnect after connection loss\br
+ FALSE or 0: No automatic reconnect after connection loss (default)\br
+ See \l {https://dev.mysql.com/doc/c-api/8.0/en/c-api-auto-reconnect.html}
+ {Automatic Reconnection Control}
+ \row
+ \li MYSQL_OPT_CONNECT_TIMEOUT
+ \li The connect timeout in seconds
+ \row
+ \li MYSQL_OPT_READ_TIMEOUT
+ \li The timeout in seconds for each attempt to read from the server
+ \row
+ \li MYSQL_OPT_WRITE_TIMEOUT
+ \li The timeout in seconds for each attempt to write to the server
+ \row
+ \li MYSQL_OPT_LOCAL_INFILE
+ \li Set to 1 to enable the support for local
+ \l {https://dev.mysql.com/doc/refman/8.0/en/load-data.html} {LOAD_DATA},
+ disabled if not set or 0
+ \row
+ \li MYSQL_OPT_SSL_MODE
+ \li The security state to use for the connection to the server: SSL_MODE_DISABLED,
+ SSL_MODE_PREFERRED, SSL_MODE_REQUIRED, SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY.
+ \row
+ \li MYSQL_OPT_TLS_VERSION
+ \li A list of protocols the client permits for encrypted connections. The value can be
+ a combination of 'TLSv1' ,' TLSv1.1', 'TLSv1.2' or 'TLSv1.3' depending on the used \l
+ {https://dev.mysql.com/doc/refman/8.0/en/encrypted-connection-protocols-ciphers.html#encrypted-connection-protocol-configuration}
+ {MySQL server} version.
+ \row
+ \li MYSQL_OPT_SSL_KEY / SSL_KEY (deprecated)
+ \li The path name of the client private key file
+ \row
+ \li MYSQL_OPT_SSL_CERT / SSL_CERT (deprecated)
+ \li The path name of the client public key certificate file
+ \row
+ \li MYSQL_OPT_SSL_CA / SSL_CA (deprecated)
+ \li The path name of the Certificate Authority (CA) certificate file
+ \row
+ \li MYSQL_OPT_SSL_CAPATH / SSL_CAPATH (deprecated)
+ \li The path name of the directory that contains trusted SSL CA certificate files
+ \row
+ \li MYSQL_OPT_SSL_CIPHER / SSL_CIPHER (deprecated)
+ \li The list of permissible ciphers for SSL encryption
+ \row
+ \li MYSQL_OPT_SSL_CRL
+ \li The path name of the file containing certificate revocation lists
+ \row
+ \li MYSQL_OPT_SSL_CRLPATH
+ \li The path name of the directory that contains files containing certificate revocation lists
+ \endtable
+ For more detailed information about the connect options please refer
+ to the \l {https://dev.mysql.com/doc/c-api/8.0/en/mysql-options.html}
+ {mysql_options()} MySQL documentation.
+
+
\section3 How to Build the QMYSQL Plugin on Unix and \macos
You need the MySQL / MariaDB header files, as well as the shared library
- \c{libmysqlclient.so} / \c{libmariadb.so}. Depending on your Linux distribution,
+ \c{libmysqlclient.<so|dylib>} / \c{libmariadb.<so|dylib>}. Depending on your Linux distribution,
you may need to install a package which is usually called "mysql-devel"
or "mariadb-devel".
- Tell \l qmake where to find the MySQL / MariaDB header files and shared
+ Tell \c qt-cmake where to find the MySQL / MariaDB header files and shared
libraries (here it is assumed that MySQL / MariaDB is installed in
- \c{/usr/local}) and run \c{make}:
+ \c{/usr/local}) and build:
\snippet code/doc_src_sql-driver.qdoc 3
\section3 How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files (e.g.
- \l {https://dev.mysql.com/downloads/installer/}{mysql-installer-web-community-8.0.18.0.msi}) or
- \l {https://downloads.mariadb.org/connector-c/3.1.5/}{mariadb-connector-c-3.1.5-win64.msi}.
+ \l {https://dev.mysql.com/downloads/installer/}{MySQL web installer} or
+ \l {https://downloads.mariadb.com/Connectors/c/}{MariaDB C Connector}).
Run the installer,
select custom installation and install the MySQL C Connector
which matches your Qt installation (x86 or x64).
- After installation make sure that the needed files are there:
+ After installation check that the needed files are there:
\list
\li \c {<MySQL dir>/lib/libmysql.lib}
\li \c {<MySQL dir>/lib/libmysql.dll}
@@ -196,27 +280,29 @@
\li \c {<MariaDB dir>/include/mysql.h}
\endlist
- Build the plugin as follows (here it is assumed that the MySQL
- C Connector is installed in
- \c{C:/Program Files/MySQL/MySQL Connector C 6.1}):
+ \note As of MySQL 8.0.19, the C Connector is no longer offered as a standalone
+ installable component. Instead, you can get \c{mysql.h} and \c{libmysql.*} by
+ installing the full MySQL Server (x64 only) or the
+ \l{https://downloads.mariadb.org/connector-c/}{MariaDB C Connector}.
- \snippet code/doc_src_sql-driver.qdoc 5
+ Build the plugin as follows (here it is assumed that \c{<MySQL dir>} is
+ \c{C:\mysql-8.0.22-winx64}):
- If you are not using a Microsoft compiler, replace \c nmake with \c
- mingw32-make in the line above.
+ \snippet code/doc_src_sql-driver.qdoc 5
- When you distribute your application, remember to include libmysql.dll / libmariadb.dll
+ When you distribute your application, remember to include \e libmysql.dll / \e libmariadb.dll
in your installation package. It must be placed in the same folder
as the application executable. \e libmysql.dll additionally needs the
- MSVC runtime libraries which can be installed with vcredist.exe
- (\l {https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads}{vcredist.exe}
+ MSVC runtime libraries which can be installed with
+ \l {https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads}{vcredist.exe}
\target QOCI
\section2 QOCI for the Oracle Call Interface (OCI)
- The Qt OCI plugin supports Oracle 9i, 10g and higher. After
- connecting to the Oracle server, the plugin will auto-detect the
- database version and enable features accordingly.
+ The Qt OCI plugin supports connecting to Oracle database as determined by
+ the version of the instant client used. This is dependent on what Oracle
+ indicates it supports. The plugin will auto-detect the database version
+ and enable features accordingly.
It's possible to connect to a Oracle database without a tnsnames.ora file.
This requires that the database SID is passed to the driver as the database
@@ -242,38 +328,50 @@
BLOBs are bound to placeholders or QSqlTableModel, which uses a prepared
query to do this internally.
+ \section3 Connection options
+ The Qt OCI plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li OCI_ATTR_PREFETCH_ROWS
+ \li Sets the OCI attribute
+ \l {https://docs.oracle.com/database/121/LNOCI/oci04sql.htm#LNOCI16355}
+ {OCI_ATTR_PREFETCH_ROWS} to the specified value
+ \row
+ \li OCI_ATTR_PREFETCH_MEMORY
+ \li Sets the OCI attribute
+ \l {https://docs.oracle.com/database/121/LNOCI/oci04sql.htm#LNOCI16355}
+ {OCI_ATTR_PREFETCH_MEMORY} to the specified value
+ \row
+ \li OCI_AUTH_MODE
+ \li OCI_SYSDBA: authenticate for SYSDBA access\br
+ OCI_SYSOPER: authenticate for SYSOPER access\br
+ OCI_DEFAULT: authenticate with normal access\br
+ see \l {https://docs.oracle.com/cd/B10500_01/appdev.920/a96584/oci15r13.htm}
+ {OCISessionBegin} for more information about the access modes
+ \endtable
+
\section3 How to Build the OCI Plugin on Unix and \macos
- For Oracle 10g, all you need is the "Instant Client Package - Basic" and
- "Instant Client Package - SDK". For Oracle prior to 10g, you require
- the standard Oracle client and the SDK packages.
+ All you need is the " - Basic" and "Instant Client
+ Package - SDK".
Oracle library files required to build the driver:
\list
- \li \c libclntsh.so (all versions)
- \li \c libwtc9.so (only Oracle 9)
+ \li \c libclntsh.<so|dylib> (all versions)
\endlist
- Tell \c qmake where to find the Oracle header files and shared
- libraries and run make:
-
- For Oracle version 9:
- \snippet code/doc_src_sql-driver.qdoc 6
+ Tell \c qt-cmake where to find the Oracle header files and shared
+ libraries and build.
- For Oracle version 10, we assume that you installed the RPM packages of the
- Instant Client Package SDK (you need to adjust the version number accordingly):
+ We assume that you installed the RPM packages of the Instant Client Package SDK
+ (you need to adjust the version number accordingly):
\snippet code/doc_src_sql-driver.qdoc 7
- \b{Note:} If you are using the Oracle Instant Client package,
+ \note If you are using the Oracle Instant Client package,
you will need to set LD_LIBRARY_PATH when building the OCI SQL plugin,
- and when running an application that uses the OCI SQL plugin. You can
- avoid this requirement by setting RPATH, and listing all of the
- libraries to link to. Here is an example:
- \snippet code/doc_src_sql-driver.qdoc 32
-
- If you wish to build the OCI plugin manually with this method, the procedure looks like this:
- \snippet code/doc_src_sql-driver.qdoc 33
+ and when running an application that uses the OCI SQL plugin.
\section3 How to Build the OCI Plugin on Windows
@@ -283,13 +381,10 @@
the "Call Interface (OCI)" option if it is available.
Build the plugin as follows (here it is assumed that Oracle Client is
- installed in \c{C:\oracle}):
+ installed in \c{C:\oracle} and SDK is installed in \c{C:\oracle\sdk}):
\snippet code/doc_src_sql-driver.qdoc 8
- If you are not using a Microsoft compiler, replace \c nmake with \c
- mingw32-make in the line above.
-
When you run your application, you will also need to add the \c oci.dll
path to your \c PATH environment variable:
@@ -305,19 +400,24 @@
driver manager that is installed on your system. The QODBC plugin
then allows you to use these data sources in your Qt applications.
- \b{Note:} You should use the native driver, if it is available, instead
+ \note You should use the native driver, if it is available, instead
of the ODBC driver. ODBC support can be used as a fallback for compliant
databases if no native driver is available.
- On Windows, an ODBC driver manager should be installed by default.
+ On Windows, an ODBC driver manager is installed by default.
For Unix systems, there are some implementations which must be
installed first. Note that every end user of your application is
required to have an ODBC driver manager installed, otherwise the
QODBC plugin will not work.
When connecting to an ODBC datasource, you should pass the name
- of the ODBC datasource to the QSqlDatabase::setDatabaseName()
+ of the ODBC datasource (DSN) to the QSqlDatabase::setDatabaseName()
function, rather than the actual database name.
+ It's also possible to pass a FILEDSN (*.dsn) filename or a complete
+ ODBC driver string. When passing a driver string you must make sure,
+ that all parameters (username, password, ...) are properly escaped.
+ Passing the username or password through the QSqlDatabase functions,
+ the escaping is done by the QODBC plugin.
The QODBC Plugin needs an ODBC compliant driver manager version 2.0 or
later. Some ODBC drivers claim to be version-2.0-compliant,
@@ -341,17 +441,11 @@
e.g., the SQLSTATEs. Before setting this connect option, consult
your ODBC documentation about behavior differences you can expect.
- When using the SAP HANA database, the connection has to be
- established using the option "SCROLLABLERESULT=TRUE", as the
- HANA ODBC driver does not provide scrollable results by default, e.g.:
-
- \snippet code/doc_src_sql-driver.cpp 39
-
If you experience very slow access of the ODBC datasource, make sure
that ODBC call tracing is turned off in the ODBC datasource manager.
Some drivers do not support scrollable cursors. In that case, only
- queries in forwardOnly mode can be used successfully.
+ queries in \l QSqlQuery::setForwardOnly() mode can be used successfully.
\section3 ODBC Stored Procedure Support
@@ -362,18 +456,68 @@
\snippet code/doc_src_sql-driver.cpp 10
- \b{Note:} The value returned by the stored procedure's return statement
+ \note The value returned by the stored procedure's return statement
is discarded.
\section3 ODBC Unicode Support
The QODBC Plugin will use the Unicode API if UNICODE is defined. On
- Windows NT based systems, this is the default. Note that the ODBC
+ Windows based systems, this is the default. Note that the ODBC
driver and the DBMS must also support Unicode.
For the Oracle 9 ODBC driver (Windows), it is necessary to check
"SQL_WCHAR support" in the ODBC driver manager otherwise Oracle
- will convert all Unicode strings to local 8-bit.
+ will convert all Unicode strings to local 8-bit representation.
+
+ \section3 Connection options
+ The Qt ODBC plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li SQL_ATTR_ACCESS_MODE
+ \li SQL_MODE_READ_ONLY: open the database in read-only mode\br
+ SQL_MODE_READ_WRITE: open the database in read-write mode (default)
+ \row
+ \li SQL_ATTR_LOGIN_TIMEOUT
+ \li Number of seconds to wait for the database connection
+ during login (a value of 0 will wait forever)
+ \row
+ \li SQL_ATTR_CONNECTION_TIMEOUT
+ \li Number of seconds to wait for any request to the database
+ (a value of 0 will wait forever)
+ \row
+ \li SQL_ATTR_CURRENT_CATALOG
+ \li The catalog (database) to use for this connection
+ \row
+ \li SQL_ATTR_METADATA_ID
+ \li SQL_TRUE: the string argument of catalog functions are treated
+ as identifiers\br
+ SQL_FALSE: the string arguments of catalog functions are not
+ treated as identifiers
+ \row
+ \li SQL_ATTR_PACKET_SIZE
+ \li Specifies the network packet size in bytes
+ \row
+ \li SQL_ATTR_TRACEFILE
+ \li A string containing the name of the trace file
+ \row
+ \li SQL_ATTR_TRACE
+ \li SQL_OPT_TRACE_ON: Enable database query tracing\br
+ SQL_OPT_TRACE_OFF: Disable database query tracing (default)
+ \row
+ \li SQL_ATTR_CONNECTION_POOLING
+ \li Enable or disable connection pooling at the environment level.\br
+ SQL_CP_DEFAULT, SQL_CP_OFF: Connection pooling is turned off (default)\br
+ SQL_CP_ONE_PER_DRIVER: A single connection pool is supported for each driver\br
+ SQL_CP_ONE_PER_HENV: A single connection pool is supported for each environment
+ \row
+ \li SQL_ATTR_ODBC_VERSION
+ \li SQL_OV_ODBC3: The driver should act as a ODBC 3.x driver\br
+ SQL_OV_ODBC2: The driver should act as a ODBC 2.x driver (default)
+ \endtable
+ For more detailed information about the connect options please refer
+ to the \l {https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function}
+ {SQLSetConnectAttr()} ODBC documentation.
\section3 How to Build the ODBC Plugin on Unix and \macos
@@ -381,9 +525,9 @@
version and ODBC drivers at \l http://www.unixodbc.org.
You need the unixODBC header files and shared libraries.
- Tell \c qmake where to find the unixODBC header files and shared
+ Tell \c qt-cmake where to find the unixODBC header files and shared
libraries (here it is assumed that unixODBC is installed in
- \c{/usr/local/unixODBC}) and run \c{make}:
+ \c{/usr/local/unixODBC}) and build:
\snippet code/doc_src_sql-driver.qdoc 11
@@ -394,11 +538,8 @@
\snippet code/doc_src_sql-driver.qdoc 12
- If you are not using a Microsoft compiler, replace \c nmake with \c
- mingw32-make in the line above.
-
\target QPSQL
- \section2 QPSQL for PostgreSQL (Version 7.3 and Above)
+ \section2 QPSQL for PostgreSQL (Version 7.3 and above)
The QPSQL driver supports version 7.3 and higher of the PostgreSQL server.
@@ -455,7 +596,7 @@
SQL result must get a new handle after each call to any of QSqlResult
fetch functions. Example:
- \snippet code/doc_src_sql-driver.cpp 36
+ \snippet code/doc_src_sql-driver_snippet.cpp 36
While reading the results of a forward-only query with PostgreSQL,
the database connection cannot be used to execute other queries.
@@ -467,7 +608,7 @@
database connections, or if we execute query2 after the while loop.
\note Some methods of QSqlDatabase like tables(), primaryIndex()
- implicity execute SQL queries, so these also cannot be used while
+ implicitly execute SQL queries, so these also cannot be used while
navigating the results of forward-only query.
\note QPSQL will print the following warning if it detects a loss of
@@ -475,20 +616,25 @@
\snippet code/doc_src_sql-driver.qdoc 38
+ \section3 Connection options
+ The Qt PostgreSQL plugin honors all connection options specified in the
+ \l {https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS}
+ {connect()} PostgreSQL documentation.
+
\section3 How to Build the QPSQL Plugin on Unix and \macos
You need the PostgreSQL client library and headers installed.
- To make \c qmake find the PostgreSQL header files and shared
- libraries, run \c qmake the following way (assuming that the
- PostgreSQL client is installed in \c{/usr}):
+ To make \c qt-cmake find the PostgreSQL header files and shared
+ libraries, build the plugin the following way (assuming that the
+ PostgreSQL client is installed in \c{/usr/local/pgsql}):
\snippet code/doc_src_sql-driver.qdoc 13
\section3 How to Build the QPSQL Plugin on Windows
Install the appropriate PostgreSQL developer libraries for your
- compiler. Assuming that PostgreSQL was installed in \c{C:\psql},
+ compiler. Assuming that PostgreSQL was installed in \c{C:\pgsql},
build the plugin as follows:
\snippet code/doc_src_sql-driver.qdoc 15
@@ -500,51 +646,8 @@
in your installation package. It must be placed in the same folder
as the application executable.
- \target QTDS
- \section2 QTDS for Sybase Adaptive Server
-
- \note TDS is no longer used by MS Sql Server, and is superseded by
- \l{QODBC}{ODBC}. QTDS is obsolete from Qt 4.7.
-
- It is not possible to set the port with QSqlDatabase::setPort() due to limitations in the
- Sybase client library. Refer to the Sybase documentation for information on how to set up
- a Sybase client configuration file to enable connections to databases on non-default ports.
-
- \section3 How to Build the QTDS Plugin on Unix and \macos
-
- Under Unix, two libraries are available which support the TDS protocol:
-
- \list
- \li FreeTDS, a free implementation of the TDS protocol
- (\l{http://www.freetds.org}).
-
- \li Sybase Open Client, available from \l{https://support.sap.com}.
- \endlist
-
- Regardless of which library you use, the shared object file
- \c{libsybdb.so} is needed. Set the \c SYBASE environment variable to
- point to the directory where you installed the client library and
- execute \c{qmake}:
-
- \snippet code/doc_src_sql-driver.qdoc 16
-
- \section3 How to Build the QDTS Plugin on Windows
-
- You can either use the DB-Library supplied by Microsoft or the Sybase
- Open Client (\l{https://support.sap.com}). Configure will try to find
- NTWDBLIB.LIB to build the plugin:
-
- \snippet code/doc_src_sql-driver.qdoc 17
-
- By default, the Microsoft library is used on Windows. If you want to
- force the use of the Sybase Open Client, you must define \c
- Q_USE_SYBASE in \c{%QTDIR%\qtbase\src\plugins\sqldrivers\tds\qsql_tds.cpp}.
-
- If you are not using a Microsoft compiler, replace \c nmake
- with \c mingw32-make in the line above.
-
\target QDB2
- \section2 QDB2 for IBM DB2 (Version 7.1 and Above)
+ \section2 QDB2 for IBM DB2 (Version 7.1 and above)
The Qt DB2 plugin makes it possible to access IBM DB2 databases. It
has been tested with IBM DB2 v7.1 and 7.2. You must install the IBM
@@ -557,6 +660,20 @@
We suggest using a forward-only query when calling stored procedures
in DB2 (see QSqlQuery::setForwardOnly()).
+ \section3 Connection options
+ The Qt IBM DB2 plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li SQL_ATTR_ACCESS_MODE
+ \li SQL_MODE_READ_ONLY: open the database in read-only mode\br
+ SQL_MODE_READ_WRITE: open the database in read-write mode (default)
+ \row
+ \li SQL_ATTR_LOGIN_TIMEOUT
+ \li Number of seconds to wait for the database connection
+ during login (max: 32767, a value of 0 will wait forever)
+ \endtable
+
\section3 How to Build the QDB2 Plugin on Unix and \macos
\snippet code/doc_src_sql-driver.qdoc 18
@@ -568,18 +685,8 @@
\snippet code/doc_src_sql-driver.qdoc 20
- If you are not using a Microsoft compiler, replace \c nmake
- with \c mingw32-make in the line above.
-
- \target QSQLITE2
- \section2 QSQLITE2 for SQLite Version 2
-
- The Qt SQLite 2 plugin is offered for compatibility. Whenever
- possible, use the \l{#QSQLITE}{version 3 plugin} instead. The
- build instructions for version 3 apply to version 2 as well.
-
\target QSQLITE
- \section2 QSQLITE for SQLite (Version 3 and Above)
+ \section2 QSQLITE for SQLite (Version 3 and above)
The Qt SQLite plugin makes it possible to access SQLite
databases. SQLite is an in-process database, which means that it
@@ -612,24 +719,77 @@
You can find information about SQLite on \l{http://www.sqlite.org}.
+ \section3 Connection options
+ The Qt SQLite plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li QSQLITE_BUSY_TIMEOUT
+ \li Busy handler timeout in milliseconds (val <= 0: disabled),
+ see \l {https://www.sqlite.org/c3ref/busy_timeout.html}
+ {SQLite documentation} for more information
+
+ \row
+ \li QSQLITE_USE_QT_VFS
+ \li If set, the database is opened using Qt's VFS which allows to
+ open databases using QFile. This way it can open databases from
+ any read-write locations (e.g.android shared storage) but also
+ from read-only resources (e.g. qrc or android assets). Be aware
+ that when opening databases from read-only resources make sure
+ you add QSQLITE_OPEN_READONLY attribute as well.
+ Otherwise it will fail to open it.
+
+ \row
+ \li QSQLITE_OPEN_READONLY
+ \li If set, the database is open in read-only mode which will fail
+ if no database exists. Otherwise the database will be opened in
+ read-write mode and created if the database file does not yet
+ exist (default)
+ \row
+ \li QSQLITE_OPEN_URI
+ \li The given filename is interpreted as an uri, see
+ \l {https://www.sqlite.org/c3ref/open.html} {SQLITE_OPEN_URI}
+ \row
+ \li QSQLITE_ENABLE_SHARED_CACHE
+ \li If set, the database is opened in
+ \l {https://www.sqlite.org/sharedcache.html} {shared cache mode},
+ otherwise in private cache mode
+ \row
+ \li QSQLITE_ENABLE_REGEXP
+ \li If set, the plugin defines a function 'regex' which can be used
+ in queries, QRegularExpression is used for evaluation of the regex query
+ \row
+ \li QSQLITE_NO_USE_EXTENDED_RESULT_CODES
+ \li Disables the usage of the \l {https://www.sqlite.org/c3ref/extended_result_codes.html}
+ {extended result code} feature in SQLite
+ \row
+ \li QSQLITE_ENABLE_NON_ASCII_CASE_FOLDING
+ \li If set, the plugin replaces the functions 'lower' and 'upper' with
+ QString functions for correct case folding of non-ascii characters
+ \row
+ \li QSQLITE_OPEN_NOFOLLOW
+ \li If set, the database filename is not allowed to contain a symbolic link
+ \endtable
+
\section3 How to Build the QSQLITE Plugin
SQLite version 3 is included as a third-party library within Qt.
- It can be built by passing the \c{-qt-sqlite} parameter to the
- configure script.
+ It can be built by passing the \c{-DFEATURE_system_sqlite=OFF} parameter to the
+ \c qt-cmake command line.
If you do not want to use the SQLite library included with Qt, you
- can pass \c{-system-sqlite} to the configure script to use the SQLite
- libraries of the operating system. This is recommended whenever possible,
- as it reduces the installation size and removes one component for which
- you need to track security advisories.
+ can pass \c{-DFEATURE_system_sqlite=ON} to the \c qt-cmake command
+ line to use the SQLite libraries of the operating system. This is
+ recommended whenever possible, as it reduces the installation size
+ and removes one component for which you need to track security
+ advisories.
On Unix and \macos (replace \c $SQLITE with the directory where
SQLite resides):
\snippet code/doc_src_sql-driver.qdoc 21
- On Windows:
+ On Windows (assuming that SQLite is installed in \c{C:\SQLITE}):
\snippet code/doc_src_sql-driver.qdoc 23
@@ -666,6 +826,47 @@
Some versions of SQLite can be forced to write a specific file format by setting
the \c{SQLITE_DEFAULT_FILE_FORMAT} define when building SQLite.
+ \target QMIMER
+ \section2 QMIMER for Mimer SQL version 11 and higher
+
+ The Qt Mimer SQL plugin makes it possible to work with the Mimer SQL RDBMS.
+ Mimer SQL provides small footprint, scalable and robust relational database
+ solutions that conform to international ISO SQL standards. Mimer SQL is available
+ on Windows, Linux, \macos, and OpenVMS as well as several embedded platforms like QNX, Android,
+ and embedded Linux.
+
+ Mimer SQL fully support Unicode. To work with Unicode data the column types National Character (NCHAR),
+ National Character Varying (NVARCHAR), or National Character Large Object (NCLOB) must be used.
+ For more information about Mimer SQL and unicode, see \l{https://developer.mimer.com/features/multilingual-support}
+
+ \section3 QMIMER Stored Procedure Support
+
+ Mimer SQL have stored procedures according to the SQL standard (PSM) and
+ the plugin fully support IN, OUT, INOUT parameters as well as resultset procedures.
+
+ Example stored procedure with INOUT and OUT parameters:
+
+ \snippet code/doc_src_sql-driver.qdoc 44
+
+ Source code to access the INOUT and OUT values:
+
+ \snippet code/doc_src_sql-driver.cpp 40
+
+ \section3 How to Build the QMIMER Plugin on Unix and \macos
+
+ You need the Mimer SQL header files and shared libraries. Get them by installing
+ any of the Mimer SQL variants found at \l{https://developer.mimer.com}.
+
+
+ \snippet code/doc_src_sql-driver.qdoc 31
+
+ \section3 How to Build the QMIMER Plugin on Windows
+
+ You need the Mimer SQL header files and shared libraries. Get them by installing
+ any of the Mimer SQL variants found at \l{https://developer.mimer.com}.
+
+ \snippet code/doc_src_sql-driver.qdoc 32
+
\target QIBASE
\section2 QIBASE for Borland InterBase
@@ -679,6 +880,17 @@
database file, no matter whether it is stored locally or on another
server.
+ \section3 Connection options
+ The Qt Borland InterBase plugin honors the following connection options:
+ \table
+ \header \li Attribute \li Possible value
+ \row
+ \li ISC_DPB_SQL_ROLE_NAME
+ \li Specifies the login role name
+ \endtable
+
+
+ \section3 How to Build the QIBASE Plugin
\snippet code/doc_src_sql-driver.cpp 24
You need the InterBase/Firebird development headers and libraries
@@ -688,20 +900,6 @@
Edition are not allowed to link this plugin to the commercial editions of
InterBase. Please use Firebird or the free edition of InterBase.
- \section3 QIBASE Unicode Support and Text Encoding
-
- By default the driver connects to the database using UNICODE_FSS. This can
- be overridden by setting the ISC_DPB_LC_CTYPE parameter with
- QSqlDatabase::setConnectOptions() before opening the connection.
-
- \snippet code/doc_src_sql-driver.cpp 25
-
- If Qt does not support the given text encoding the driver will issue a
- warning message and connect to the database using UNICODE_FSS.
-
- Note that if the text encoding set when connecting to the database is
- not the same as in the database, problems with transliteration might arise.
-
\section3 QIBASE Stored procedures
InterBase/Firebird return OUT values as result set, so when calling stored
@@ -732,13 +930,10 @@
\snippet code/doc_src_sql-driver.qdoc 29
- If you are using Firebird, the Firebird library has to be set explicitly:
+ If you are using Firebird:
\snippet code/doc_src_sql-driver.qdoc 30
- If you are not using a Microsoft compiler, replace \c nmake
- with \c mingw32-make in the line above.
-
Note that \c{C:\interbase\bin} must be in the \c PATH.
\target troubleshooting
@@ -746,7 +941,7 @@
You should always use client libraries that have been compiled with
the same compiler as you are using for your project. If you cannot get
- a source distibution to compile the client libraries yourself, you
+ a source distribution to compile the client libraries yourself, you
must make sure that the pre-compiled library is compatible with
your compiler, otherwise you will get a lot of "undefined symbols"
errors. Some compilers have tools to convert libraries, e.g. Borland
@@ -767,7 +962,7 @@
Qt Creator, you can update the \c PATH environment variable in the
\gui Run section of the \gui Project panel to include the path to
the folder containing the client libraries.
- \li Compile Qt with \c{QT_DEBUG_COMPONENT} defined to get very verbose
+ \li Compile Qt with \c{QT_DEBUG_PLUGINS} defined to get very verbose
debug output when loading plugins.
\endlist
diff --git a/src/sql/doc/src/sql-programming.qdoc b/src/sql/doc/src/sql-programming.qdoc
index ece89a30ab..a7f87fe73f 100644
--- a/src/sql/doc/src/sql-programming.qdoc
+++ b/src/sql/doc/src/sql-programming.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group database
@@ -105,7 +81,6 @@
\page sql-connecting.html
\title Connecting to Databases
- \contentspage SQL Programming
\previouspage SQL Programming
\nextpage Executing SQL Statements
@@ -175,7 +150,6 @@
\title Executing SQL Statements
\previouspage Connecting to Databases
- \contentspage SQL Programming
\nextpage Using the SQL Model Classes
@@ -325,7 +299,6 @@
\title Using the SQL Model Classes
\previouspage Executing SQL Statements
- \contentspage SQL Programming
\nextpage Presenting Data in a Table View
In addition to QSqlQuery, Qt offers three higher-level classes
@@ -471,7 +444,6 @@
\title Presenting Data in a Table View
\previouspage Using the SQL Model Classes
- \contentspage SQL Programming
\nextpage Creating Data-Aware Forms
The QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel
@@ -484,15 +456,15 @@
The following example creates a view based on an SQL data model:
- \snippet sqldatabase/sqldatabase.cpp 17
- \snippet sqldatabase/sqldatabase.cpp 18
- \snippet sqldatabase/sqldatabase.cpp 19
+ \snippet sqldatabase/sqldatabase_snippet.cpp 17
+ \snippet sqldatabase/sqldatabase_snippet.cpp 18
+ \snippet sqldatabase/sqldatabase_snippet.cpp 19
If the model is a read-write model (e.g., QSqlTableModel), the
view lets the user edit the fields. You can disable this by
calling
- \snippet sqldatabase/sqldatabase.cpp 20
+ \snippet sqldatabase/sqldatabase_snippet.cpp 20
You can use the same model as a data source for multiple views.
If the user edits the model through one of the views, the other
@@ -524,11 +496,11 @@
submitted.
The items in the view are rendered using a delegate. The default
- delegate, QItemDelegate, handles the most common data types (\c
+ delegate, QStyledItemDelegate, handles the most common data types (\c
int, QString, QImage, etc.). The delegate is also responsible for
providing editor widgets (e.g., a combobox) when the user starts
editing an item in the view. You can create your own delegates by
- subclassing QAbstractItemDelegate or QItemDelegate. See
+ subclassing QAbstractItemDelegate or QStyledItemDelegate. See
\l{Model/View Programming} for more information.
QSqlTableModel is optimized to operate on a single table at a
@@ -575,7 +547,6 @@
\title Creating Data-Aware Forms
\previouspage Presenting Data in a Table View
- \contentspage SQL Programming
Using the SQL models described above, the contents of a database can
be presented to other model/view components. For some applications,
diff --git a/src/sql/kernel/kernel.pri b/src/sql/kernel/kernel.pri
deleted file mode 100644
index fd6ace8277..0000000000
--- a/src/sql/kernel/kernel.pri
+++ /dev/null
@@ -1,27 +0,0 @@
-HEADERS += kernel/qtsqlglobal.h \
- kernel/qtsqlglobal_p.h \
- kernel/qsqlquery.h \
- kernel/qsqldatabase.h \
- kernel/qsqlfield.h \
- kernel/qsqlrecord.h \
- kernel/qsqldriver.h \
- kernel/qsqldriver_p.h \
- kernel/qsqlnulldriver_p.h \
- kernel/qsqldriverplugin.h \
- kernel/qsqlerror.h \
- kernel/qsqlresult.h \
- kernel/qsqlresult_p.h \
- kernel/qsqlcachedresult_p.h \
- kernel/qsqlindex.h
-
-SOURCES += kernel/qsqlquery.cpp \
- kernel/qsqldatabase.cpp \
- kernel/qsqlfield.cpp \
- kernel/qsqlrecord.cpp \
- kernel/qsqldriver.cpp \
- kernel/qsqldriverplugin.cpp \
- kernel/qsqlerror.cpp \
- kernel/qsqlresult.cpp \
- kernel/qsqlindex.cpp \
- kernel/qsqlcachedresult.cpp
-
diff --git a/src/sql/kernel/qsql.qdoc b/src/sql/kernel/qsql.qdoc
index aec666f381..71e9f2e986 100644
--- a/src/sql/kernel/qsql.qdoc
+++ b/src/sql/kernel/qsql.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\namespace QSql
diff --git a/src/sql/kernel/qsqlcachedresult.cpp b/src/sql/kernel/qsqlcachedresult.cpp
index 1e76154f82..3cc0b6419a 100644
--- a/src/sql/kernel/qsqlcachedresult.cpp
+++ b/src/sql/kernel/qsqlcachedresult.cpp
@@ -1,47 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "private/qsqlcachedresult_p.h"
#include <qvariant.h>
-#include <qdatetime.h>
-#include <qvector.h>
#include <QtSql/private/qsqldriver_p.h>
QT_BEGIN_NAMESPACE
@@ -58,7 +20,7 @@ QT_BEGIN_NAMESPACE
to indicate that we are not interested in the actual values.
*/
-static const uint initial_cache_size = 128;
+static constexpr qsizetype initial_cache_size = 128;
void QSqlCachedResultPrivate::cleanup()
{
@@ -258,7 +220,7 @@ bool QSqlCachedResult::cacheNext()
if (d->atEnd)
return false;
- if(isForwardOnly()) {
+ if (isForwardOnly()) {
d->cache.resize(d->colCount);
}
diff --git a/src/sql/kernel/qsqlcachedresult_p.h b/src/sql/kernel/qsqlcachedresult_p.h
index 1bca1fd090..b8eefceee6 100644
--- a/src/sql/kernel/qsqlcachedresult_p.h
+++ b/src/sql/kernel/qsqlcachedresult_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLCACHEDRESULT_P_H
#define QSQLCACHEDRESULT_P_H
@@ -54,11 +18,11 @@
#include <QtSql/private/qtsqlglobal_p.h>
#include "QtSql/qsqlresult.h"
#include "QtSql/private/qsqlresult_p.h"
+#include <QtCore/qcontainerfwd.h>
QT_BEGIN_NAMESPACE
class QVariant;
-template <typename T> class QVector;
class QSqlCachedResultPrivate;
@@ -67,7 +31,7 @@ class Q_SQL_EXPORT QSqlCachedResult: public QSqlResult
Q_DECLARE_PRIVATE(QSqlCachedResult)
public:
- typedef QVector<QVariant> ValueCache;
+ typedef QList<QVariant> ValueCache;
protected:
QSqlCachedResult(QSqlCachedResultPrivate &d);
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index 32338c1fe2..fdbb16a589 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -1,92 +1,74 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqldatabase.h"
#include "qsqlquery.h"
-#include "qdebug.h"
+#include "qloggingcategory.h"
#include "qcoreapplication.h"
#include "qreadwritelock.h"
-#include "qsqlresult.h"
#include "qsqldriver.h"
+#include "qsqldriver_p.h"
#include "qsqldriverplugin.h"
#include "qsqlindex.h"
+#include "QtCore/qapplicationstatic.h"
#include "private/qfactoryloader_p.h"
#include "private/qsqlnulldriver_p.h"
-#include "qmutex.h"
#include "qhash.h"
#include "qthread.h"
-#include <stdlib.h>
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QSqlDriverFactoryInterface_iid,
- QLatin1String("/sqldrivers")))
-
-const char *QSqlDatabase::defaultConnection = const_cast<char *>("qt_sql_default_connection");
+static Q_LOGGING_CATEGORY(lcSqlDb, "qt.sql.qsqldatabase")
-typedef QHash<QString, QSqlDriverCreatorBase*> DriverDict;
+using namespace Qt::StringLiterals;
-class QConnectionDict: public QHash<QString, QSqlDatabase>
-{
-public:
- inline bool contains_ts(const QString &key)
- {
- QReadLocker locker(&lock);
- return contains(key);
+#define CHECK_QCOREAPPLICATION \
+ if (Q_UNLIKELY(!QCoreApplication::instance())) { \
+ qCWarning(lcSqlDb, "QSqlDatabase requires a QCoreApplication"); \
+ return; \
}
- inline QStringList keys_ts() const
- {
- QReadLocker locker(&lock);
- return keys();
+#define CHECK_QCOREAPPLICATION_RETVAL \
+ if (Q_UNLIKELY(!QCoreApplication::instance())) { \
+ qCWarning(lcSqlDb, "QSqlDatabase requires a QCoreApplication"); \
+ return {}; \
}
- mutable QReadWriteLock lock;
-};
-Q_GLOBAL_STATIC(QConnectionDict, dbDict)
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QSqlDriverFactoryInterface_iid, "/sqldrivers"_L1))
+
+const char *QSqlDatabase::defaultConnection = "qt_sql_default_connection";
+
+namespace {
+ struct QtSqlGlobals
+ {
+ ~QtSqlGlobals();
+ QSqlDatabase connection(const QString &key) const
+ {
+ QReadLocker locker(&lock);
+ return connections.value(key);
+ }
+ bool connectionExists(const QString &key) const
+ {
+ QReadLocker locker(&lock);
+ return connections.contains(key);
+ }
+ QStringList connectionNames() const
+ {
+ QReadLocker locker(&lock);
+ return connections.keys();
+ }
+ mutable QReadWriteLock lock;
+ QHash<QString, QSqlDriverCreatorBase*> registeredDrivers;
+ QHash<QString, QSqlDatabase> connections;
+ };
+}
+Q_APPLICATION_STATIC(QtSqlGlobals, s_sqlGlobals)
class QSqlDatabasePrivate
{
public:
- QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = nullptr):
+ QSqlDatabasePrivate(QSqlDriver *dr):
ref(1),
- q(d),
driver(dr),
port(-1)
{
@@ -99,7 +81,6 @@ public:
void disable();
QAtomicInt ref;
- QSqlDatabase *q;
QSqlDriver* driver;
QString dbname;
QString uname;
@@ -116,13 +97,10 @@ public:
static void addDatabase(const QSqlDatabase &db, const QString & name);
static void removeDatabase(const QString& name);
static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn = true);
- static DriverDict &driverDict();
- static void cleanConnections();
};
QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref(1)
{
- q = other.q;
dbname = other.dbname;
uname = other.uname;
pword = other.pword;
@@ -142,51 +120,25 @@ QSqlDatabasePrivate::~QSqlDatabasePrivate()
delete driver;
}
-void QSqlDatabasePrivate::cleanConnections()
+QtSqlGlobals::~QtSqlGlobals()
{
- QConnectionDict *dict = dbDict();
- Q_ASSERT(dict);
- QWriteLocker locker(&dict->lock);
-
- QConnectionDict::iterator it = dict->begin();
- while (it != dict->end()) {
- invalidateDb(it.value(), it.key(), false);
- ++it;
- }
- dict->clear();
-}
-
-static bool qDriverDictInit = false;
-static void cleanDriverDict()
-{
- qDeleteAll(QSqlDatabasePrivate::driverDict());
- QSqlDatabasePrivate::driverDict().clear();
- QSqlDatabasePrivate::cleanConnections();
- qDriverDictInit = false;
-}
-
-DriverDict &QSqlDatabasePrivate::driverDict()
-{
- static DriverDict dict;
- if (!qDriverDictInit) {
- qDriverDictInit = true;
- qAddPostRoutine(cleanDriverDict);
- }
- return dict;
+ qDeleteAll(registeredDrivers);
+ for (const auto &[k, v] : std::as_const(connections).asKeyValueRange())
+ QSqlDatabasePrivate::invalidateDb(v, k, false);
}
QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null()
{
static QSqlNullDriver dr;
- static QSqlDatabasePrivate n(nullptr, &dr);
+ static QSqlDatabasePrivate n(&dr);
return &n;
}
void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn)
{
if (db.d->ref.loadRelaxed() != 1 && doWarn) {
- qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
- "all queries will cease to work.", name.toLocal8Bit().constData());
+ qCWarning(lcSqlDb, "QSqlDatabasePrivate::removeDatabase: connection '%ls' is still in use, "
+ "all queries will cease to work.", qUtf16Printable(name));
db.d->disable();
db.d->connName.clear();
}
@@ -194,28 +146,28 @@ void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &na
void QSqlDatabasePrivate::removeDatabase(const QString &name)
{
- QConnectionDict *dict = dbDict();
- Q_ASSERT(dict);
- QWriteLocker locker(&dict->lock);
+ CHECK_QCOREAPPLICATION
+ QtSqlGlobals *sqlGlobals = s_sqlGlobals();
+ QWriteLocker locker(&sqlGlobals->lock);
- if (!dict->contains(name))
+ if (!sqlGlobals->connections.contains(name))
return;
- invalidateDb(dict->take(name), name);
+ invalidateDb(sqlGlobals->connections.take(name), name);
}
void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &name)
{
- QConnectionDict *dict = dbDict();
- Q_ASSERT(dict);
- QWriteLocker locker(&dict->lock);
-
- if (dict->contains(name)) {
- invalidateDb(dict->take(name), name);
- qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old "
- "connection removed.", name.toLocal8Bit().data());
+ CHECK_QCOREAPPLICATION
+ QtSqlGlobals *sqlGlobals = s_sqlGlobals();
+ QWriteLocker locker(&sqlGlobals->lock);
+
+ if (sqlGlobals->connections.contains(name)) {
+ invalidateDb(sqlGlobals->connections.take(name), name);
+ qCWarning(lcSqlDb, "QSqlDatabasePrivate::addDatabase: duplicate connection name '%ls', old "
+ "connection removed.", qUtf16Printable(name));
}
- dict->insert(name, db);
+ sqlGlobals->connections.insert(name, db);
db.d->connName = name;
}
@@ -223,22 +175,18 @@ void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &nam
*/
QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)
{
- const QConnectionDict *dict = dbDict();
- Q_ASSERT(dict);
-
- dict->lock.lockForRead();
- QSqlDatabase db = dict->value(name);
- dict->lock.unlock();
+ CHECK_QCOREAPPLICATION_RETVAL
+ QSqlDatabase db = s_sqlGlobals()->connection(name);
if (!db.isValid())
return db;
if (db.driver()->thread() != QThread::currentThread()) {
- qWarning("QSqlDatabasePrivate::database: requested database does not belong to the calling thread.");
+ qCWarning(lcSqlDb, "QSqlDatabasePrivate::database: requested database does not belong to the calling thread.");
return QSqlDatabase();
}
if (open && !db.isOpen()) {
if (!db.open())
- qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
+ qCWarning(lcSqlDb) << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
}
return db;
@@ -250,7 +198,6 @@ QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)
*/
void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other)
{
- q = other->q;
dbname = other->dbname;
uname = other->uname;
pword = other->pword;
@@ -336,6 +283,10 @@ void QSqlDatabasePrivate::disable()
QSqlDriver. Alternatively, you can subclass your own database
driver from QSqlDriver. See \l{How to Write Your Own Database
Driver} for more information.
+ A QSqlDatabase instance must only be accessed by the thread it
+ was created in. Therefore you have to make sure to create them
+ in the correct context. Alternatively you can change the context
+ with QSqlDatabase::moveToThread().
Create a connection (i.e., an instance of QSqlDatabase) by calling
one of the static addDatabase() functions, where you specify
@@ -427,9 +378,6 @@ void QSqlDatabasePrivate::disable()
\li registers a custom-made driver
\endtable
- \note QSqlDatabase::exec() is deprecated. Use QSqlQuery::exec()
- instead.
-
\note When using transactions, you must start the
transaction before you create your query.
@@ -533,23 +481,25 @@ void QSqlDatabase::removeDatabase(const QString& connectionName)
QStringList QSqlDatabase::drivers()
{
+ CHECK_QCOREAPPLICATION_RETVAL
QStringList list;
if (QFactoryLoader *fl = loader()) {
typedef QMultiMap<int, QString> PluginKeyMap;
- typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
const PluginKeyMap keyMap = fl->keyMap();
- const PluginKeyMapConstIterator cend = keyMap.constEnd();
- for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it)
- if (!list.contains(it.value()))
- list << it.value();
+ for (const QString &val : keyMap) {
+ if (!list.contains(val))
+ list << val;
+ }
}
- DriverDict dict = QSqlDatabasePrivate::driverDict();
- for (DriverDict::const_iterator i = dict.constBegin(); i != dict.constEnd(); ++i) {
- if (!list.contains(i.key()))
- list << i.key();
+ QtSqlGlobals *sqlGlobals = s_sqlGlobals();
+ QReadLocker locker(&sqlGlobals->lock);
+ const auto &dict = sqlGlobals->registeredDrivers;
+ for (const auto &[k, _] : dict.asKeyValueRange()) {
+ if (!list.contains(k))
+ list << k;
}
return list;
@@ -561,7 +511,7 @@ QStringList QSqlDatabase::drivers()
and don't want to compile it as a plugin.
Example:
- \snippet code/src_sql_kernel_qsqldatabase.cpp 2
+ \snippet code/src_sql_kernel_qsqldatabase_snippet.cpp 2
QSqlDatabase takes ownership of the \a creator pointer, so you
mustn't delete it yourself.
@@ -570,9 +520,12 @@ QStringList QSqlDatabase::drivers()
*/
void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase *creator)
{
- delete QSqlDatabasePrivate::driverDict().take(name);
+ CHECK_QCOREAPPLICATION
+ QtSqlGlobals *sqlGlobals = s_sqlGlobals();
+ QWriteLocker locker(&sqlGlobals->lock);
+ delete sqlGlobals->registeredDrivers.take(name);
if (creator)
- QSqlDatabasePrivate::driverDict().insert(name, creator);
+ sqlGlobals->registeredDrivers.insert(name, creator);
}
/*!
@@ -586,7 +539,8 @@ void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase
bool QSqlDatabase::contains(const QString& connectionName)
{
- return dbDict()->contains_ts(connectionName);
+ CHECK_QCOREAPPLICATION_RETVAL
+ return s_sqlGlobals()->connectionExists(connectionName);
}
/*!
@@ -598,7 +552,8 @@ bool QSqlDatabase::contains(const QString& connectionName)
*/
QStringList QSqlDatabase::connectionNames()
{
- return dbDict()->keys_ts();
+ CHECK_QCOREAPPLICATION_RETVAL
+ return s_sqlGlobals()->connectionNames();
}
/*!
@@ -619,8 +574,7 @@ QStringList QSqlDatabase::connectionNames()
\row \li QODBC \li ODBC Driver (includes Microsoft SQL Server)
\row \li QPSQL \li PostgreSQL Driver
\row \li QSQLITE \li SQLite version 3 or above
- \row \li QSQLITE2 \li SQLite version 2
- \row \li QTDS \li Sybase Adaptive Server
+ \row \li QMIMER \li Mimer SQL 11 or above
\endtable
Additional third party drivers, including your own custom
@@ -630,8 +584,8 @@ QStringList QSqlDatabase::connectionNames()
*/
QSqlDatabase::QSqlDatabase(const QString &type)
+ : d(new QSqlDatabasePrivate(nullptr))
{
- d = new QSqlDatabasePrivate(this);
d->init(type);
}
@@ -642,8 +596,8 @@ QSqlDatabase::QSqlDatabase(const QString &type)
*/
QSqlDatabase::QSqlDatabase(QSqlDriver *driver)
+ : d(new QSqlDatabasePrivate(driver))
{
- d = new QSqlDatabasePrivate(this, driver);
}
/*!
@@ -652,8 +606,8 @@ QSqlDatabase::QSqlDatabase(QSqlDriver *driver)
objects.
*/
QSqlDatabase::QSqlDatabase()
+ : d(QSqlDatabasePrivate::shared_null())
{
- d = QSqlDatabasePrivate::shared_null();
d->ref.ref();
}
@@ -683,27 +637,27 @@ QSqlDatabase &QSqlDatabase::operator=(const QSqlDatabase &other)
void QSqlDatabasePrivate::init(const QString &type)
{
+ CHECK_QCOREAPPLICATION
drvName = type;
if (!driver) {
- DriverDict dict = QSqlDatabasePrivate::driverDict();
- for (DriverDict::const_iterator it = dict.constBegin();
- it != dict.constEnd() && !driver; ++it) {
- if (type == it.key()) {
- driver = ((QSqlDriverCreatorBase*)(*it))->createObject();
- }
- }
+ QtSqlGlobals *sqlGlobals = s_sqlGlobals();
+ QReadLocker locker(&sqlGlobals->lock);
+ const auto &dict = sqlGlobals->registeredDrivers;
+ auto it = dict.find(type);
+ if (it != dict.end())
+ driver = it.value()->createObject();
}
if (!driver && loader())
driver = qLoadPlugin<QSqlDriver, QSqlDriverPlugin>(loader(), type);
if (!driver) {
- qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data());
- qWarning("QSqlDatabase: available drivers: %s",
- QSqlDatabase::drivers().join(QLatin1Char(' ')).toLatin1().data());
+ qCWarning(lcSqlDb, "QSqlDatabase: %ls driver not loaded", qUtf16Printable(type));
+ qCWarning(lcSqlDb, "QSqlDatabase: available drivers: %ls",
+ qUtf16Printable(QSqlDatabase::drivers().join(u' ')));
if (QCoreApplication::instance() == nullptr)
- qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
+ qCWarning(lcSqlDb, "QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
driver = shared_null()->driver;
}
}
@@ -732,8 +686,9 @@ QSqlDatabase::~QSqlDatabase()
lastError() is not affected.
\sa QSqlQuery, lastError()
+ \deprecated [6.6] Use QSqlQuery::exec() instead.
*/
-
+#if QT_DEPRECATED_SINCE(6, 6)
QSqlQuery QSqlDatabase::exec(const QString & query) const
{
QSqlQuery r(d->driver->createResult());
@@ -743,6 +698,7 @@ QSqlQuery QSqlDatabase::exec(const QString & query) const
}
return r;
}
+#endif
/*!
Opens the database connection using the current connection
@@ -1136,92 +1092,8 @@ QSqlRecord QSqlDatabase::record(const QString& tablename) const
The format of the \a options string is a semicolon separated list
of option names or option=value pairs. The options depend on the
- database client used:
-
- \table
- \header \li ODBC \li MySQL \li PostgreSQL
- \row
-
- \li
- \list
- \li SQL_ATTR_ACCESS_MODE
- \li SQL_ATTR_LOGIN_TIMEOUT
- \li SQL_ATTR_CONNECTION_TIMEOUT
- \li SQL_ATTR_CURRENT_CATALOG
- \li SQL_ATTR_METADATA_ID
- \li SQL_ATTR_PACKET_SIZE
- \li SQL_ATTR_TRACEFILE
- \li SQL_ATTR_TRACE
- \li SQL_ATTR_CONNECTION_POOLING
- \li SQL_ATTR_ODBC_VERSION
- \endlist
-
- \li
- \list
- \li CLIENT_COMPRESS
- \li CLIENT_FOUND_ROWS
- \li CLIENT_IGNORE_SPACE
- \li CLIENT_ODBC
- \li CLIENT_NO_SCHEMA
- \li CLIENT_INTERACTIVE
- \li UNIX_SOCKET
- \li MYSQL_OPT_RECONNECT
- \li MYSQL_OPT_CONNECT_TIMEOUT
- \li MYSQL_OPT_READ_TIMEOUT
- \li MYSQL_OPT_WRITE_TIMEOUT
- \li SSL_KEY
- \li SSL_CERT
- \li SSL_CA
- \li SSL_CAPATH
- \li SSL_CIPHER
- \endlist
-
- \li
- \list
- \li connect_timeout
- \li options
- \li tty
- \li requiressl
- \li service
- \endlist
-
- \header \li DB2 \li OCI \li TDS
- \row
-
- \li
- \list
- \li SQL_ATTR_ACCESS_MODE
- \li SQL_ATTR_LOGIN_TIMEOUT
- \endlist
-
- \li
- \list
- \li OCI_ATTR_PREFETCH_ROWS
- \li OCI_ATTR_PREFETCH_MEMORY
- \endlist
-
- \li
- \e none
-
- \header \li SQLite \li Interbase
- \row
-
- \li
- \list
- \li QSQLITE_BUSY_TIMEOUT
- \li QSQLITE_OPEN_READONLY
- \li QSQLITE_OPEN_URI
- \li QSQLITE_ENABLE_SHARED_CACHE
- \li QSQLITE_ENABLE_REGEXP
- \endlist
-
- \li
- \list
- \li ISC_DPB_LC_CTYPE
- \li ISC_DPB_SQL_ROLE_NAME
- \endlist
-
- \endtable
+ database client used and are described for each plugin in the
+ \l{sql-driver.html}{SQL Database Drivers} page.
Examples:
\snippet code/src_sql_kernel_qsqldatabase.cpp 4
@@ -1262,6 +1134,7 @@ bool QSqlDatabase::isDriverAvailable(const QString& name)
}
/*! \fn QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName)
+ \overload
This overload is useful when you want to create a database
connection with a \l{QSqlDriver} {driver} you instantiated
@@ -1271,9 +1144,7 @@ bool QSqlDatabase::isDriverAvailable(const QString& name)
application. For example, you can create a PostgreSQL connection
with your own QPSQL driver like this:
- \snippet code/src_sql_kernel_qsqldatabase.cpp 5
- \codeline
- \snippet code/src_sql_kernel_qsqldatabase.cpp 6
+ \snippet code/src_sql_kernel_qsqldatabase_snippet.cpp 6
The above code sets up a PostgreSQL connection and instantiates a
QPSQLDriver object. Next, addDatabase() is called to add the
@@ -1292,7 +1163,7 @@ bool QSqlDatabase::isDriverAvailable(const QString& name)
client library. Make sure the client library is in your linker's
search path, and add lines like these to your \c{.pro} file:
- \snippet code/src_sql_kernel_qsqldatabase.cpp 7
+ \snippet code/src_sql_kernel_qsqldatabase_snippet.cpp 7
The method described works for all the supplied drivers. The only
difference will be in the driver constructor arguments. Here is a
@@ -1327,27 +1198,22 @@ bool QSqlDatabase::isDriverAvailable(const QString& name)
\li SQLHANDLE environment, SQLHANDLE connection
\li \c qsql_db2.cpp
\row
- \li QTDS
- \li QTDSDriver
- \li LOGINREC *loginRecord, DBPROCESS *dbProcess, const QString &hostName
- \li \c qsql_tds.cpp
- \row
\li QSQLITE
\li QSQLiteDriver
\li sqlite *connection
\li \c qsql_sqlite.cpp
\row
+ \li QMIMER
+ \li QMimerSQLDriver
+ \li MimerSession *connection
+ \li \c qsql_mimer.cpp
+ \row
\li QIBASE
\li QIBaseDriver
\li isc_db_handle connection
\li \c qsql_ibase.cpp
\endtable
- The host name (or service name) is needed when constructing the
- QTDSDriver for creating new connections for internal queries. This
- is to prevent blocking when several QSqlQuery objects are used
- simultaneously.
-
\warning Adding a database connection with the same connection
name as an existing connection, causes the existing connection to
be replaced by the new one.
@@ -1385,6 +1251,8 @@ bool QSqlDatabase::isValid() const
\note The new connection has not been opened. Before using the new
connection, you must call open().
+
+ \reentrant
*/
QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QString &connectionName)
{
@@ -1416,24 +1284,11 @@ QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QStrin
QSqlDatabase QSqlDatabase::cloneDatabase(const QString &other, const QString &connectionName)
{
- const QConnectionDict *dict = dbDict();
- Q_ASSERT(dict);
-
- dict->lock.lockForRead();
- QSqlDatabase otherDb = dict->value(other);
- dict->lock.unlock();
- if (!otherDb.isValid())
- return QSqlDatabase();
-
- QSqlDatabase db(otherDb.driverName());
- db.d->copy(otherDb.d);
- QSqlDatabasePrivate::addDatabase(db, connectionName);
- return db;
+ CHECK_QCOREAPPLICATION_RETVAL
+ return cloneDatabase(s_sqlGlobals()->connection(other), connectionName);
}
/*!
- \since 4.4
-
Returns the connection name, which may be empty. \note The
connection name is not the \l{databaseName()} {database name}.
@@ -1445,10 +1300,11 @@ QString QSqlDatabase::connectionName() const
}
/*!
- \since 4.6
+ \property QSqlDatabase::numericalPrecisionPolicy
+ \since 6.8
- Sets the default numerical precision policy used by queries created
- on this database connection to \a precisionPolicy.
+ This property holds the default numerical precision policy used by
+ queries created on this database connection.
Note: Drivers that don't support fetching numerical values with low
precision will ignore the precision policy. You can use
@@ -1458,32 +1314,74 @@ QString QSqlDatabase::connectionName() const
Note: Setting the default precision policy to \a precisionPolicy
doesn't affect any currently active queries.
- \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(),
- QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy()
+ \sa QSql::NumericalPrecisionPolicy, QSqlQuery::numericalPrecisionPolicy,
+ QSqlDriver::numericalPrecisionPolicy
*/
+/*!
+ Sets \l numericalPrecisionPolicy to \a precisionPolicy.
+ */
void QSqlDatabase::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
{
- if(driver())
+ if (driver())
driver()->setNumericalPrecisionPolicy(precisionPolicy);
d->precisionPolicy = precisionPolicy;
}
/*!
- \since 4.6
-
- Returns the current default precision policy for the database connection.
-
- \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(),
- QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy()
+ Returns the \l numericalPrecisionPolicy.
*/
QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy() const
{
- if(driver())
+ if (driver())
return driver()->numericalPrecisionPolicy();
else
return d->precisionPolicy;
}
+/*!
+ \since 6.8
+
+ Changes the thread affinity for QSqlDatabase and its associated driver.
+ This function returns \c true when the function succeeds. Event processing
+ will continue in the \a targetThread.
+
+ During this operation you have to make sure that there is no QSqlQuery
+ bound to this instance otherwise the QSqlDatabase will not be moved to
+ the given thread and the function returns \c false.
+
+ Since the associated driver is derived from QObject, all constraints for
+ moving a QObject to another thread also apply to this function.
+
+ \sa QObject::moveToThread(), {Threads and the SQL Module}
+*/
+bool QSqlDatabase::moveToThread(QThread *targetThread)
+{
+ if (auto drv = driver()) {
+ if (drv != QSqlDatabasePrivate::shared_null()->driver) {
+ // two instances are alive - the one here and the one in dbDict()
+ if (d->ref.loadRelaxed() > 2) {
+ qWarning("QSqlDatabasePrivate::moveToThread: connection '%ls' is still in use "
+ "in the current thread.", qUtf16Printable(d->connName));
+ return false;
+ }
+ return drv->moveToThread(targetThread);
+ }
+ }
+ return false;
+}
+
+/*!
+ \since 6.8
+
+ Returns a pointer to the associated QThread instance.
+*/
+QThread *QSqlDatabase::currentThread() const
+{
+ if (auto drv = driver())
+ return drv->thread();
+ return nullptr;
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSqlDatabase &d)
@@ -1504,3 +1402,5 @@ QDebug operator<<(QDebug dbg, const QSqlDatabase &d)
#endif
QT_END_NAMESPACE
+
+#include "moc_qsqldatabase.cpp"
diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h
index f233c72c19..5059dbba83 100644
--- a/src/sql/kernel/qsqldatabase.h
+++ b/src/sql/kernel/qsqldatabase.h
@@ -1,48 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLDATABASE_H
#define QSQLDATABASE_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qmetaobject.h>
#include <QtCore/qstring.h>
+// clazy:excludeall=qproperty-without-notify
QT_BEGIN_NAMESPACE
@@ -52,6 +18,7 @@ class QSqlIndex;
class QSqlRecord;
class QSqlQuery;
class QSqlDatabasePrivate;
+class QThread;
class Q_SQL_EXPORT QSqlDriverCreatorBase
{
@@ -69,7 +36,10 @@ public:
class Q_SQL_EXPORT QSqlDatabase
{
+ Q_GADGET
public:
+ Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
+
QSqlDatabase();
QSqlDatabase(const QSqlDatabase &other);
~QSqlDatabase();
@@ -84,7 +54,10 @@ public:
QStringList tables(QSql::TableType type = QSql::Tables) const;
QSqlIndex primaryIndex(const QString& tablename) const;
QSqlRecord record(const QString& tablename) const;
+#if QT_DEPRECATED_SINCE(6, 6)
+ QT_DEPRECATED_VERSION_X_6_6("Use QSqlQuery::exec() instead.")
QSqlQuery exec(const QString& query = QString()) const;
+#endif
QSqlError lastError() const;
bool isValid() const;
@@ -108,21 +81,23 @@ public:
QString connectionName() const;
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
+ bool moveToThread(QThread *targetThread);
+ QThread *currentThread() const;
QSqlDriver* driver() const;
static const char *defaultConnection;
static QSqlDatabase addDatabase(const QString& type,
- const QString& connectionName = QLatin1String(defaultConnection));
+ const QString& connectionName = QLatin1StringView(defaultConnection));
static QSqlDatabase addDatabase(QSqlDriver* driver,
- const QString& connectionName = QLatin1String(defaultConnection));
+ const QString& connectionName = QLatin1StringView(defaultConnection));
static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName);
static QSqlDatabase cloneDatabase(const QString &other, const QString& connectionName);
- static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection),
+ static QSqlDatabase database(const QString& connectionName = QLatin1StringView(defaultConnection),
bool open = true);
static void removeDatabase(const QString& connectionName);
- static bool contains(const QString& connectionName = QLatin1String(defaultConnection));
+ static bool contains(const QString& connectionName = QLatin1StringView(defaultConnection));
static QStringList drivers();
static QStringList connectionNames();
static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator);
diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp
index adf4421c89..c0cb0374a9 100644
--- a/src/sql/kernel/qsqldriver.cpp
+++ b/src/sql/kernel/qsqldriver.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqldriver.h"
@@ -43,11 +7,15 @@
#include "qsqlerror.h"
#include "qsqlfield.h"
#include "qsqlindex.h"
-#include "private/qobject_p.h"
#include "private/qsqldriver_p.h"
+#include "private/qtools_p.h"
+
+#include <limits.h>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
static QString prepareIdentifier(const QString &identifier,
QSqlDriver::IdentifierType type, const QSqlDriver *driver)
{
@@ -101,20 +69,6 @@ QSqlDriver::~QSqlDriver()
}
/*!
- \since 4.4
-
- \fn QSqlDriver::notification(const QString &name)
-
- This signal is emitted when the database posts an event notification
- that the driver subscribes to. \a name identifies the event notification.
-
- \sa subscribeToNotification()
-
- \obsolete use QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload)
- instead
-*/
-
-/*!
\since 5.0
\fn QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant & payload)
@@ -261,6 +215,7 @@ bool QSqlDriver::isOpenError() const
\value SQLite
\value Interbase
\value DB2
+ \value [since 6.6] MimerSQL
*/
/*!
@@ -435,8 +390,8 @@ bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType t
{
Q_UNUSED(type);
return identifier.size() > 2
- && identifier.startsWith(QLatin1Char('"')) //left delimited
- && identifier.endsWith(QLatin1Char('"')); //right delimited
+ && identifier.startsWith(u'"') //left delimited
+ && identifier.endsWith(u'"'); //right delimited
}
/*!
@@ -449,7 +404,6 @@ bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType t
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
@@ -492,78 +446,77 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName,
{
const auto tableNameString = tableName.isEmpty() ? QString()
: prepareIdentifier(tableName, QSqlDriver::TableName, this);
- int i;
QString s;
s.reserve(128);
switch (type) {
case SelectStatement:
- for (i = 0; i < rec.count(); ++i) {
+ for (qsizetype i = 0; i < rec.count(); ++i) {
if (rec.isGenerated(i))
- s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", "));
+ s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(", "_L1);
}
if (s.isEmpty())
return s;
s.chop(2);
- s = QLatin1String("SELECT ") + s + QLatin1String(" FROM ") + tableNameString;
+ s = "SELECT "_L1 + s + " FROM "_L1 + tableNameString;
break;
case WhereStatement:
{
const QString tableNamePrefix = tableNameString.isEmpty()
- ? QString() : tableNameString + QLatin1Char('.');
- for (int i = 0; i < rec.count(); ++i) {
+ ? QString() : tableNameString + u'.';
+ for (qsizetype i = 0; i < rec.count(); ++i) {
if (!rec.isGenerated(i))
continue;
- s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND "));
+ s.append(s.isEmpty() ? "WHERE "_L1 : " AND "_L1);
s.append(tableNamePrefix);
s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this));
if (rec.isNull(i))
- s.append(QLatin1String(" IS NULL"));
+ s.append(" IS NULL"_L1);
else if (preparedStatement)
- s.append(QLatin1String(" = ?"));
+ s.append(" = ?"_L1);
else
- s.append(QLatin1String(" = ")).append(formatValue(rec.field(i)));
+ s.append(" = "_L1).append(formatValue(rec.field(i)));
}
break;
}
case UpdateStatement:
- s = s + QLatin1String("UPDATE ") + tableNameString + QLatin1String(" SET ");
- for (i = 0; i < rec.count(); ++i) {
+ s = s + "UPDATE "_L1 + tableNameString + " SET "_L1;
+ for (qsizetype i = 0; i < rec.count(); ++i) {
if (!rec.isGenerated(i))
continue;
- s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('='));
+ s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(u'=');
if (preparedStatement)
- s.append(QLatin1Char('?'));
+ s.append(u'?');
else
s.append(formatValue(rec.field(i)));
- s.append(QLatin1String(", "));
+ s.append(", "_L1);
}
- if (s.endsWith(QLatin1String(", ")))
+ if (s.endsWith(", "_L1))
s.chop(2);
else
s.clear();
break;
case DeleteStatement:
- s = s + QLatin1String("DELETE FROM ") + tableNameString;
+ s = s + "DELETE FROM "_L1 + tableNameString;
break;
case InsertStatement: {
- s = s + QLatin1String("INSERT INTO ") + tableNameString + QLatin1String(" (");
+ s = s + "INSERT INTO "_L1 + tableNameString + " ("_L1;
QString vals;
- for (i = 0; i < rec.count(); ++i) {
+ for (qsizetype i = 0; i < rec.count(); ++i) {
if (!rec.isGenerated(i))
continue;
- s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", "));
+ s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(", "_L1);
if (preparedStatement)
- vals.append(QLatin1Char('?'));
+ vals.append(u'?');
else
vals.append(formatValue(rec.field(i)));
- vals.append(QLatin1String(", "));
+ vals.append(", "_L1);
}
if (vals.isEmpty()) {
s.clear();
} else {
vals.chop(2); // remove trailing comma
- s[s.length() - 2] = QLatin1Char(')');
- s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')'));
+ s[s.size() - 2] = u')';
+ s.append("VALUES ("_L1).append(vals).append(u')');
}
break; }
}
@@ -605,72 +558,69 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName,
*/
QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const
{
- const QLatin1String nullTxt("NULL");
+ const auto nullTxt = "NULL"_L1;
QString r;
if (field.isNull())
r = nullTxt;
else {
- switch (field.type()) {
- case QVariant::Int:
- case QVariant::UInt:
- if (field.value().type() == QVariant::Bool)
- r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0");
+ switch (field.metaType().id()) {
+ case QMetaType::Int:
+ case QMetaType::UInt:
+ if (field.value().userType() == QMetaType::Bool)
+ r = field.value().toBool() ? "1"_L1 : "0"_L1;
else
r = field.value().toString();
break;
#if QT_CONFIG(datestring)
- case QVariant::Date:
+ case QMetaType::QDate:
if (field.value().toDate().isValid())
- r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate)
- + QLatin1Char('\'');
+ r = u'\'' + field.value().toDate().toString(Qt::ISODate) + u'\'';
else
r = nullTxt;
break;
- case QVariant::Time:
+ case QMetaType::QTime:
if (field.value().toTime().isValid())
- r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate)
- + QLatin1Char('\'');
+ r = u'\'' + field.value().toTime().toString(Qt::ISODate) + u'\'';
else
r = nullTxt;
break;
- case QVariant::DateTime:
+ case QMetaType::QDateTime:
if (field.value().toDateTime().isValid())
- r = QLatin1Char('\'') +
- field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\'');
+ r = u'\'' + field.value().toDateTime().toString(Qt::ISODate) + u'\'';
else
r = nullTxt;
break;
#endif
- case QVariant::String:
- case QVariant::Char:
+ case QMetaType::QString:
+ case QMetaType::QChar:
{
QString result = field.value().toString();
if (trimStrings) {
- int end = result.length();
+ int end = result.size();
while (end && result.at(end-1).isSpace()) /* skip white space from end */
end--;
result.truncate(end);
}
/* escape the "'" character */
- result.replace(QLatin1Char('\''), QLatin1String("''"));
- r = QLatin1Char('\'') + result + QLatin1Char('\'');
+ result.replace(u'\'', "''"_L1);
+ r = u'\'' + result + u'\'';
break;
}
- case QVariant::Bool:
+ case QMetaType::Bool:
r = QString::number(field.value().toBool());
break;
- case QVariant::ByteArray : {
+ case QMetaType::QByteArray : {
if (hasFeature(BLOB)) {
- QByteArray ba = field.value().toByteArray();
- QString res;
- static const char hexchars[] = "0123456789abcdef";
- for (int i = 0; i < ba.size(); ++i) {
- uchar s = (uchar) ba[i];
- res += QLatin1Char(hexchars[s >> 4]);
- res += QLatin1Char(hexchars[s & 0x0f]);
+ const QByteArray ba = field.value().toByteArray();
+ r.reserve((ba.size() + 1) * 2);
+ r += u'\'';
+ for (const char c : ba) {
+ const uchar s = uchar(c);
+ r += QLatin1Char(QtMiscUtils::toHexLower(s >> 4));
+ r += QLatin1Char(QtMiscUtils::toHexLower(s & 0x0f));
}
- r = QLatin1Char('\'') + res + QLatin1Char('\'');
+ r += u'\'';
break;
}
}
@@ -729,7 +679,6 @@ QVariant QSqlDriver::handle() const
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)
@@ -753,7 +702,6 @@ bool QSqlDriver::subscribeToNotification(const QString &name)
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)
@@ -768,7 +716,6 @@ bool QSqlDriver::unsubscribeFromNotification(const QString &name)
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
@@ -777,16 +724,7 @@ QStringList QSqlDriver::subscribedToNotifications() const
}
/*!
- \since 4.6
-
- Sets the default numerical precision policy used by queries created
- by this driver to \a precisionPolicy.
-
- Note: Setting the default precision policy to \a precisionPolicy
- doesn't affect any currently active queries.
-
- \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(),
- QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy()
+ Sets \l numericalPrecisionPolicy to \a precisionPolicy.
*/
void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
{
@@ -795,12 +733,17 @@ void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy prec
}
/*!
- \since 4.6
+ \property QSqlDriver::numericalPrecisionPolicy
+ \since 6.8
- Returns the current default precision policy for the database connection.
+ This property holds the precision policy for the database connection.
+ \note Setting the precision policy doesn't affect any currently active queries.
- \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(),
- QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy()
+ \sa QSql::NumericalPrecisionPolicy, QSqlQuery::numericalPrecisionPolicy,
+ QSqlDatabase::numericalPrecisionPolicy
+*/
+/*!
+ Returns the \l numericalPrecisionPolicy.
*/
QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const
{
@@ -843,4 +786,19 @@ bool QSqlDriver::cancelQuery()
return false;
}
+/*!
+ \since 6.0
+
+ Returns the maximum length for the identifier \a type according to the database settings. Returns
+ INT_MAX by default if the is no maximum for the database.
+*/
+
+int QSqlDriver::maximumIdentifierLength(QSqlDriver::IdentifierType type) const
+{
+ Q_UNUSED(type);
+ return INT_MAX;
+}
+
QT_END_NAMESPACE
+
+#include "moc_qsqldriver.cpp"
diff --git a/src/sql/kernel/qsqldriver.h b/src/sql/kernel/qsqldriver.h
index 31de63be15..a5fe40fa15 100644
--- a/src/sql/kernel/qsqldriver.h
+++ b/src/sql/kernel/qsqldriver.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLDRIVER_H
#define QSQLDRIVER_H
@@ -45,6 +9,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
+// clazy:excludeall=qproperty-without-notify
QT_BEGIN_NAMESPACE
@@ -86,9 +51,12 @@ public:
Sybase,
SQLite,
Interbase,
- DB2
+ DB2,
+ MimerSQL,
};
+ Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
+
explicit QSqlDriver(QObject *parent = nullptr);
~QSqlDriver();
virtual bool isOpen() const;
@@ -130,7 +98,7 @@ public:
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
DbmsType dbmsType() const;
-
+ virtual int maximumIdentifierLength(IdentifierType type) const;
public Q_SLOTS:
virtual bool cancelQuery();
diff --git a/src/sql/kernel/qsqldriver_p.h b/src/sql/kernel/qsqldriver_p.h
index 614fbf69a1..cfa6a2fa47 100644
--- a/src/sql/kernel/qsqldriver_p.h
+++ b/src/sql/kernel/qsqldriver_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLDRIVER_P_H
#define QSQLDRIVER_P_H
@@ -63,10 +27,10 @@ class QSqlDriverPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QSqlDriver)
public:
- QSqlDriverPrivate(QSqlDriver::DbmsType dbmstype = QSqlDriver::UnknownDbms)
- : QObjectPrivate()
- , dbmsType(dbmstype)
- {}
+ QSqlDriverPrivate(QSqlDriver::DbmsType type = QSqlDriver::UnknownDbms)
+ : QObjectPrivate(),
+ dbmsType(type)
+ { }
QSqlError error;
QSql::NumericalPrecisionPolicy precisionPolicy = QSql::LowPrecisionDouble;
diff --git a/src/sql/kernel/qsqldriverplugin.cpp b/src/sql/kernel/qsqldriverplugin.cpp
index 8e9982fca2..6dc5c35f0b 100644
--- a/src/sql/kernel/qsqldriverplugin.cpp
+++ b/src/sql/kernel/qsqldriverplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqldriverplugin.h"
@@ -100,3 +64,5 @@ QSqlDriverPlugin::~QSqlDriverPlugin()
}
QT_END_NAMESPACE
+
+#include "moc_qsqldriverplugin.cpp"
diff --git a/src/sql/kernel/qsqldriverplugin.h b/src/sql/kernel/qsqldriverplugin.h
index 001368a291..6eda126667 100644
--- a/src/sql/kernel/qsqldriverplugin.h
+++ b/src/sql/kernel/qsqldriverplugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLDRIVERPLUGIN_H
#define QSQLDRIVERPLUGIN_H
diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp
index 7a1a91948c..a52f209d53 100644
--- a/src/sql/kernel/qsqlerror.cpp
+++ b/src/sql/kernel/qsqlerror.cpp
@@ -1,47 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlerror.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSqlError &s)
{
@@ -53,7 +19,7 @@ QDebug operator<<(QDebug dbg, const QSqlError &s)
}
#endif
-class QSqlErrorPrivate
+class QSqlErrorPrivate : public QSharedData
{
public:
QString driverError;
@@ -61,7 +27,7 @@ public:
QSqlError::ErrorType errorType;
QString errorCode;
};
-
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlErrorPrivate)
/*!
\class QSqlError
@@ -90,15 +56,6 @@ public:
\value UnknownError Unknown error.
*/
-/*!
- \fn QSqlError::QSqlError(const QString &driverText, const QString &databaseText, ErrorType type, int number)
- \obsolete
-
- Constructs an error containing the driver error text \a
- driverText, the database-specific error text \a databaseText, the
- type \a type and the optional error number \a number.
-*/
-
/*! \fn QSqlError::QSqlError(QSqlError &&other)
Move-constructs a QSqlError instance, making it point at the same
object that \a other was pointing to.
@@ -127,33 +84,15 @@ public:
\since 5.10
*/
-#if QT_DEPRECATED_SINCE(5, 3)
-QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,
- int number)
-{
- d = new QSqlErrorPrivate;
-
- d->driverError = driverText;
- d->databaseError = databaseText;
- d->errorType = type;
- if (number != -1)
- d->errorCode = QString::number(number);
-}
-#endif
-
/*!
Constructs an error containing the driver error text \a
driverText, the database-specific error text \a databaseText, the
type \a type and the error code \a code.
-
- \note DB2: It is possible for DB2 to report more than one error code.
- When this happens, \c ; is used as separator between the error codes.
*/
QSqlError::QSqlError(const QString &driverText, const QString &databaseText,
ErrorType type, const QString &code)
+ : d(new QSqlErrorPrivate)
{
- d = new QSqlErrorPrivate;
-
d->driverError = driverText;
d->databaseError = databaseText;
d->errorType = type;
@@ -164,43 +103,38 @@ QSqlError::QSqlError(const QString &driverText, const QString &databaseText,
/*!
Creates a copy of \a other.
*/
-QSqlError::QSqlError(const QSqlError& other)
-{
- d = new QSqlErrorPrivate;
-
- *d = *other.d;
-}
+QSqlError::QSqlError(const QSqlError &other)
+ = default;
/*!
Assigns the \a other error's values to this error.
*/
-QSqlError& QSqlError::operator=(const QSqlError& other)
-{
- if (d)
- *d = *other.d;
- else
- d = new QSqlErrorPrivate(*other.d);
- return *this;
-}
+QSqlError &QSqlError::operator=(const QSqlError &other)
+ = default;
+
/*!
- Compare the \a other error's values to this error and returns \c true, if it equal.
+ Compare the \a other error's type() and nativeErrorCode()
+ to this error and returns \c true, if it equal.
*/
-bool QSqlError::operator==(const QSqlError& other) const
+bool QSqlError::operator==(const QSqlError &other) const
{
- return (d->errorType == other.d->errorType);
+ return (d->errorType == other.d->errorType &&
+ d->errorCode == other.d->errorCode);
}
/*!
- Compare the \a other error's values to this error and returns \c true if it is not equal.
+ Compare the \a other error's type() and nativeErrorCode()
+ to this error and returns \c true if it is not equal.
*/
-bool QSqlError::operator!=(const QSqlError& other) const
+bool QSqlError::operator!=(const QSqlError &other) const
{
- return (d->errorType != other.d->errorType);
+ return (d->errorType != other.d->errorType ||
+ d->errorCode != other.d->errorCode);
}
@@ -209,9 +143,7 @@ bool QSqlError::operator!=(const QSqlError& other) const
*/
QSqlError::~QSqlError()
-{
- delete d;
-}
+ = default;
/*!
Returns the text of the error as reported by the driver. This may
@@ -225,25 +157,6 @@ QString QSqlError::driverText() const
}
/*!
- \fn void QSqlError::setDriverText(const QString &driverText)
- \obsolete
-
- Sets the driver error text to the value of \a driverText.
-
- Use QSqlError(const QString &driverText, const QString &databaseText,
- ErrorType type, int number) instead
-
- \sa driverText(), setDatabaseText(), text()
-*/
-
-#if QT_DEPRECATED_SINCE(5, 1)
-void QSqlError::setDriverText(const QString& driverText)
-{
- d->driverError = driverText;
-}
-#endif
-
-/*!
Returns the text of the error as reported by the database. This
may contain database-specific descriptions; it may be empty.
@@ -256,25 +169,6 @@ QString QSqlError::databaseText() const
}
/*!
- \fn void QSqlError::setDatabaseText(const QString &databaseText)
- \obsolete
-
- Sets the database error text to the value of \a databaseText.
-
- Use QSqlError(const QString &driverText, const QString &databaseText,
- ErrorType type, int number) instead
-
- \sa databaseText(), setDriverText(), text()
-*/
-
-#if QT_DEPRECATED_SINCE(5, 1)
-void QSqlError::setDatabaseText(const QString& databaseText)
-{
- d->databaseError = databaseText;
-}
-#endif
-
-/*!
Returns the error type, or -1 if the type cannot be determined.
*/
@@ -284,70 +178,11 @@ QSqlError::ErrorType QSqlError::type() const
}
/*!
- \fn void QSqlError::setType(ErrorType type)
- \obsolete
-
- Sets the error type to the value of \a type.
-
- Use QSqlError(const QString &driverText, const QString &databaseText,
- ErrorType type, int number) instead
-
- \sa type()
-*/
-
-#if QT_DEPRECATED_SINCE(5, 1)
-void QSqlError::setType(ErrorType type)
-{
- d->errorType = type;
-}
-#endif
-
-/*!
- \fn int QSqlError::number() const
- \obsolete
-
- Returns the database-specific error number, or -1 if it cannot be
- determined.
-
- Returns 0 if the error code is not an integer.
-
- \warning Some databases use alphanumeric error codes, which makes
- number() unreliable if such a database is used.
-
- Use nativeErrorCode() instead
-
- \sa nativeErrorCode()
-*/
-
-#if QT_DEPRECATED_SINCE(5, 3)
-int QSqlError::number() const
-{
- return d->errorCode.isEmpty() ? -1 : d->errorCode.toInt();
-}
-#endif
-
-/*!
- \fn void QSqlError::setNumber(int number)
- \obsolete
-
- Sets the database-specific error number to \a number.
-
- Use QSqlError(const QString &driverText, const QString &databaseText,
- ErrorType type, int number) instead
-
- \sa number()
-*/
-
-#if QT_DEPRECATED_SINCE(5, 1)
-void QSqlError::setNumber(int number)
-{
- d->errorCode = QString::number(number);
-}
-#endif
-
-/*!
Returns the database-specific error code, or an empty string if
it cannot be determined.
+ \note Some drivers (like DB2 or ODBC) may return more than one
+ error code. When this happens, \c ; is used as separator between
+ the error codes.
*/
QString QSqlError::nativeErrorCode() const
@@ -365,8 +200,8 @@ QString QSqlError::nativeErrorCode() const
QString QSqlError::text() const
{
QString result = d->databaseError;
- if (!d->databaseError.isEmpty() && !d->driverError.isEmpty() && !d->databaseError.endsWith(QLatin1String("\n")))
- result += QLatin1Char(' ');
+ if (!d->databaseError.isEmpty() && !d->driverError.isEmpty() && !d->databaseError.endsWith(u'\n'))
+ result += u' ';
result += d->driverError;
return result;
}
diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h
index 7dfb6eb9ec..24f2921f5a 100644
--- a/src/sql/kernel/qsqlerror.h
+++ b/src/sql/kernel/qsqlerror.h
@@ -1,51 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLERROR_H
#define QSQLERROR_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
class QSqlErrorPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlErrorPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlError
{
@@ -57,57 +23,33 @@ public:
TransactionError,
UnknownError
};
-#if QT_DEPRECATED_SINCE(5, 3)
- QT_DEPRECATED QSqlError(const QString &driverText, const QString &databaseText,
- ErrorType type, int number);
-#endif
QSqlError(const QString &driverText = QString(),
const QString &databaseText = QString(),
ErrorType type = NoError,
const QString &errorCode = QString());
- QSqlError(const QSqlError& other);
- QSqlError(QSqlError &&other) noexcept : d(other.d) { other.d = nullptr; }
- QSqlError& operator=(const QSqlError& other);
- QSqlError &operator=(QSqlError &&other) noexcept { swap(other); return *this; }
-
- bool operator==(const QSqlError& other) const;
- bool operator!=(const QSqlError& other) const;
+ QSqlError(const QSqlError &other);
+ QSqlError(QSqlError &&other) noexcept = default;
+ QSqlError& operator=(const QSqlError &other);
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QSqlError)
~QSqlError();
- void swap(QSqlError &other) noexcept { qSwap(d, other.d); }
+ bool operator==(const QSqlError &other) const;
+ bool operator!=(const QSqlError &other) const;
+
+ void swap(QSqlError &other) noexcept { d.swap(other.d); }
QString driverText() const;
QString databaseText() const;
ErrorType type() const;
-#if QT_DEPRECATED_SINCE(5, 3)
- QT_DEPRECATED int number() const;
-#endif
QString nativeErrorCode() const;
QString text() const;
bool isValid() const;
-#if QT_DEPRECATED_SINCE(5, 1)
- QT_DEPRECATED void setDriverText(const QString &driverText);
- QT_DEPRECATED void setDatabaseText(const QString &databaseText);
- QT_DEPRECATED void setType(ErrorType type);
- QT_DEPRECATED void setNumber(int number);
-#endif
-
private:
- // ### Qt6: Keep the pointer and remove the rest.
- QString unused1;
- QString unused2;
- struct Unused {
- ErrorType unused3;
- int unused4;
- };
- union {
- QSqlErrorPrivate *d;
- Unused unused5;
- };
+ QExplicitlySharedDataPointer<QSqlErrorPrivate> d;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QSqlError)
+Q_DECLARE_SHARED(QSqlError)
#ifndef QT_NO_DEBUG_STREAM
Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlError &);
diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp
index 5a6d173b3b..0bd0ca5161 100644
--- a/src/sql/kernel/qsqlfield.cpp
+++ b/src/sql/kernel/qsqlfield.cpp
@@ -1,73 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlfield.h"
-#include "qatomic.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE
-class QSqlFieldPrivate
+class QSqlFieldPrivate : public QSharedData
{
public:
QSqlFieldPrivate(const QString &name,
- QVariant::Type type, const QString &tableName) :
- ref(1), nm(name), table(tableName), def(QVariant()), type(type),
+ QMetaType type, const QString &tableName) :
+ nm(name), table(tableName), def(QVariant()), type(type),
req(QSqlField::Unknown), len(-1), prec(-1), tp(-1),
ro(false), gen(true), autoval(false)
{}
- QSqlFieldPrivate(const QSqlFieldPrivate &other)
- : ref(1),
- nm(other.nm),
- table(other.table),
- def(other.def),
- type(other.type),
- req(other.req),
- len(other.len),
- prec(other.prec),
- tp(other.tp),
- ro(other.ro),
- gen(other.gen),
- autoval(other.autoval)
- {}
-
bool operator==(const QSqlFieldPrivate& other) const
{
return (nm == other.nm
@@ -82,11 +30,10 @@ public:
&& autoval == other.autoval);
}
- QAtomicInt ref;
QString nm;
QString table;
QVariant def;
- QVariant::Type type;
+ QMetaType type;
QSqlField::RequiredStatus req;
int len;
int prec;
@@ -95,6 +42,7 @@ public:
bool gen: 1;
bool autoval: 1;
};
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlFieldPrivate)
/*!
@@ -151,58 +99,52 @@ public:
\value Unknown The database driver couldn't determine whether the field is required or
optional.
- \sa requiredStatus()
+ \sa requiredStatus
*/
/*!
- Constructs an empty field called \a fieldName of variant type \a type.
+ \fn QSqlField::QSqlField(const QString &fieldName, QVariant::Type type, const QString &table)
+ \deprecated [6.0] Use the constructor taking a QMetaType instead.
+ \overload
- \sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
- setGenerated(), setReadOnly()
+ Constructs an empty field called \a fieldName of variant type \a
+ type in \a table.
*/
-QSqlField::QSqlField(const QString &fieldName, QVariant::Type type)
-{
- d = new QSqlFieldPrivate(fieldName, type, QString());
- val = QVariant(type);
-}
/*!
+ \fn void QSqlField::swap(QSqlField &other)
+ \since 6.6
+
+ Swaps this field with \a other. This function is very fast and
+ never fails.
+*/
+
+/*!
+ \since 6.0
+
\overload
- Constructs an empty field called \a fieldName of variant type \a
+ Constructs an empty field called \a fieldName of type \a
type in \a table.
-
- \sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
- setGenerated(), setReadOnly()
*/
-QSqlField::QSqlField(const QString &fieldName, QVariant::Type type,
- const QString &table)
+QSqlField::QSqlField(const QString &fieldName, QMetaType type, const QString &table)
+ : val(QVariant(type, nullptr)),
+ d(new QSqlFieldPrivate(fieldName, type, table))
{
- d = new QSqlFieldPrivate(fieldName, type, table);
- val = QVariant(type);
}
/*!
Constructs a copy of \a other.
*/
-QSqlField::QSqlField(const QSqlField& other)
-{
- d = other.d;
- d->ref.ref();
- val = other.val;
-}
+QSqlField::QSqlField(const QSqlField &other)
+ = default;
/*!
Sets the field equal to \a other.
*/
QSqlField& QSqlField::operator=(const QSqlField& other)
-{
- qAtomicAssign(d, other.d);
- val = other.val;
- return *this;
-}
-
+ = default;
/*! \fn bool QSqlField::operator!=(const QSqlField &other) const
Returns \c true if the field is unequal to \a other; otherwise returns
@@ -224,16 +166,10 @@ bool QSqlField::operator==(const QSqlField& other) const
*/
QSqlField::~QSqlField()
-{
- if (!d->ref.deref())
- delete d;
-}
+ = default;
/*!
- Sets the required status of this field to \a required.
-
- \sa requiredStatus(), setType(), setLength(), setPrecision(),
- setDefaultValue(), setGenerated(), setReadOnly()
+ Sets \l requiredStatus to \a required.
*/
void QSqlField::setRequiredStatus(RequiredStatus required)
{
@@ -246,16 +182,11 @@ void QSqlField::setRequiredStatus(RequiredStatus required)
Sets the required status of this field to \l Required if \a
required is true; otherwise sets it to \l Optional.
- \sa setRequiredStatus(), requiredStatus()
+ \sa requiredStatus
*/
/*!
- Sets the field's length to \a fieldLength. For strings this is the
- maximum number of characters the string can hold; the meaning
- varies for other types.
-
- \sa length(), setType(), setRequiredStatus(), setPrecision(),
- setDefaultValue(), setGenerated(), setReadOnly()
+ Sets \l length to \a fieldLength.
*/
void QSqlField::setLength(int fieldLength)
{
@@ -264,10 +195,7 @@ void QSqlField::setLength(int fieldLength)
}
/*!
- Sets the field's \a precision. This only affects numeric fields.
-
- \sa precision(), setType(), setRequiredStatus(), setLength(),
- setDefaultValue(), setGenerated(), setReadOnly()
+ Sets \l precision to \a precision.
*/
void QSqlField::setPrecision(int precision)
{
@@ -276,10 +204,16 @@ void QSqlField::setPrecision(int precision)
}
/*!
- Sets the default value used for this field to \a value.
+ \property QSqlField::defaultValue
+ \since 6.8
+
+ This property holds the default value for this field.
+ Only some database drivers supports this property. Currently
+ those are SQLite, PostgreSQL, Oracle and MySQL/MariaDB.
+*/
- \sa defaultValue(), value(), setType(), setRequiredStatus(),
- setLength(), setPrecision(), setGenerated(), setReadOnly()
+/*!
+ Sets \l defaultValue to \a value.
*/
void QSqlField::setDefaultValue(const QVariant &value)
{
@@ -287,23 +221,20 @@ void QSqlField::setDefaultValue(const QVariant &value)
d->def = value;
}
+#if QT_DEPRECATED_SINCE(6, 8)
/*!
\internal
+ \deprecated [6.8] This internal value is no longer used.
*/
void QSqlField::setSqlType(int type)
{
detach();
d->tp = type;
}
+#endif
/*!
- Sets the generated state. If \a gen is false, no SQL will
- be generated for this field; otherwise, Qt classes such as
- QSqlQueryModel and QSqlTableModel will generate SQL for this
- field.
-
- \sa isGenerated(), setType(), setRequiredStatus(), setLength(),
- setPrecision(), setDefaultValue(), setReadOnly()
+ Sets \l generated to \a gen.
*/
void QSqlField::setGenerated(bool gen)
{
@@ -313,19 +244,28 @@ void QSqlField::setGenerated(bool gen)
/*!
- Sets the value of the field to \a value. If the field is read-only
- (isReadOnly() returns \c true), nothing happens.
+ \property QSqlField::value
+ \since 6.8
+
+ This property holds the \a value as a QVariant
+ Setting a \a value to a read-only QSqlField is a no-op.
If the data type of \a value differs from the field's current
data type, an attempt is made to cast it to the proper type. This
preserves the data type of the field in the case of assignment,
e.g. a QString to an integer data type.
To set the value to NULL, use clear().
-
- \sa value(), isReadOnly(), defaultValue()
*/
+/*!
+ \fn QVariant QSqlField::value() const
+
+ Returns the value of \l value.
+*/
+/*!
+ Sets \l value to \a value.
+*/
void QSqlField::setValue(const QVariant& value)
{
if (isReadOnly())
@@ -336,23 +276,19 @@ void QSqlField::setValue(const QVariant& value)
/*!
Clears the value of the field and sets it to NULL.
If the field is read-only, nothing happens.
-
- \sa setValue(), isReadOnly(), requiredStatus()
*/
void QSqlField::clear()
{
if (isReadOnly())
return;
- val = QVariant(type());
+ val = QVariant(d->type, nullptr);
}
-/*!
- Sets the name of the field to \a name.
- \sa name()
+/*!
+ Sets \l name to \a name.
*/
-
void QSqlField::setName(const QString& name)
{
detach();
@@ -360,9 +296,7 @@ void QSqlField::setName(const QString& name)
}
/*!
- Sets the read only flag of the field's value to \a readOnly. A
- read-only field cannot have its value set with setValue() and
- cannot be cleared to NULL with clear().
+ Sets \l readOnly to \a readOnly.
*/
void QSqlField::setReadOnly(bool readOnly)
{
@@ -371,17 +305,14 @@ void QSqlField::setReadOnly(bool readOnly)
}
/*!
- \fn QVariant QSqlField::value() const
+ \property QSqlField::name
- Returns the value of the field as a QVariant.
-
- Use isNull() to check if the field's value is NULL.
+ This property holds the name of the field.
+ This can be the column name or a user given alias.
*/
/*!
- Returns the name of the field.
-
- \sa setName()
+ Returns the value of \l name.
*/
QString QSqlField::name() const
{
@@ -389,66 +320,106 @@ QString QSqlField::name() const
}
/*!
- Returns the field's type as stored in the database.
+ \property QSqlField::metaType
+ \since 6.8
+
+ This property holds the field's type as stored in the database.
Note that the actual value might have a different type,
Numerical values that are too large to store in a long
int or double are usually stored as strings to prevent
precision loss.
- \sa setType()
+ \sa QSqlDatabase::numericalPrecisionPolicy
+*/
+
+/*!
+ Returns the value of \l metaType.
*/
-QVariant::Type QSqlField::type() const
+QMetaType QSqlField::metaType() const
{
return d->type;
}
/*!
- Set's the field's variant type to \a type.
-
- \sa type(), setRequiredStatus(), setLength(), setPrecision(),
- setDefaultValue(), setGenerated(), setReadOnly()
+ Sets \l metaType to \a type.
*/
-void QSqlField::setType(QVariant::Type type)
+void QSqlField::setMetaType(QMetaType type)
{
detach();
d->type = type;
if (!val.isValid())
- val = QVariant(type);
+ val = QVariant(type, nullptr);
}
+/*!
+ \fn QVariant::Type QSqlField::type() const
+ \deprecated [6.0] Use metaType() instead.
+
+ Returns the field's type as stored in the database.
+ Note that the actual value might have a different type,
+ Numerical values that are too large to store in a long
+ int or double are usually stored as strings to prevent
+ precision loss.
+
+ \sa metaType
+*/
/*!
- Returns \c true if the field's value is read-only; otherwise returns
- false.
+ \fn void QSqlField::setType(QVariant::Type type)
+ \deprecated [6.0] Use setMetaType() instead.
+
+ Sets the field's variant type to \a type.
+
+ \sa metaType
+*/
+
+/*!
+ \property QSqlField::readOnly
+ \since 6.8
- \sa setReadOnly(), type(), requiredStatus(), length(), precision(),
- defaultValue(), isGenerated()
+ When this property is \c true then this QSqlField cannot be modified.
+ A read-only field cannot have its value set with setValue() and
+ cannot be cleared to NULL with clear().
+*/
+
+/*!
+ Returns the value of \l readOnly.
*/
bool QSqlField::isReadOnly() const
-{ return d->ro; }
+{
+ return d->ro;
+}
/*!
Returns \c true if the field's value is NULL; otherwise returns
false.
- \sa value()
+ \sa value
*/
bool QSqlField::isNull() const
-{ return val.isNull(); }
+{
+ return val.isNull();
+}
/*! \internal
*/
void QSqlField::detach()
{
- qAtomicDetach(d);
+ d.detach();
}
/*!
- Returns \c true if this is a required field; otherwise returns \c false.
+ \property QSqlField::requiredStatus
+ \since 6.8
+
+ This property holds the RequiredStatus of the field.
An \c INSERT will fail if a required field does not have a value.
- \sa setRequiredStatus(), type(), length(), precision(), defaultValue(),
- isGenerated()
+ \sa RequiredStatus
+*/
+
+/*!
+ Returns the value of \l requiredStatus.
*/
QSqlField::RequiredStatus QSqlField::requiredStatus() const
{
@@ -456,13 +427,19 @@ QSqlField::RequiredStatus QSqlField::requiredStatus() const
}
/*!
- Returns the field's length.
+ \property QSqlField::length
+ \since 6.8
- If the returned value is negative, it means that the information
+ This property holds the field's length.
+
+ If the value is negative, it means that the information
is not available from the database.
+ For strings this is the maximum number of characters the string
+ can hold; the meaning varies for other types.
+*/
- \sa setLength(), type(), requiredStatus(), precision(), defaultValue(),
- isGenerated()
+/*!
+ Returns the value of \l length.
*/
int QSqlField::length() const
{
@@ -470,14 +447,17 @@ int QSqlField::length() const
}
/*!
- Returns the field's precision; this is only meaningful for numeric
- types.
+ \property QSqlField::precision
+ \since 6.8
+
+ This property holds the field's precision; this is only meaningful
+ for numeric types.
If the returned value is negative, it means that the information
is not available from the database.
-
- \sa setPrecision(), type(), requiredStatus(), length(), defaultValue(),
- isGenerated()
+*/
+/*!
+ Returns the value of \l precision.
*/
int QSqlField::precision() const
{
@@ -485,18 +465,17 @@ int QSqlField::precision() const
}
/*!
- Returns the field's default value (which may be NULL).
-
- \sa setDefaultValue(), type(), requiredStatus(), length(), precision(),
- isGenerated()
+ Sets the value of \l defaultValue.
*/
QVariant QSqlField::defaultValue() const
{
return d->def;
}
+#if QT_DEPRECATED_SINCE(6, 8)
/*!
\internal
+ \deprecated [6.8] This internal value is no longer used.
Returns the type ID for the field.
@@ -507,13 +486,19 @@ int QSqlField::typeID() const
{
return d->tp;
}
+#endif
/*!
- Returns \c true if the field is generated; otherwise returns
- false.
+ \property QSqlField::generated
+ \since 6.8
- \sa setGenerated(), type(), requiredStatus(), length(), precision(),
- defaultValue()
+ This property holds the generated state. If \a generated is \c false,
+ no SQL will be generated for this field; otherwise, Qt classes such as
+ QSqlQueryModel and QSqlTableModel will generate SQL for this field.
+*/
+
+/*!
+ Returns the value of \l generated.
*/
bool QSqlField::isGenerated() const
{
@@ -526,7 +511,7 @@ bool QSqlField::isGenerated() const
*/
bool QSqlField::isValid() const
{
- return d->type != QVariant::Invalid;
+ return d->type.isValid();
}
#ifndef QT_NO_DEBUG_STREAM
@@ -534,7 +519,7 @@ QDebug operator<<(QDebug dbg, const QSqlField &f)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "QSqlField(" << f.name() << ", " << QMetaType::typeName(f.type());
+ dbg << "QSqlField(" << f.name() << ", " << f.metaType().name();
dbg << ", tableName: " << (f.tableName().isEmpty() ? QStringLiteral("(not specified)") : f.tableName());
if (f.length() >= 0)
dbg << ", length: " << f.length();
@@ -544,8 +529,6 @@ QDebug operator<<(QDebug dbg, const QSqlField &f)
dbg << ", required: "
<< (f.requiredStatus() == QSqlField::Required ? "yes" : "no");
dbg << ", generated: " << (f.isGenerated() ? "yes" : "no");
- if (f.typeID() >= 0)
- dbg << ", typeID: " << f.typeID();
if (!f.defaultValue().isNull())
dbg << ", defaultValue: \"" << f.defaultValue() << '\"';
dbg << ", autoValue: " << f.isAutoValue()
@@ -555,16 +538,21 @@ QDebug operator<<(QDebug dbg, const QSqlField &f)
#endif
/*!
- Returns \c true if the value is auto-generated by the database,
- for example auto-increment primary key values.
+ \property QSqlField::autoValue
+ \since 6.8
+
+ If the value is auto-generated by the database,
+ for example auto-increment primary key values, this value is \c true.
\note When using the ODBC driver, due to limitations in the ODBC API,
the \c isAutoValue() field is only populated in a QSqlField resulting from a
QSqlRecord obtained by executing a \c SELECT query. It is \c false in a QSqlField
resulting from a QSqlRecord returned from QSqlDatabase::record() or
QSqlDatabase::primaryIndex().
+*/
- \sa setAutoValue()
+/*!
+ Returns the value of \l autoValue.
*/
bool QSqlField::isAutoValue() const
{
@@ -572,11 +560,8 @@ bool QSqlField::isAutoValue() const
}
/*!
- Marks the field as an auto-generated value if \a autoVal
- is true.
-
- \sa isAutoValue()
- */
+ Sets \l autoValue to \a autoVal.
+*/
void QSqlField::setAutoValue(bool autoVal)
{
detach();
@@ -584,24 +569,26 @@ void QSqlField::setAutoValue(bool autoVal)
}
/*!
- Sets the tableName of the field to \a table.
-
- \sa tableName()
+ Sets \l tableName to \a tableName.
*/
-void QSqlField::setTableName(const QString &table)
+void QSqlField::setTableName(const QString &tableName)
{
detach();
- d->table = table;
+ d->table = tableName;
}
/*!
- Returns the tableName of the field.
+ \property QSqlField::tableName
+ \since 6.8
+
+ This property holds the tableName of the field.
\note When using the QPSQL driver, due to limitations in the libpq library,
the \c tableName() field is not populated in a QSqlField resulting
from a QSqlRecord obtained by QSqlQuery::record() of a forward-only query.
-
- \sa setTableName()
+*/
+/*!
+ Returns the \l tableName.
*/
QString QSqlField::tableName() const
{
@@ -609,3 +596,5 @@ QString QSqlField::tableName() const
}
QT_END_NAMESPACE
+
+#include "moc_qsqlfield.cpp"
diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h
index 8650ba8715..451f70f3b6 100644
--- a/src/sql/kernel/qsqlfield.h
+++ b/src/sql/kernel/qsqlfield.h
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLFIELD_H
#define QSQLFIELD_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qvariant.h>
#include <QtCore/qstring.h>
@@ -48,22 +13,38 @@ QT_BEGIN_NAMESPACE
class QSqlFieldPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlField
{
+ Q_GADGET
public:
enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
- explicit QSqlField(const QString& fieldName = QString(),
- QVariant::Type type = QVariant::Invalid);
- QSqlField(const QString &fieldName, QVariant::Type type,
- const QString &tableName);
+ Q_PROPERTY(QVariant value READ value WRITE setValue)
+ Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue)
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QString tableName READ tableName WRITE setTableName)
+ Q_PROPERTY(QMetaType metaType READ metaType WRITE setMetaType)
+ Q_PROPERTY(RequiredStatus requiredStatus READ requiredStatus WRITE setRequiredStatus)
+ Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
+ Q_PROPERTY(bool generated READ isGenerated WRITE setGenerated)
+ Q_PROPERTY(bool autoValue READ isAutoValue WRITE setAutoValue)
+ Q_PROPERTY(int length READ length WRITE setLength)
+ Q_PROPERTY(int precision READ precision WRITE setPrecision)
+
+ explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
QSqlField(const QSqlField& other);
QSqlField& operator=(const QSqlField& other);
+ QSqlField(QSqlField &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
+ ~QSqlField();
+
+ void swap(QSqlField &other) noexcept { val.swap(other.val); d.swap(other.d); }
+
bool operator==(const QSqlField& other) const;
inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
- ~QSqlField();
void setValue(const QVariant& value);
inline QVariant value() const
@@ -76,17 +57,31 @@ public:
void setReadOnly(bool readOnly);
bool isReadOnly() const;
void clear();
- QVariant::Type type() const;
bool isAutoValue() const;
- void setType(QVariant::Type type);
+ QMetaType metaType() const;
+ void setMetaType(QMetaType type);
+
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
+ QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
+ QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
+ : QSqlField(fieldName, QMetaType(type), tableName)
+ {}
+ QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
+ QVariant::Type type() const { return QVariant::Type(metaType().id()); };
+ QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
+ void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
+ QT_WARNING_POP
+#endif
+
void setRequiredStatus(RequiredStatus status);
inline void setRequired(bool required)
{ setRequiredStatus(required ? Required : Optional); }
void setLength(int fieldLength);
void setPrecision(int precision);
void setDefaultValue(const QVariant &value);
- void setSqlType(int type);
void setGenerated(bool gen);
void setAutoValue(bool autoVal);
@@ -94,16 +89,24 @@ public:
int length() const;
int precision() const;
QVariant defaultValue() const;
- int typeID() const;
bool isGenerated() const;
bool isValid() const;
+#if QT_DEPRECATED_SINCE(6, 8)
+ QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
+ void setSqlType(int type);
+ QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
+ int typeID() const;
+#endif
private:
void detach();
+ // ### Qt7: move to private class
QVariant val;
- QSqlFieldPrivate* d;
+ QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
};
+Q_DECLARE_SHARED(QSqlField)
+
#ifndef QT_NO_DEBUG_STREAM
Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
#endif
diff --git a/src/sql/kernel/qsqlindex.cpp b/src/sql/kernel/qsqlindex.cpp
index 5781f24b5c..15ee489928 100644
--- a/src/sql/kernel/qsqlindex.cpp
+++ b/src/sql/kernel/qsqlindex.cpp
@@ -1,49 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlindex.h"
#include "qsqlfield.h"
-#include "qstringlist.h"
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QSqlIndex
\brief The QSqlIndex class provides functions to manipulate and
@@ -76,6 +41,25 @@ QSqlIndex::QSqlIndex(const QSqlIndex& other)
{
}
+/*! \fn QSqlIndex::QSqlIndex(QSqlIndex &&other)
+ Move-constructs a new QSqlIndex from \a other.
+
+ \note The moved-from object \a other is placed in a
+ partially-formed state, in which the only valid operations are
+ destruction and assignment of a new value.
+
+ \since 6.6
+*/
+/*! \fn QSqlIndex& QSqlIndex::operator=(QSqlIndex &&other)
+ Move-assigns \a other to this QSqlIndex instance.
+
+ \note The moved-from object \a other is placed in a
+ partially-formed state, in which the only valid operations are
+ destruction and assignment of a new value.
+
+ \since 6.6
+*/
+
/*!
Sets the index equal to \a other.
*/
@@ -89,6 +73,7 @@ QSqlIndex& QSqlIndex::operator=(const QSqlIndex& other)
return *this;
}
+
/*!
Destroys the object and frees any allocated resources.
*/
@@ -99,21 +84,23 @@ QSqlIndex::~QSqlIndex()
}
/*!
- Sets the name of the index to \a name.
+ \property QSqlIndex::name
+ \since 6.8
+ This property holds the name of the index.
+*/
+/*!
+ \fn QString QSqlIndex::name() const
+ Returns the \l name.
+*/
+/*!
+ Sets \l name to \a name.
*/
-
void QSqlIndex::setName(const QString& name)
{
nm = name;
}
/*!
- \fn QString QSqlIndex::name() const
-
- Returns the name of the index.
-*/
-
-/*!
Appends the field \a field to the list of indexed fields. The
field is appended with an ascending sort order.
*/
@@ -162,35 +149,18 @@ void QSqlIndex::setDescending(int i, bool desc)
sorts[i] = desc;
}
-/*! \internal
-
- Creates a string representing the field number \a i using prefix \a
- prefix. If \a verbose is true, ASC or DESC is included in the field
- description if the field is sorted in ASCending or DESCending order.
+/*!
+ \property QSqlIndex::cursorName
+ \since 6.8
+ This property holds the name of the cursor which the index
+ is associated with.
*/
-
-QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const
-{
- QString f;
- if (!prefix.isEmpty())
- f += prefix + QLatin1Char('.');
- f += field(i).name();
- if (verbose)
- f += QLatin1Char(' ') + QString((isDescending(i)
- ? QLatin1String("DESC") : QLatin1String("ASC")));
- return f;
-}
-
/*!
\fn QString QSqlIndex::cursorName() const
-
- Returns the name of the cursor which the index is associated with.
+ Returns the \l cursorName.
*/
-
-
/*!
- Sets the name of the cursor that the index is associated with to
- \a cursorName.
+ Sets \l cursorName to \a cursorName.
*/
void QSqlIndex::setCursorName(const QString& cursorName)
{
@@ -198,3 +168,5 @@ void QSqlIndex::setCursorName(const QString& cursorName)
}
QT_END_NAMESPACE
+
+#include "moc_qsqlindex.cpp"
diff --git a/src/sql/kernel/qsqlindex.h b/src/sql/kernel/qsqlindex.h
index b6fbdbbaaf..3d5d95b373 100644
--- a/src/sql/kernel/qsqlindex.h
+++ b/src/sql/kernel/qsqlindex.h
@@ -1,63 +1,40 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLINDEX_H
#define QSQLINDEX_H
#include <QtSql/qtsqlglobal.h>
#include <QtSql/qsqlrecord.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qvector.h>
-#if QT_DEPRECATED_SINCE(5,6)
#include <QtCore/qlist.h>
-#endif
+#include <QtCore/qmetaobject.h>
+#include <QtCore/qstring.h>
+// clazy:excludeall=qproperty-without-notify
QT_BEGIN_NAMESPACE
class Q_SQL_EXPORT QSqlIndex : public QSqlRecord
{
+ Q_GADGET
public:
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QString cursorName READ cursorName WRITE setCursorName)
+
explicit QSqlIndex(const QString &cursorName = QString(), const QString &name = QString());
QSqlIndex(const QSqlIndex &other);
+ QSqlIndex(QSqlIndex &&other) noexcept = default;
~QSqlIndex();
QSqlIndex &operator=(const QSqlIndex &other);
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QSqlIndex)
+
+ void swap(QSqlIndex &other) noexcept {
+ QSqlRecord::swap(other);
+ cursor.swap(other.cursor);
+ nm.swap(other.nm);
+ sorts.swap(other.sorts);
+ };
+
void setCursorName(const QString &cursorName);
inline QString cursorName() const { return cursor; }
void setName(const QString& name);
@@ -70,12 +47,14 @@ public:
void setDescending(int i, bool desc);
private:
- QString createField(int i, const QString& prefix, bool verbose) const;
+ // ### Qt7: move to d-ptr
QString cursor;
QString nm;
- QVector<bool> sorts;
+ QList<bool> sorts;
};
+Q_DECLARE_SHARED(QSqlIndex)
+
QT_END_NAMESPACE
#endif // QSQLINDEX_H
diff --git a/src/sql/kernel/qsqlnulldriver_p.h b/src/sql/kernel/qsqlnulldriver_p.h
index 7a40199d71..00226fb18b 100644
--- a/src/sql/kernel/qsqlnulldriver_p.h
+++ b/src/sql/kernel/qsqlnulldriver_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLNULLDRIVER_P_H
#define QSQLNULLDRIVER_P_H
@@ -64,7 +28,7 @@ class QSqlNullResult : public QSqlResult
public:
inline explicit QSqlNullResult(const QSqlDriver* d): QSqlResult(d)
{ QSqlResult::setLastError(
- QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); }
+ QSqlError(QLatin1StringView("Driver not loaded"), QLatin1StringView("Driver not loaded"), QSqlError::ConnectionError)); }
protected:
inline QVariant data(int) override { return QVariant(); }
inline bool reset (const QString&) override { return false; }
@@ -94,7 +58,7 @@ class QSqlNullDriver : public QSqlDriver
public:
inline QSqlNullDriver(): QSqlDriver()
{ QSqlDriver::setLastError(
- QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); }
+ QSqlError(QLatin1StringView("Driver not loaded"), QLatin1StringView("Driver not loaded"), QSqlError::ConnectionError)); }
inline bool hasFeature(DriverFeature) const override { return false; }
inline bool open(const QString &, const QString &, const QString &, const QString &, int, const QString&) override
{ return false; }
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index ce6c997919..14a1116531 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -1,59 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2022 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 "qsqlquery.h"
//#define QT_DEBUG_SQL
-#include "qdebug.h"
-#include "qelapsedtimer.h"
#include "qatomic.h"
+#include "qdebug.h"
+#include "qloggingcategory.h"
#include "qsqlrecord.h"
#include "qsqlresult.h"
#include "qsqldriver.h"
#include "qsqldatabase.h"
#include "private/qsqlnulldriver_p.h"
-#include "qvector.h"
-#include "qmap.h"
+
+#ifdef QT_DEBUG_SQL
+#include "qelapsedtimer.h"
+#endif
QT_BEGIN_NAMESPACE
+static Q_LOGGING_CATEGORY(lcSqlQuery, "qt.sql.qsqlquery")
+
class QSqlQueryPrivate
{
public:
@@ -65,7 +33,7 @@ public:
static QSqlQueryPrivate* shared_null();
};
-Q_GLOBAL_STATIC_WITH_ARGS(QSqlQueryPrivate, nullQueryPrivate, (0))
+Q_GLOBAL_STATIC_WITH_ARGS(QSqlQueryPrivate, nullQueryPrivate, (nullptr))
Q_GLOBAL_STATIC(QSqlNullDriver, nullDriver)
Q_GLOBAL_STATIC_WITH_ARGS(QSqlNullResult, nullResult, (nullDriver()))
@@ -180,7 +148,7 @@ QSqlQueryPrivate::~QSqlQueryPrivate()
them in the same query.
You can retrieve the values of all the fields in a single variable
- (a map) using boundValues().
+ using boundValues().
\note Not all SQL operations support binding values. Refer to your database
system's documentation to check their availability.
@@ -244,12 +212,18 @@ QSqlQuery::QSqlQuery(QSqlResult *result)
QSqlQuery::~QSqlQuery()
{
- if (!d->ref.deref())
+ if (d && !d->ref.deref())
delete d;
}
+#if QT_DEPRECATED_SINCE(6, 2)
/*!
Constructs a copy of \a other.
+
+ \deprecated QSqlQuery cannot be meaningfully copied. Prepared
+ statements, bound values and so on will not work correctly, depending
+ on your database driver (for instance, changing the copy will affect
+ the original). Treat QSqlQuery as a move-only type instead.
*/
QSqlQuery::QSqlQuery(const QSqlQuery& other)
@@ -259,16 +233,53 @@ QSqlQuery::QSqlQuery(const QSqlQuery& other)
}
/*!
+ Assigns \a other to this object.
+
+ \deprecated QSqlQuery cannot be meaningfully copied. Prepared
+ statements, bound values and so on will not work correctly, depending
+ on your database driver (for instance, changing the copy will affect
+ the original). Treat QSqlQuery as a move-only type instead.
+*/
+
+QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other)
+{
+ qAtomicAssign(d, other.d);
+ return *this;
+}
+#endif
+
+/*!
+ \fn QSqlQuery::QSqlQuery(QSqlQuery &&other) noexcept
+ \since 6.2
+ Move-constructs a QSqlQuery from \a other.
+*/
+
+/*!
+ \fn QSqlQuery &QSqlQuery::operator=(QSqlQuery &&other) noexcept
+ \since 6.2
+ Move-assigns \a other to this object.
+*/
+
+/*!
+ \fn void QSqlQuery::swap(QSqlQuery &other) noexcept
+ \since 6.2
+ Swaps \a other to this object. This operation is very
+ fast and never fails.
+*/
+
+/*!
\internal
*/
static void qInit(QSqlQuery *q, const QString& query, const QSqlDatabase &db)
{
QSqlDatabase database = db;
- if (!database.isValid())
- database = QSqlDatabase::database(QLatin1String(QSqlDatabase::defaultConnection), false);
- if (database.isValid()) {
- *q = QSqlQuery(database.driver()->createResult());
+ if (!database.isValid()) {
+ database =
+ QSqlDatabase::database(QLatin1StringView(QSqlDatabase::defaultConnection), false);
}
+ if (database.isValid())
+ *q = QSqlQuery(database.driver()->createResult());
+
if (!query.isEmpty())
q->exec(query);
}
@@ -300,17 +311,6 @@ QSqlQuery::QSqlQuery(const QSqlDatabase &db)
qInit(this, QString(), db);
}
-
-/*!
- Assigns \a other to this object.
-*/
-
-QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other)
-{
- qAtomicAssign(d, other.d);
- return *this;
-}
-
/*!
Returns \c true if the query is not \l{isActive()}{active},
the query is not positioned on a valid record,
@@ -330,19 +330,26 @@ bool QSqlQuery::isNull(int field) const
/*!
\overload
+*/
+bool QSqlQuery::isNull(const QString &name) const
+{
+ return isNull(QStringView(name));
+}
+
+/*!
+ \overload
Returns \c true if there is no field with this \a name; otherwise
returns isNull(int index) for the corresponding field index.
This overload is less efficient than \l{QSqlQuery::}{isNull()}
*/
-
-bool QSqlQuery::isNull(const QString &name) const
+bool QSqlQuery::isNull(QStringView name) const
{
- int index = d->sqlResult->record().indexOf(name);
+ qsizetype index = d->sqlResult->record().indexOf(name);
if (index > -1)
return isNull(index);
- qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name));
+ qCWarning(lcSqlQuery, "QSqlQuery::isNull: unknown field name '%ls'", qUtf16Printable(name.toString()));
return true;
}
@@ -377,6 +384,10 @@ bool QSqlQuery::exec(const QString& query)
QElapsedTimer t;
t.start();
#endif
+ if (!driver()) {
+ qCWarning(lcSqlQuery, "QSqlQuery::exec: called before driver has been set up");
+ return false;
+ }
if (d->ref.loadRelaxed() != 1) {
bool fo = isForwardOnly();
*this = QSqlQuery(driver()->createResult());
@@ -391,19 +402,20 @@ bool QSqlQuery::exec(const QString& query)
}
d->sqlResult->setQuery(query.trimmed());
if (!driver()->isOpen() || driver()->isOpenError()) {
- qWarning("QSqlQuery::exec: database not open");
+ qCWarning(lcSqlQuery, "QSqlQuery::exec: database not open");
return false;
}
if (query.isEmpty()) {
- qWarning("QSqlQuery::exec: empty query");
+ qCWarning(lcSqlQuery, "QSqlQuery::exec: empty query");
return false;
}
bool retval = d->sqlResult->reset(query);
#ifdef QT_DEBUG_SQL
- qDebug().nospace() << "Executed query (" << t.elapsed() << "ms, " << d->sqlResult->size()
- << " results, " << d->sqlResult->numRowsAffected()
- << " affected): " << d->sqlResult->lastQuery();
+ qCDebug(lcSqlQuery()).nospace() << "Executed query (" << t.elapsed() << "ms, "
+ << d->sqlResult->size()
+ << " results, " << d->sqlResult->numRowsAffected()
+ << " affected): " << d->sqlResult->lastQuery();
#endif
return retval;
}
@@ -414,7 +426,7 @@ bool QSqlQuery::exec(const QString& query)
The fields are numbered from left to right using the text of the
\c SELECT statement, e.g. in
- \snippet code/src_sql_kernel_qsqlquery.cpp 0
+ \snippet code/src_sql_kernel_qsqlquery_snippet.cpp 0
field 0 is \c forename and field 1 is \c
surname. Using \c{SELECT *} is not recommended because the order
@@ -431,25 +443,32 @@ QVariant QSqlQuery::value(int index) const
{
if (isActive() && isValid() && (index > -1))
return d->sqlResult->data(index);
- qWarning("QSqlQuery::value: not positioned on a valid record");
+ qCWarning(lcSqlQuery, "QSqlQuery::value: not positioned on a valid record");
return QVariant();
}
/*!
\overload
+*/
+QVariant QSqlQuery::value(const QString &name) const
+{
+ return value(QStringView(name));
+}
+
+/*!
+ \overload
Returns the value of the field called \a name in the current record.
If field \a name does not exist an invalid variant is returned.
This overload is less efficient than \l{QSqlQuery::}{value()}
*/
-
-QVariant QSqlQuery::value(const QString& name) const
+QVariant QSqlQuery::value(QStringView name) const
{
- int index = d->sqlResult->record().indexOf(name);
+ qsizetype index = d->sqlResult->record().indexOf(name);
if (index > -1)
return value(index);
- qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name));
+ qCWarning(lcSqlQuery, "QSqlQuery::value: unknown field name '%ls'", qUtf16Printable(name.toString()));
return QVariant();
}
@@ -595,7 +614,7 @@ bool QSqlQuery::seek(int index, bool relative)
}
// let drivers optimize
if (isForwardOnly() && actualIdx < at()) {
- qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");
+ qCWarning(lcSqlQuery, "QSqlQuery::seek: cannot seek backwards in a forward only query");
return false;
}
if (actualIdx == (at() + 1) && at() != QSql::BeforeFirstRow) {
@@ -701,7 +720,7 @@ bool QSqlQuery::previous()
if (!isSelect() || !isActive())
return false;
if (isForwardOnly()) {
- qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");
+ qCWarning(lcSqlQuery, "QSqlQuery::seek: cannot seek backwards in a forward only query");
return false;
}
@@ -734,7 +753,7 @@ bool QSqlQuery::first()
if (!isSelect() || !isActive())
return false;
if (isForwardOnly() && at() > QSql::BeforeFirstRow) {
- qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");
+ qCWarning(lcSqlQuery, "QSqlQuery::seek: cannot seek backwards in a forward only query");
return false;
}
return d->sqlResult->fetchFirst();
@@ -849,10 +868,9 @@ bool QSqlQuery::isSelect() const
}
/*!
- Returns \c true if you can only scroll forward through a result set;
- otherwise returns \c false.
+ Returns \l forwardOnly.
- \sa setForwardOnly(), next()
+ \sa forwardOnly, next(), seek()
*/
bool QSqlQuery::isForwardOnly() const
{
@@ -860,7 +878,10 @@ bool QSqlQuery::isForwardOnly() const
}
/*!
- Sets forward only mode to \a forward. If \a forward is true, only
+ \property QSqlQuery::forwardOnly
+ \since 6.8
+
+ This property holds the forward only mode. If \a forward is true, only
next() and seek() with positive values, are allowed for navigating
the results.
@@ -889,7 +910,11 @@ bool QSqlQuery::isForwardOnly() const
mode, do not execute any other SQL command on the same database
connection. This will cause the query results to be lost.
- \sa isForwardOnly(), next(), seek(), QSqlResult::setForwardOnly()
+ \sa next(), seek()
+*/
+/*!
+ Sets \l forwardOnly to \a forward.
+ \sa forwardOnly, next(), seek()
*/
void QSqlQuery::setForwardOnly(bool forward)
{
@@ -919,7 +944,7 @@ QSqlRecord QSqlQuery::record() const
QSqlRecord rec = d->sqlResult->record();
if (isValid()) {
- for (int i = 0; i < rec.count(); ++i)
+ for (qsizetype i = 0; i < rec.count(); ++i)
rec.setValue(i, value(i));
}
return rec;
@@ -975,19 +1000,19 @@ bool QSqlQuery::prepare(const QString& query)
d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy());
}
if (!driver()) {
- qWarning("QSqlQuery::prepare: no driver");
+ qCWarning(lcSqlQuery, "QSqlQuery::prepare: no driver");
return false;
}
if (!driver()->isOpen() || driver()->isOpenError()) {
- qWarning("QSqlQuery::prepare: database not open");
+ qCWarning(lcSqlQuery, "QSqlQuery::prepare: database not open");
return false;
}
if (query.isEmpty()) {
- qWarning("QSqlQuery::prepare: empty query");
+ qCWarning(lcSqlQuery, "QSqlQuery::prepare: empty query");
return false;
}
#ifdef QT_DEBUG_SQL
- qDebug("\n QSqlQuery::prepare: %s", query.toLocal8Bit().constData());
+ qCDebug(lcSqlQuery, "\n QSqlQuery::prepare: %ls", qUtf16Printable(query));
#endif
return d->sqlResult->savePrepare(query);
}
@@ -1014,9 +1039,9 @@ bool QSqlQuery::exec()
bool retval = d->sqlResult->exec();
#ifdef QT_DEBUG_SQL
- qDebug().nospace() << "Executed prepared query (" << t.elapsed() << "ms, "
- << d->sqlResult->size() << " results, " << d->sqlResult->numRowsAffected()
- << " affected): " << d->sqlResult->lastQuery();
+ qCDebug(lcSqlQuery).nospace() << "Executed prepared query (" << t.elapsed() << "ms, "
+ << d->sqlResult->size() << " results, " << d->sqlResult->numRowsAffected()
+ << " affected): " << d->sqlResult->lastQuery();
#endif
return retval;
}
@@ -1028,8 +1053,6 @@ bool QSqlQuery::exec()
*/
/*!
- \since 4.2
-
Executes a previously prepared SQL query in a batch. All the bound
parameters have to be lists of variants. If the database doesn't
support batch executions, the driver will simulate it using
@@ -1044,12 +1067,12 @@ bool QSqlQuery::exec()
The example above inserts four new rows into \c myTable:
- \snippet code/src_sql_kernel_qsqlquery.cpp 3
+ \snippet code/src_sql_kernel_qsqlquery_snippet.cpp 3
To bind NULL values, a null QVariant of the relevant type has to be
added to the bound QVariantList; for example, \c
- {QVariant(QVariant::String)} should be used if you are using
- strings.
+ {QVariant(QMetaType::fromType<QString>())} should be used if you are
+ using strings.
\note Every bound QVariantList must contain the same amount of
variants.
@@ -1086,7 +1109,7 @@ bool QSqlQuery::execBatch(BatchExecutionMode mode)
the result into.
To bind a NULL value, use a null QVariant; for example, use
- \c {QVariant(QVariant::String)} if you are binding a string.
+ \c {QVariant(QMetaType::fromType<QString>())} if you are binding a string.
\sa addBindValue(), prepare(), exec(), boundValue(), boundValues()
*/
@@ -1116,7 +1139,7 @@ void QSqlQuery::bindValue(int pos, const QVariant& val, QSql::ParamType paramTyp
overwritten with data from the database after the exec() call.
To bind a NULL value, use a null QVariant; for example, use \c
- {QVariant(QVariant::String)} if you are binding a string.
+ {QVariant(QMetaType::fromType<QString>())} if you are binding a string.
\sa bindValue(), prepare(), exec(), boundValue(), boundValues()
*/
@@ -1137,6 +1160,7 @@ QVariant QSqlQuery::boundValue(const QString& placeholder) const
/*!
Returns the value for the placeholder at position \a pos.
+ \sa boundValues()
*/
QVariant QSqlQuery::boundValue(int pos) const
{
@@ -1144,27 +1168,54 @@ QVariant QSqlQuery::boundValue(int pos) const
}
/*!
- Returns a map of the bound values.
+ \since 6.0
- With named binding, the bound values can be examined in the
- following ways:
+ Returns a list of bound values.
+
+ The order of the list is in binding order, irrespective of whether
+ named or positional binding is used.
+
+ The bound values can be examined in the following way:
\snippet sqldatabase/sqldatabase.cpp 14
- With positional binding, the code becomes:
+ \sa boundValue(), bindValue(), addBindValue(), boundValueNames()
+*/
+
+QVariantList QSqlQuery::boundValues() const
+{
+ const QVariantList values(d->sqlResult->boundValues());
+ return values;
+}
+
+/*!
+ \since 6.6
+
+ Returns the names of all bound values.
- \snippet sqldatabase/sqldatabase.cpp 15
+ The order of the list is in binding order, irrespective of whether
+ named or positional binding is used.
- \sa boundValue(), bindValue(), addBindValue()
+ \sa boundValues(), boundValueName()
*/
-QMap<QString,QVariant> QSqlQuery::boundValues() const
+QStringList QSqlQuery::boundValueNames() const
{
- QMap<QString,QVariant> map;
+ return d->sqlResult->boundValueNames();
+}
+
+/*!
+ \since 6.6
+
+ Returns the bound value name at position \a pos.
- const QVector<QVariant> values(d->sqlResult->boundValues());
- for (int i = 0; i < values.count(); ++i)
- map[d->sqlResult->boundValueName(i)] = values.at(i);
- return map;
+ The order of the list is in binding order, irrespective of whether
+ named or positional binding is used.
+
+ \sa boundValueNames()
+*/
+QString QSqlQuery::boundValueName(int pos) const
+{
+ return d->sqlResult->boundValueName(pos);
}
/*!
@@ -1193,7 +1244,7 @@ QString QSqlQuery::executedQuery() const
For MySQL databases the row's auto-increment field will be returned.
- \note For this function to work in PSQL, the table table must
+ \note For this function to work in PSQL, the table must
contain OIDs, which may not have been created by default. Check the
\c default_with_oids configuration variable to be sure.
@@ -1205,6 +1256,8 @@ QVariant QSqlQuery::lastInsertId() const
}
/*!
+ \property QSqlQuery::numericalPrecisionPolicy
+ \since 6.8
Instruct the database driver to return numerical values with a
precision specified by \a precisionPolicy.
@@ -1223,17 +1276,19 @@ QVariant QSqlQuery::lastInsertId() const
active query. Call \l{exec()}{exec(QString)} or prepare() in order
to activate the policy.
- \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy()
+ \sa QSql::NumericalPrecisionPolicy, QSqlDriver::numericalPrecisionPolicy,
+ QSqlDatabase::numericalPrecisionPolicy
*/
+/*!
+ Sets \l numericalPrecisionPolicy to \a precisionPolicy.
+ */
void QSqlQuery::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
{
d->sqlResult->setNumericalPrecisionPolicy(precisionPolicy);
}
/*!
- Returns the current precision policy.
-
- \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy()
+ Returns the \l numericalPrecisionPolicy.
*/
QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const
{
@@ -1241,8 +1296,41 @@ QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const
}
/*!
- \since 4.3.2
+ \property QSqlQuery::positionalBindingEnabled
+ \since 6.8
+ This property enables or disables the positional \l {Approaches to Binding Values}{binding}
+ for this query, depending on \a enable (default is \c true).
+ Disabling positional bindings is useful if the query itself contains a '?'
+ which must not be handled as a positional binding parameter but, for example,
+ as a JSON operator for a PostgreSQL database.
+
+ This property will have no effect when the database has native
+ support for positional bindings with question marks (see also
+ \l{QSqlDriver::PositionalPlaceholders}).
+*/
+/*!
+ Sets \l positionalBindingEnabled to \a enable.
+ \since 6.7
+ \sa positionalBindingEnabled
+*/
+void QSqlQuery::setPositionalBindingEnabled(bool enable)
+{
+ d->sqlResult->setPositionalBindingEnabled(enable);
+}
+
+/*!
+ Returns \l positionalBindingEnabled.
+ \since 6.7
+ \sa positionalBindingEnabled
+*/
+bool QSqlQuery::isPositionalBindingEnabled() const
+{
+ return d->sqlResult->isPositionalBindingEnabled();
+}
+
+
+/*!
Instruct the database driver that no more data will be fetched from
this query until it is re-executed. There is normally no need to
call this function, but it may be helpful in order to free resources
@@ -1264,8 +1352,6 @@ void QSqlQuery::finish()
}
/*!
- \since 4.4
-
Discards the current result set and navigates to the next if available.
Some databases are capable of returning multiple result sets for
@@ -1291,7 +1377,7 @@ void QSqlQuery::finish()
databases may have restrictions on which statements are allowed to
be used in a SQL batch.
- \sa QSqlDriver::hasFeature(), setForwardOnly(), next(), isSelect(),
+ \sa QSqlDriver::hasFeature(), forwardOnly, next(), isSelect(),
numRowsAffected(), isActive(), lastError()
*/
bool QSqlQuery::nextResult()
@@ -1302,3 +1388,5 @@ bool QSqlQuery::nextResult()
}
QT_END_NAMESPACE
+
+#include "moc_qsqlquery.cpp"
diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h
index 3be04c492c..244b026205 100644
--- a/src/sql/kernel/qsqlquery.h
+++ b/src/sql/kernel/qsqlquery.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLQUERY_H
#define QSQLQUERY_H
@@ -43,32 +7,56 @@
#include <QtSql/qtsqlglobal.h>
#include <QtSql/qsqldatabase.h>
#include <QtCore/qstring.h>
+#include <QtCore/qvariant.h>
+// clazy:excludeall=qproperty-without-notify
QT_BEGIN_NAMESPACE
-class QVariant;
class QSqlDriver;
class QSqlError;
class QSqlResult;
class QSqlRecord;
-template <class Key, class T> class QMap;
class QSqlQueryPrivate;
+
class Q_SQL_EXPORT QSqlQuery
{
+ Q_GADGET
public:
+ Q_PROPERTY(bool forwardOnly READ isForwardOnly WRITE setForwardOnly)
+ Q_PROPERTY(bool positionalBindingEnabled READ isPositionalBindingEnabled WRITE setPositionalBindingEnabled)
+ Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
+
explicit QSqlQuery(QSqlResult *r);
explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase());
explicit QSqlQuery(const QSqlDatabase &db);
- QSqlQuery(const QSqlQuery& other);
- QSqlQuery& operator=(const QSqlQuery& other);
+
+#if QT_DEPRECATED_SINCE(6, 2)
+ QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move construction instead.")
+ QSqlQuery(const QSqlQuery &other);
+ QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move assignment instead.")
+ QSqlQuery& operator=(const QSqlQuery &other);
+#else
+ QSqlQuery(const QSqlQuery &other) = delete;
+ QSqlQuery& operator=(const QSqlQuery &other) = delete;
+#endif
+
+ QSqlQuery(QSqlQuery &&other) noexcept
+ : d(std::exchange(other.d, nullptr))
+ {}
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlQuery)
+
~QSqlQuery();
+ void swap(QSqlQuery &other) noexcept
+ { qt_ptr_swap(d, other.d); }
+
bool isValid() const;
bool isActive() const;
bool isNull(int field) const;
bool isNull(const QString &name) const;
+ bool isNull(QStringView name) const;
int at() const;
QString lastQuery() const;
int numRowsAffected() const;
@@ -83,11 +71,15 @@ public:
void setForwardOnly(bool forward);
bool exec(const QString& query);
QVariant value(int i) const;
- QVariant value(const QString& name) const;
+ QVariant value(const QString &name) const;
+ QVariant value(QStringView name) const;
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
+ void setPositionalBindingEnabled(bool enable);
+ bool isPositionalBindingEnabled() const;
+
bool seek(int i, bool relative = false);
bool next();
bool previous();
@@ -107,7 +99,9 @@ public:
void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In);
QVariant boundValue(const QString& placeholder) const;
QVariant boundValue(int pos) const;
- QMap<QString, QVariant> boundValues() const;
+ QVariantList boundValues() const;
+ QStringList boundValueNames() const;
+ QString boundValueName(int pos) const;
QString executedQuery() const;
QVariant lastInsertId() const;
void finish();
diff --git a/src/sql/kernel/qsqlrecord.cpp b/src/sql/kernel/qsqlrecord.cpp
index c4dc5d1adb..53b64c1464 100644
--- a/src/sql/kernel/qsqlrecord.cpp
+++ b/src/sql/kernel/qsqlrecord.cpp
@@ -1,85 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlrecord.h"
-#include "qdebug.h"
-#include "qstringlist.h"
#include "qatomic.h"
+#include "qdebug.h"
+#include "qlist.h"
#include "qsqlfield.h"
#include "qstring.h"
-#include "qvector.h"
QT_BEGIN_NAMESPACE
-class QSqlRecordPrivate
+class QSqlRecordPrivate : public QSharedData
{
public:
- QSqlRecordPrivate();
- QSqlRecordPrivate(const QSqlRecordPrivate &other);
-
- inline bool contains(int index) { return index >= 0 && index < fields.count(); }
- QString createField(int index, const QString &prefix) const;
+ inline bool contains(qsizetype index) const
+ {
+ return index >= 0 && index < fields.size();
+ }
- QVector<QSqlField> fields;
- QAtomicInt ref;
+ QList<QSqlField> fields;
};
-
-QSqlRecordPrivate::QSqlRecordPrivate() : ref(1)
-{
-}
-
-QSqlRecordPrivate::QSqlRecordPrivate(const QSqlRecordPrivate &other): fields(other.fields), ref(1)
-{
-}
-
-/*! \internal
- Just for compat
-*/
-QString QSqlRecordPrivate::createField(int index, const QString &prefix) const
-{
- QString f;
- if (!prefix.isEmpty())
- f = prefix + QLatin1Char('.');
- f += fields.at(index).name();
- return f;
-}
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlRecordPrivate)
/*!
\class QSqlRecord
@@ -122,8 +64,8 @@ QString QSqlRecordPrivate::createField(int index, const QString &prefix) const
*/
QSqlRecord::QSqlRecord()
+ : d(new QSqlRecordPrivate)
{
- d = new QSqlRecordPrivate();
}
/*!
@@ -133,11 +75,39 @@ QSqlRecord::QSqlRecord()
of a record in \l{constant time}.
*/
-QSqlRecord::QSqlRecord(const QSqlRecord& other)
-{
- d = other.d;
- d->ref.ref();
-}
+QSqlRecord::QSqlRecord(const QSqlRecord &other)
+ = default;
+
+/*!
+ \fn QSqlRecord::QSqlRecord(QSqlRecord &&other)
+ \since 6.6
+
+ Move-constructs a new QSqlRecord from \a other.
+
+ \note The moved-from object \a other is placed in a partially-formed state,
+ in which the only valid operations are destruction and assignment of a new
+ value.
+*/
+
+/*!
+ \fn QSqlRecord &QSqlRecord::operator=(QSqlRecord &&other)
+ \since 6.6
+
+ Move-assigns \a other to this QSqlRecord instance.
+
+ \note The moved-from object \a other is placed in a partially-formed state,
+ in which the only valid operations are destruction and assignment of a new
+ value.
+*/
+
+/*!
+ \fn void QSqlRecord::swap(QSqlRecord &other)
+ \since 6.6
+
+ Swaps SQL record \a other with this SQL record. This operation is very fast
+ and never fails.
+*/
+
/*!
Sets the record equal to \a other.
@@ -146,21 +116,16 @@ QSqlRecord::QSqlRecord(const QSqlRecord& other)
of a record in \l{constant time}.
*/
-QSqlRecord& QSqlRecord::operator=(const QSqlRecord& other)
-{
- qAtomicAssign(d, other.d);
- return *this;
-}
+QSqlRecord& QSqlRecord::operator=(const QSqlRecord &other)
+ = default;
/*!
Destroys the object and frees any allocated resources.
*/
QSqlRecord::~QSqlRecord()
-{
- if (!d->ref.deref())
- delete d;
-}
+ = default;
+
/*!
\fn bool QSqlRecord::operator!=(const QSqlRecord &other) const
@@ -197,14 +162,21 @@ QVariant QSqlRecord::value(int index) const
/*!
\overload
+*/
+QVariant QSqlRecord::value(const QString &name) const
+{
+ return value(QStringView(name));
+}
+
+/*!
+ \overload
Returns the value of the field called \a name in the record. If
field \a name does not exist an invalid variant is returned.
- \sa indexOf()
+ \sa indexOf(), isNull()
*/
-
-QVariant QSqlRecord::value(const QString& name) const
+QVariant QSqlRecord::value(QStringView name) const
{
return value(indexOf(name));
}
@@ -222,22 +194,29 @@ QString QSqlRecord::fieldName(int index) const
}
/*!
+ \overload
+*/
+int QSqlRecord::indexOf(const QString &name) const
+{
+ return indexOf(QStringView(name));
+}
+
+/*!
Returns the position of the field called \a name within the
record, or -1 if it cannot be found. Field names are not
case-sensitive. If more than one field matches, the first one is
returned.
\sa fieldName()
-*/
-
-int QSqlRecord::indexOf(const QString& name) const
+ */
+int QSqlRecord::indexOf(QStringView name) const
{
- QStringRef tableName;
- QStringRef fieldName(&name);
- const int idx = name.indexOf(QLatin1Char('.'));
+ QStringView tableName;
+ QStringView fieldName(name);
+ const qsizetype idx = name.indexOf(u'.');
if (idx != -1) {
- tableName = name.leftRef(idx);
- fieldName = name.midRef(idx + 1);
+ tableName = fieldName.left(idx);
+ fieldName = fieldName.mid(idx + 1);
}
const int cnt = count();
for (int i = 0; i < cnt; ++i) {
@@ -264,11 +243,23 @@ QSqlField QSqlRecord::field(int index) const
return d->fields.value(index);
}
-/*! \overload
- Returns the field called \a name.
+/*!
+ \overload
*/
QSqlField QSqlRecord::field(const QString &name) const
{
+ return field(QStringView(name));
+}
+
+/*!
+ \overload
+
+ Returns the field called \a name. If the field called
+ \a name is not found, function returns
+ a \l{default-constructed value}.
+ */
+QSqlField QSqlRecord::field(QStringView name) const
+{
return field(indexOf(name));
}
@@ -279,7 +270,7 @@ QSqlField QSqlRecord::field(const QString &name) const
\sa insert(), replace(), remove()
*/
-void QSqlRecord::append(const QSqlField& field)
+void QSqlRecord::append(const QSqlField &field)
{
detach();
d->fields.append(field);
@@ -290,7 +281,7 @@ void QSqlRecord::append(const QSqlField& field)
\sa append(), replace(), remove()
*/
-void QSqlRecord::insert(int pos, const QSqlField& field)
+void QSqlRecord::insert(int pos, const QSqlField &field)
{
detach();
d->fields.insert(pos, field);
@@ -303,7 +294,7 @@ void QSqlRecord::insert(int pos, const QSqlField& field)
\sa append(), insert(), remove()
*/
-void QSqlRecord::replace(int pos, const QSqlField& field)
+void QSqlRecord::replace(int pos, const QSqlField &field)
{
if (!d->contains(pos))
return;
@@ -354,11 +345,18 @@ bool QSqlRecord::isEmpty() const
/*!
+ \overload
+*/
+bool QSqlRecord::contains(const QString &name) const
+{
+ return contains(QStringView(name));
+}
+
+/*!
Returns \c true if there is a field in the record called \a name;
otherwise returns \c false.
*/
-
-bool QSqlRecord::contains(const QString& name) const
+bool QSqlRecord::contains(QStringView name) const
{
return indexOf(name) >= 0;
}
@@ -373,12 +371,18 @@ bool QSqlRecord::contains(const QString& name) const
void QSqlRecord::clearValues()
{
detach();
- int count = d->fields.count();
- for (int i = 0; i < count; ++i)
- d->fields[i].clear();
+ for (QSqlField &f : d->fields)
+ f.clear();
}
/*!
+ \overload
+*/
+void QSqlRecord::setGenerated(const QString &name, bool generated)
+{
+ setGenerated(QStringView(name), generated);
+}
+/*!
Sets the generated flag for the field called \a name to \a
generated. If the field does not exist, nothing happens. Only
fields that have \a generated set to true are included in the SQL
@@ -386,15 +390,12 @@ void QSqlRecord::clearValues()
\sa isGenerated()
*/
-
-void QSqlRecord::setGenerated(const QString& name, bool generated)
+void QSqlRecord::setGenerated(QStringView name, bool generated)
{
setGenerated(indexOf(name), generated);
}
/*!
- \overload
-
Sets the generated flag for the field \a index to \a generated.
\sa isGenerated()
@@ -409,10 +410,10 @@ void QSqlRecord::setGenerated(int index, bool generated)
}
/*!
- \overload
-
Returns \c true if the field \a index is null or if there is no field at
position \a index; otherwise returns \c false.
+
+ \sa setNull()
*/
bool QSqlRecord::isNull(int index) const
{
@@ -420,12 +421,22 @@ bool QSqlRecord::isNull(int index) const
}
/*!
+ \overload
+*/
+bool QSqlRecord::isNull(const QString &name) const
+{
+ return isNull(QStringView(name));
+}
+
+/*!
+ \overload
+
Returns \c true if the field called \a name is null or if there is no
field called \a name; otherwise returns \c false.
\sa setNull()
*/
-bool QSqlRecord::isNull(const QString& name) const
+bool QSqlRecord::isNull(QStringView name) const
{
return isNull(indexOf(name));
}
@@ -446,29 +457,45 @@ void QSqlRecord::setNull(int index)
/*!
\overload
+*/
+void QSqlRecord::setNull(const QString &name)
+{
+ setNull(QStringView(name));
+}
+
+/*!
+ \overload
Sets the value of the field called \a name to null. If the field
does not exist, nothing happens.
*/
-void QSqlRecord::setNull(const QString& name)
+void QSqlRecord::setNull(QStringView name)
{
setNull(indexOf(name));
}
+/*!
+ \overload
+*/
+bool QSqlRecord::isGenerated(const QString &name) const
+{
+ return isGenerated(QStringView(name));
+}
/*!
+ \overload
+
Returns \c true if the record has a field called \a name and this
field is to be generated (the default); otherwise returns \c false.
\sa setGenerated()
*/
-bool QSqlRecord::isGenerated(const QString& name) const
+bool QSqlRecord::isGenerated(QStringView name) const
{
return isGenerated(indexOf(name));
}
-/*! \overload
-
+/*!
Returns \c true if the record has a field at position \a index and this
field is to be generated (the default); otherwise returns \c false.
@@ -487,7 +514,7 @@ bool QSqlRecord::isGenerated(int index) const
int QSqlRecord::count() const
{
- return d->fields.count();
+ return d->fields.size();
}
/*!
@@ -497,7 +524,7 @@ int QSqlRecord::count() const
\sa setNull()
*/
-void QSqlRecord::setValue(int index, const QVariant& val)
+void QSqlRecord::setValue(int index, const QVariant &val)
{
if (!d->contains(index))
return;
@@ -505,15 +532,22 @@ void QSqlRecord::setValue(int index, const QVariant& val)
d->fields[index].setValue(val);
}
-
+/*!
+ \overload
+*/
+void QSqlRecord::setValue(const QString &name, const QVariant &val)
+{
+ setValue(QStringView(name), val);
+}
/*!
\overload
Sets the value of the field called \a name to \a val. If the field
does not exist, nothing happens.
-*/
-void QSqlRecord::setValue(const QString& name, const QVariant& val)
+ \sa setNull()
+*/
+void QSqlRecord::setValue(QStringView name, const QVariant &val)
{
setValue(indexOf(name), val);
}
@@ -523,7 +557,7 @@ void QSqlRecord::setValue(const QString& name, const QVariant& val)
*/
void QSqlRecord::detach()
{
- qAtomicDetach(d);
+ d.detach();
}
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h
index 94631bafd9..8f653ba5e1 100644
--- a/src/sql/kernel/qsqlrecord.h
+++ b/src/sql/kernel/qsqlrecord.h
@@ -1,95 +1,73 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLRECORD_H
#define QSQLRECORD_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
class QSqlField;
-class QStringList;
class QVariant;
class QSqlRecordPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlRecordPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlRecord
{
public:
QSqlRecord();
- QSqlRecord(const QSqlRecord& other);
- QSqlRecord& operator=(const QSqlRecord& other);
+ QSqlRecord(const QSqlRecord &other);
+ QSqlRecord(QSqlRecord &&other) noexcept = default;
+ QSqlRecord& operator=(const QSqlRecord &other);
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlRecord)
~QSqlRecord();
+ void swap(QSqlRecord &other) noexcept { d.swap(other.d); }
+
bool operator==(const QSqlRecord &other) const;
inline bool operator!=(const QSqlRecord &other) const { return !operator==(other); }
QVariant value(int i) const;
- QVariant value(const QString& name) const;
- void setValue(int i, const QVariant& val);
- void setValue(const QString& name, const QVariant& val);
+ QVariant value(const QString &name) const;
+ QVariant value(QStringView name) const;
+ void setValue(int i, const QVariant &val);
+ void setValue(const QString &name, const QVariant &val);
+ void setValue(QStringView name, const QVariant &val);
void setNull(int i);
- void setNull(const QString& name);
+ void setNull(const QString &name);
+ void setNull(QStringView name);
bool isNull(int i) const;
- bool isNull(const QString& name) const;
+ bool isNull(const QString &name) const;
+ bool isNull(QStringView name) const;
int indexOf(const QString &name) const;
+ int indexOf(QStringView name) const;
QString fieldName(int i) const;
QSqlField field(int i) const;
QSqlField field(const QString &name) const;
+ QSqlField field(QStringView name) const;
bool isGenerated(int i) const;
- bool isGenerated(const QString& name) const;
- void setGenerated(const QString& name, bool generated);
+ bool isGenerated(const QString &name) const;
+ bool isGenerated(QStringView name) const;
+ void setGenerated(const QString &name, bool generated);
+ void setGenerated(QStringView name, bool generated);
void setGenerated(int i, bool generated);
- void append(const QSqlField& field);
- void replace(int pos, const QSqlField& field);
- void insert(int pos, const QSqlField& field);
+ void append(const QSqlField &field);
+ void replace(int pos, const QSqlField &field);
+ void insert(int pos, const QSqlField &field);
void remove(int pos);
bool isEmpty() const;
- bool contains(const QString& name) const;
+ bool contains(const QString &name) const;
+ bool contains(QStringView name) const;
void clear();
void clearValues();
int count() const;
@@ -97,9 +75,11 @@ public:
private:
void detach();
- QSqlRecordPrivate* d;
+ QExplicitlySharedDataPointer<QSqlRecordPrivate> d;
};
+Q_DECLARE_SHARED(QSqlRecord)
+
#ifndef QT_NO_DEBUG_STREAM
Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlRecord &);
#endif
diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp
index cc91c6d0ed..59e9879cf0 100644
--- a/src/sql/kernel/qsqlresult.cpp
+++ b/src/sql/kernel/qsqlresult.cpp
@@ -1,80 +1,31 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlresult.h"
-#include "qvariant.h"
-#include "qhash.h"
+#include "qlist.h"
+#include "qsqldriver.h"
#include "qsqlerror.h"
#include "qsqlfield.h"
#include "qsqlrecord.h"
-#include "qvector.h"
-#include "qsqldriver.h"
-#include "qpointer.h"
#include "qsqlresult_p.h"
+#include "quuid.h"
+#include "qvariant.h"
+#include "qdatetime.h"
#include "private/qsqldriver_p.h"
-#include <QDebug>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
QString QSqlResultPrivate::holderAt(int index) const
{
return holders.size() > index ? holders.at(index).holderName : fieldSerial(index);
}
-// return a unique id for bound names
-QString QSqlResultPrivate::fieldSerial(int i) const
+QString QSqlResultPrivate::fieldSerial(qsizetype i) const
{
- ushort arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- ushort *end = &arr[(sizeof(arr)/sizeof(*arr))];
- ushort *ptr = end;
-
- while (i > 0) {
- *(--ptr) = 'a' + i % 16;
- i >>= 4;
- }
-
- const int nb = end - ptr;
- *(--ptr) = 'a' + nb;
- *(--ptr) = ':';
-
- return QString::fromUtf16(ptr, int(end - ptr));
+ return QString(":%1"_L1).arg(i);
}
static bool qIsAlnum(QChar ch)
@@ -86,19 +37,22 @@ static bool qIsAlnum(QChar ch)
QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const
{
- int n = query.size();
+ if (!positionalBindingEnabled)
+ return query;
+
+ const qsizetype n = query.size();
QString result;
result.reserve(n * 5 / 4);
QChar closingQuote;
- int count = 0;
+ qsizetype count = 0;
bool ignoreBraces = (sqldriver->dbmsType() == QSqlDriver::PostgreSQL);
- for (int i = 0; i < n; ++i) {
+ for (qsizetype i = 0; i < n; ++i) {
QChar ch = query.at(i);
if (!closingQuote.isNull()) {
if (ch == closingQuote) {
- if (closingQuote == QLatin1Char(']')
+ if (closingQuote == u']'
&& i + 1 < n && query.at(i + 1) == closingQuote) {
// consume the extra character. don't close.
++i;
@@ -109,13 +63,13 @@ QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const
}
result += ch;
} else {
- if (ch == QLatin1Char('?')) {
+ if (ch == u'?') {
result += fieldSerial(count++);
} else {
- if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`'))
+ if (ch == u'\'' || ch == u'"' || ch == u'`')
closingQuote = ch;
- else if (!ignoreBraces && ch == QLatin1Char('['))
- closingQuote = QLatin1Char(']');
+ else if (!ignoreBraces && ch == u'[')
+ closingQuote = u']';
result += ch;
}
}
@@ -126,20 +80,28 @@ QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const
QString QSqlResultPrivate::namedToPositionalBinding(const QString &query)
{
- int n = query.size();
+ // In the Interbase case if it is an EXECUTE BLOCK then it is up to the
+ // caller to make sure that it is not using named bindings for the wrong
+ // parts of the query since Interbase uses them literally
+ if (sqldriver->dbmsType() == QSqlDriver::Interbase &&
+ query.trimmed().startsWith("EXECUTE BLOCK"_L1, Qt::CaseInsensitive))
+ return query;
+
+ const qsizetype n = query.size();
QString result;
result.reserve(n);
QChar closingQuote;
int count = 0;
- int i = 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);
if (!closingQuote.isNull()) {
if (ch == closingQuote) {
- if (closingQuote == QLatin1Char(']')
+ if (closingQuote == u']'
&& i + 1 < n && query.at(i + 1) == closingQuote) {
// consume the extra character. don't close.
++i;
@@ -151,22 +113,28 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query)
result += ch;
++i;
} else {
- if (ch == QLatin1Char(':')
- && (i == 0 || query.at(i - 1) != QLatin1Char(':'))
+ if (ch == u':'
+ && (i == 0 || query.at(i - 1) != u':')
&& (i + 1 < n && qIsAlnum(query.at(i + 1)))) {
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 += QLatin1Char('?');
i = pos;
} else {
- if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`'))
+ if (ch == u'\'' || ch == u'"' || ch == u'`')
closingQuote = ch;
- else if (!ignoreBraces && ch == QLatin1Char('['))
- closingQuote = QLatin1Char(']');
+ else if (!ignoreBraces && ch == u'[')
+ closingQuote = u']';
result += ch;
++i;
}
@@ -626,6 +594,33 @@ bool QSqlResult::prepare(const QString& query)
return true; // fake prepares should always succeed
}
+bool QSqlResultPrivate::isVariantNull(const QVariant &variant)
+{
+ if (variant.isNull())
+ return true;
+
+ switch (variant.typeId()) {
+ case qMetaTypeId<QString>():
+ return static_cast<const QString*>(variant.constData())->isNull();
+ case qMetaTypeId<QByteArray>():
+ return static_cast<const QByteArray*>(variant.constData())->isNull();
+ case qMetaTypeId<QDateTime>():
+ // We treat invalid date-time as null, since its ISODate would be empty.
+ return !static_cast<const QDateTime*>(variant.constData())->isValid();
+ case qMetaTypeId<QDate>():
+ return static_cast<const QDate*>(variant.constData())->isNull();
+ case qMetaTypeId<QTime>():
+ // As for QDateTime, QTime can be invalid without being null.
+ return !static_cast<const QTime*>(variant.constData())->isValid();
+ case qMetaTypeId<QUuid>():
+ return static_cast<const QUuid*>(variant.constData())->isNull();
+ default:
+ break;
+ }
+
+ return false;
+}
+
/*!
Executes the query, returning true if successful; otherwise returns
false.
@@ -639,34 +634,31 @@ bool QSqlResult::exec()
// fake preparation - just replace the placeholders..
QString query = lastQuery();
if (d->binds == NamedBinding) {
- int i;
- QVariant val;
- QString holder;
- for (i = d->holders.count() - 1; i >= 0; --i) {
- holder = d->holders.at(i).holderName;
- val = d->values.value(d->indexes.value(holder).value(0,-1));
- QSqlField f(QLatin1String(""), val.type());
- f.setValue(val);
+ for (qsizetype i = d->holders.size() - 1; i >= 0; --i) {
+ const QString &holder = d->holders.at(i).holderName;
+ const QVariant val = d->values.value(d->indexes.value(holder).value(0,-1));
+ QSqlField f(""_L1, val.metaType());
+ if (QSqlResultPrivate::isVariantNull(val))
+ f.setValue(QVariant());
+ else
+ f.setValue(val);
query = query.replace(d->holders.at(i).holderPos,
- holder.length(), driver()->formatValue(f));
+ holder.size(), driver()->formatValue(f));
}
} else {
- QString val;
- int i = 0;
- int idx = 0;
- for (idx = 0; idx < d->values.count(); ++idx) {
- i = query.indexOf(QLatin1Char('?'), i);
+ qsizetype i = 0;
+ for (const QVariant &var : std::as_const(d->values)) {
+ i = query.indexOf(u'?', i);
if (i == -1)
continue;
- QVariant var = d->values.value(idx);
- QSqlField f(QLatin1String(""), var.type());
- if (var.isNull())
+ QSqlField f(""_L1, var.metaType());
+ if (QSqlResultPrivate::isVariantNull(var))
f.clear();
else
f.setValue(var);
- val = driver()->formatValue(f);
- query = query.replace(i, 1, driver()->formatValue(f));
- i += val.length();
+ const QString val = driver()->formatValue(f);
+ query = query.replace(i, 1, val);
+ i += val.size();
}
}
@@ -689,10 +681,10 @@ void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType param
{
Q_D(QSqlResult);
d->binds = PositionalBinding;
- QVector<int> &indexes = d->indexes[d->fieldSerial(index)];
+ QList<int> &indexes = d->indexes[d->fieldSerial(index)];
if (!indexes.contains(index))
indexes.append(index);
- if (d->values.count() <= index)
+ if (d->values.size() <= index)
d->values.resize(index + 1);
d->values[index] = val;
if (paramType != QSql::In || !d->types.isEmpty())
@@ -716,9 +708,9 @@ void QSqlResult::bindValue(const QString& placeholder, const QVariant& val,
d->binds = NamedBinding;
// if the index has already been set when doing emulated named
// bindings - don't reset it
- const QVector<int> indexes = d->indexes.value(placeholder);
+ const QList<int> indexes = d->indexes.value(placeholder);
for (int idx : indexes) {
- if (d->values.count() <= idx)
+ if (d->values.size() <= idx)
d->values.resize(idx + 1);
d->values[idx] = val;
if (paramType != QSql::In || !d->types.isEmpty())
@@ -763,7 +755,7 @@ QVariant QSqlResult::boundValue(int index) const
QVariant QSqlResult::boundValue(const QString& placeholder) const
{
Q_D(const QSqlResult);
- const QVector<int> indexes = d->indexes.value(placeholder);
+ const QList<int> indexes = d->indexes.value(placeholder);
return d->values.value(indexes.value(0,-1));
}
@@ -798,22 +790,37 @@ QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const
int QSqlResult::boundValueCount() const
{
Q_D(const QSqlResult);
- return d->values.count();
+ return d->values.size();
}
/*!
- 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()
*/
-QVector<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.
*/
QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const
@@ -856,10 +863,24 @@ void QSqlResult::resetBindCount()
}
/*!
+ Returns the names of all bound values.
+
+ \sa boundValue(), boundValueName()
+ */
+QStringList QSqlResult::boundValueNames() const
+{
+ Q_D(const QSqlResult);
+ QList<QString> ret;
+ for (const QHolder &holder : std::as_const(d->holders))
+ ret.push_back(holder.holderName);
+ return ret;
+}
+
+/*!
Returns the name of the bound value at position \a index in the
current record (row).
- \sa boundValue()
+ \sa boundValue(), boundValueNames()
*/
QString QSqlResult::boundValueName(int index) const
{
@@ -925,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
@@ -942,7 +961,7 @@ void QSqlResult::virtual_hook(int, void *)
contain equal amount of values (rows).
NULL values are passed in as typed QVariants, for example
- \c {QVariant(QVariant::Int)} for an integer NULL value.
+ \c {QVariant(QMetaType::fromType<int>())} for an integer NULL value.
Example:
@@ -957,11 +976,13 @@ bool QSqlResult::execBatch(bool arrayBind)
Q_UNUSED(arrayBind);
Q_D(QSqlResult);
- QVector<QVariant> values = d->values;
- if (values.count() == 0)
+ const QList<QVariant> values = d->values;
+ if (values.size() == 0)
return false;
- for (int i = 0; i < values.at(0).toList().count(); ++i) {
- for (int j = 0; j < values.count(); ++j)
+ const qsizetype batchCount = values.at(0).toList().size();
+ const qsizetype valueCount = values.size();
+ for (qsizetype i = 0; i < batchCount; ++i) {
+ for (qsizetype j = 0; j < valueCount; ++j)
bindValue(j, values.at(j).toList().at(i), QSql::In);
if (!exec())
return false;
@@ -992,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()
{
@@ -1022,7 +1060,7 @@ bool QSqlResult::nextResult()
This snippet returns the handle for PostgreSQL or MySQL:
- \snippet code/src_sql_kernel_qsqlresult.cpp 2
+ \snippet code/src_sql_kernel_qsqlresult_snippet.cpp 2
\sa QSqlDriver::handle()
*/
diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h
index d4192bfad2..4200bbde34 100644
--- a/src/sql/kernel/qsqlresult.h
+++ b/src/sql/kernel/qsqlresult.h
@@ -1,58 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLRESULT_H
#define QSQLRESULT_H
#include <QtSql/qtsqlglobal.h>
#include <QtCore/qvariant.h>
-#include <QtCore/qvector.h>
-
-// for testing:
-class tst_QSqlQuery;
+#include <QtCore/qcontainerfwd.h>
QT_BEGIN_NAMESPACE
class QString;
class QSqlRecord;
-template <typename T> class QVector;
class QVariant;
class QSqlDriver;
class QSqlError;
@@ -63,8 +23,6 @@ class Q_SQL_EXPORT QSqlResult
Q_DECLARE_PRIVATE(QSqlResult)
friend class QSqlQuery;
friend class QSqlTableModelPrivate;
- // for testing:
- friend class ::tst_QSqlQuery;
public:
virtual ~QSqlResult();
@@ -106,8 +64,14 @@ protected:
QSql::ParamType bindValueType(const QString& placeholder) const;
QSql::ParamType bindValueType(int pos) const;
int boundValueCount() const;
- QVector<QVariant>& boundValues() const;
+#if QT_SQL_REMOVED_SINCE(6, 6)
+ QList<QVariant> &boundValues() const;
+#endif
+ QVariantList &boundValues(QT6_DECL_NEW_OVERLOAD);
+ QVariantList boundValues(QT6_DECL_NEW_OVERLOAD) const;
+
QString executedQuery() const;
+ QStringList boundValueNames() const;
QString boundValueName(int pos) const;
void clear();
bool hasOutValues() const;
@@ -133,6 +97,8 @@ protected:
virtual void detachFromResultSet();
virtual void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy);
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
+ void setPositionalBindingEnabled(bool enable);
+ bool isPositionalBindingEnabled() const;
virtual bool nextResult();
void resetBindCount(); // HACK
diff --git a/src/sql/kernel/qsqlresult_p.h b/src/sql/kernel/qsqlresult_p.h
index 3b9697046d..6eebdaaba4 100644
--- a/src/sql/kernel/qsqlresult_p.h
+++ b/src/sql/kernel/qsqlresult_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLRESULT_P_H
#define QSQLRESULT_P_H
@@ -53,6 +17,7 @@
#include <QtSql/private/qtsqlglobal_p.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qhash.h>
#include "qsqlerror.h"
#include "qsqlresult.h"
#include "qsqldriver.h"
@@ -65,11 +30,11 @@ QT_BEGIN_NAMESPACE
inline Class##Private* drv_d_func() { return !sqldriver ? nullptr : reinterpret_cast<Class *>(static_cast<QSqlDriver*>(sqldriver))->d_func(); }
struct QHolder {
- QHolder(const QString &hldr = QString(), int index = -1): holderName(hldr), holderPos(index) { }
+ QHolder(const QString &hldr = QString(), qsizetype index = -1): holderName(hldr), holderPos(index) { }
bool operator==(const QHolder &h) const { return h.holderPos == holderPos && h.holderName == holderName; }
bool operator!=(const QHolder &h) const { return h.holderPos != holderPos || h.holderName != holderName; }
QString holderName;
- int holderPos;
+ qsizetype holderPos;
};
class Q_SQL_EXPORT QSqlResultPrivate
@@ -107,7 +72,7 @@ public:
clearIndex();
}
- virtual QString fieldSerial(int) const;
+ virtual QString fieldSerial(qsizetype) const;
QString positionalToNamedBinding(const QString &query) const;
QString namedToPositionalBinding(const QString &query);
QString holderAt(int index) const;
@@ -119,11 +84,11 @@ public:
QString executedQuery;
QHash<int, QSql::ParamType> types;
- QVector<QVariant> values;
- using IndexMap = QHash<QString, QVector<int> >;
+ QList<QVariant> values;
+ using IndexMap = QHash<QString, QList<int>>;
IndexMap indexes;
- using QHolderVector = QVector<QHolder>;
+ using QHolderVector = QList<QHolder>;
QHolderVector holders;
QSqlResult::BindingSyntax binds = QSqlResult::PositionalBinding;
@@ -133,6 +98,9 @@ public:
bool active = false;
bool isSel = false;
bool forwardOnly = false;
+ bool positionalBindingEnabled = true;
+
+ static bool isVariantNull(const QVariant &variant);
};
QT_END_NAMESPACE
diff --git a/src/sql/kernel/qtsqlglobal.h b/src/sql/kernel/qtsqlglobal.h
index ec79e8da1e..977d97abbf 100644
--- a/src/sql/kernel/qtsqlglobal.h
+++ b/src/sql/kernel/qtsqlglobal.h
@@ -1,60 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QTSQLGLOBAL_H
#define QTSQLGLOBAL_H
+#if 0
+#pragma qt_class(QSql)
+#endif
+
#include <QtCore/qglobal.h>
#include <QtSql/qtsql-config.h>
+#include <QtSql/qtsqlexports.h>
QT_BEGIN_NAMESPACE
-#ifndef QT_STATIC
-# if defined(QT_BUILD_SQL_LIB)
-# define Q_SQL_EXPORT Q_DECL_EXPORT
-# else
-# define Q_SQL_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_SQL_EXPORT
-#endif
-
namespace QSql
{
enum Location
diff --git a/src/sql/kernel/qtsqlglobal_p.h b/src/sql/kernel/qtsqlglobal_p.h
index 78a2461257..df217fb68f 100644
--- a/src/sql/kernel/qtsqlglobal_p.h
+++ b/src/sql/kernel/qtsqlglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QTSQLGLOBAL_P_H
#define QTSQLGLOBAL_P_H
diff --git a/src/sql/models/models.pri b/src/sql/models/models.pri
deleted file mode 100644
index 972cf2f3f2..0000000000
--- a/src/sql/models/models.pri
+++ /dev/null
@@ -1,12 +0,0 @@
-HEADERS += models/qsqlquerymodel.h \
- models/qsqlquerymodel_p.h \
- models/qsqltablemodel.h \
- models/qsqltablemodel_p.h \
- models/qsqlrelationaldelegate.h \
- models/qsqlrelationaltablemodel.h
-
-SOURCES += models/qsqlquerymodel.cpp \
- models/qsqltablemodel.cpp \
- models/qsqlrelationaldelegate.cpp \
- models/qsqlrelationaltablemodel.cpp
-
diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp
index c0b1061c6b..6f91fb9739 100644
--- a/src/sql/models/qsqlquerymodel.cpp
+++ b/src/sql/models/qsqlquerymodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlquerymodel.h"
#include "qsqlquerymodel_p.h"
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#define QSQL_PREFETCH 255
void QSqlQueryModelPrivate::prefetch(int limit)
@@ -113,7 +79,7 @@ int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const
the lower-level QSqlQuery and can be used to provide data to
view classes such as QTableView. For example:
- \snippet sqldatabase/sqldatabase.cpp 16
+ \snippet sqldatabase/sqldatabase_snippet.cpp 16
We set the model's query, then we set up the labels displayed in
the view header.
@@ -124,8 +90,8 @@ int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const
\snippet sqldatabase/sqldatabase.cpp 21
The code snippet above extracts the \c salary field from record 4 in
- the result set of the query \c{SELECT * from employee}. Assuming
- that \c salary is column 2, we can rewrite the last line as follows:
+ the result set of the \c SELECT query. Since \c salary is the 2nd
+ column (or column index 1), we can rewrite the last line as follows:
\snippet sqldatabase/sqldatabase.cpp 22
@@ -173,8 +139,6 @@ QSqlQueryModel::~QSqlQueryModel()
}
/*!
- \since 4.1
-
Fetches more rows from a database.
This only affects databases that don't report back the size of a query
(see QSqlDriver::hasFeature()).
@@ -196,8 +160,6 @@ void QSqlQueryModel::fetchMore(const QModelIndex &parent)
}
/*!
- \since 4.1
-
Returns \c true if it is possible to read more rows from the database.
This only affects databases that don't report back the size of a query
(see QSqlDriver::hasFeature()).
@@ -329,7 +291,6 @@ void QSqlQueryModel::endResetModel()
}
/*! \fn int QSqlQueryModel::rowCount(const QModelIndex &parent) const
- \since 4.1
If the database supports returning the size of a query
(see QSqlDriver::hasFeature()), the number of rows of the current
@@ -418,6 +379,18 @@ void QSqlQueryModel::queryChange()
// do nothing
}
+#if QT_DEPRECATED_SINCE(6, 2)
+/*!
+ \deprecated [6.2] Use the \c{setQuery(QSqlQuery &&query)} overload instead.
+ \overload
+*/
+void QSqlQueryModel::setQuery(const QSqlQuery &query)
+{
+ QT_IGNORE_DEPRECATIONS(QSqlQuery copy = query;)
+ setQuery(std::move(copy));
+}
+#endif // QT_DEPRECATED_SINCE(6, 2)
+
/*!
Resets the model and sets the data provider to be the given \a
query. Note that the query must be active and must not be
@@ -428,9 +401,11 @@ void QSqlQueryModel::queryChange()
\note Calling setQuery() will remove any inserted columns.
+ \since 6.2
+
\sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError()
*/
-void QSqlQueryModel::setQuery(const QSqlQuery &query)
+void QSqlQueryModel::setQuery(QSqlQuery &&query)
{
Q_D(QSqlQueryModel);
beginResetModel();
@@ -443,25 +418,24 @@ void QSqlQueryModel::setQuery(const QSqlQuery &query)
d->bottom = QModelIndex();
d->error = QSqlError();
- d->query = query;
+ d->query = std::move(query);
d->rec = newRec;
d->atEnd = true;
- if (query.isForwardOnly()) {
- d->error = QSqlError(QLatin1String("Forward-only queries "
- "cannot be used in a data model"),
+ if (d->query.isForwardOnly()) {
+ d->error = QSqlError("Forward-only queries cannot be used in a data model"_L1,
QString(), QSqlError::ConnectionError);
endResetModel();
return;
}
- if (!query.isActive()) {
- d->error = query.lastError();
+ if (!d->query.isActive()) {
+ d->error = d->query.lastError();
endResetModel();
return;
}
- if (query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) {
+ if (d->query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) {
d->bottom = createIndex(d->query.size() - 1, d->rec.count() - 1);
} else {
d->bottom = createIndex(-1, d->rec.count() - 1);
@@ -541,11 +515,11 @@ bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation,
}
/*!
- Returns the QSqlQuery associated with this model.
+ Returns a reference to the const QSqlQuery object associated with this model.
\sa setQuery()
*/
-QSqlQuery QSqlQueryModel::query() const
+const QSqlQuery &QSqlQueryModel::query(QT6_IMPL_NEW_OVERLOAD) const
{
Q_D(const QSqlQueryModel);
return d->query;
@@ -644,7 +618,7 @@ bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex &par
d->colOffsets.append(nVal);
Q_ASSERT(d->colOffsets.size() >= d->rec.count());
}
- for (int i = column + 1; i < d->colOffsets.count(); ++i)
+ for (int i = column + 1; i < d->colOffsets.size(); ++i)
++d->colOffsets[i];
}
endInsertColumns();
@@ -673,7 +647,7 @@ bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &par
int i;
for (i = 0; i < count; ++i)
d->rec.remove(column);
- for (i = column; i < d->colOffsets.count(); ++i)
+ for (i = column; i < d->colOffsets.size(); ++i)
d->colOffsets[i] -= count;
endRemoveColumns();
@@ -702,3 +676,5 @@ QModelIndex QSqlQueryModel::indexInQuery(const QModelIndex &item) const
}
QT_END_NAMESPACE
+
+#include "moc_qsqlquerymodel.cpp"
diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h
index 427b369ae2..73308b79e8 100644
--- a/src/sql/models/qsqlquerymodel.h
+++ b/src/sql/models/qsqlquerymodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLQUERYMODEL_H
#define QSQLQUERYMODEL_H
@@ -76,9 +40,16 @@ public:
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
+#if QT_DEPRECATED_SINCE(6, 2)
+ QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Pass it by move instead.")
void setQuery(const QSqlQuery &query);
+#endif
+ void setQuery(QSqlQuery &&query);
void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
+#if QT_SQL_REMOVED_SINCE(6, 5)
QSqlQuery query() const;
+#endif
+ const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const;
virtual void clear();
diff --git a/src/sql/models/qsqlquerymodel_p.h b/src/sql/models/qsqlquerymodel_p.h
index 64e9aeb3db..a4c408d081 100644
--- a/src/sql/models/qsqlquerymodel_p.h
+++ b/src/sql/models/qsqlquerymodel_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLQUERYMODEL_P_H
#define QSQLQUERYMODEL_P_H
@@ -57,8 +21,8 @@
#include "QtSql/qsqlquery.h"
#include "QtSql/qsqlrecord.h"
#include "QtCore/qhash.h"
+#include "QtCore/qlist.h"
#include "QtCore/qvarlengtharray.h"
-#include "QtCore/qvector.h"
QT_REQUIRE_CONFIG(sqlmodel);
@@ -80,7 +44,7 @@ public:
QModelIndex bottom;
QSqlRecord rec;
uint atEnd : 1;
- QVector<QHash<int, QVariant> > headers;
+ QList<QHash<int, QVariant>> headers;
QVarLengthArray<int, 56> colOffsets; // used to calculate indexInQuery of columns
int nestedResetLevel;
};
@@ -90,22 +54,22 @@ class QSqlQueryModelSql
{
public:
// SQL keywords
- inline const static QLatin1String as() { return QLatin1String("AS"); }
- inline const static QLatin1String asc() { return QLatin1String("ASC"); }
- inline const static QLatin1String comma() { return QLatin1String(","); }
- inline const static QLatin1String desc() { return QLatin1String("DESC"); }
- inline const static QLatin1String eq() { return QLatin1String("="); }
+ inline const static QLatin1StringView as() { return QLatin1StringView("AS"); }
+ inline const static QLatin1StringView asc() { return QLatin1StringView("ASC"); }
+ inline const static QLatin1StringView comma() { return QLatin1StringView(","); }
+ inline const static QLatin1StringView desc() { return QLatin1StringView("DESC"); }
+ inline const static QLatin1StringView eq() { return QLatin1StringView("="); }
// "and" is a C++ keyword
- inline const static QLatin1String et() { return QLatin1String("AND"); }
- inline const static QLatin1String from() { return QLatin1String("FROM"); }
- inline const static QLatin1String leftJoin() { return QLatin1String("LEFT JOIN"); }
- inline const static QLatin1String on() { return QLatin1String("ON"); }
- inline const static QLatin1String orderBy() { return QLatin1String("ORDER BY"); }
- inline const static QLatin1String parenClose() { return QLatin1String(")"); }
- inline const static QLatin1String parenOpen() { return QLatin1String("("); }
- inline const static QLatin1String select() { return QLatin1String("SELECT"); }
- inline const static QLatin1String sp() { return QLatin1String(" "); }
- inline const static QLatin1String where() { return QLatin1String("WHERE"); }
+ inline const static QLatin1StringView et() { return QLatin1StringView("AND"); }
+ inline const static QLatin1StringView from() { return QLatin1StringView("FROM"); }
+ inline const static QLatin1StringView leftJoin() { return QLatin1StringView("LEFT JOIN"); }
+ inline const static QLatin1StringView on() { return QLatin1StringView("ON"); }
+ inline const static QLatin1StringView orderBy() { return QLatin1StringView("ORDER BY"); }
+ inline const static QLatin1StringView parenClose() { return QLatin1StringView(")"); }
+ inline const static QLatin1StringView parenOpen() { return QLatin1StringView("("); }
+ inline const static QLatin1StringView select() { return QLatin1StringView("SELECT"); }
+ inline const static QLatin1StringView sp() { return QLatin1StringView(" "); }
+ inline const static QLatin1StringView where() { return QLatin1StringView("WHERE"); }
// Build expressions based on key words
inline const static QString as(const QString &a, const QString &b) { return b.isEmpty() ? a : concat(concat(a, as()), b); }
diff --git a/src/sql/models/qsqlrelationaldelegate.cpp b/src/sql/models/qsqlrelationaldelegate.cpp
index f01548baf9..ee9bc668b6 100644
--- a/src/sql/models/qsqlrelationaldelegate.cpp
+++ b/src/sql/models/qsqlrelationaldelegate.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qglobal.h"
diff --git a/src/sql/models/qsqlrelationaldelegate.h b/src/sql/models/qsqlrelationaldelegate.h
index 2f16a4a54b..35c534eae4 100644
--- a/src/sql/models/qsqlrelationaldelegate.h
+++ b/src/sql/models/qsqlrelationaldelegate.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLRELATIONALDELEGATE_H
#define QSQLRELATIONALDELEGATE_H
@@ -46,7 +10,7 @@ QT_REQUIRE_CONFIG(sqlmodel);
#ifdef QT_WIDGETS_LIB
-#include <QtWidgets/qitemdelegate.h>
+#include <QtWidgets/qstyleditemdelegate.h>
#if QT_CONFIG(listview)
#include <QtWidgets/qlistview.h>
#endif
@@ -58,8 +22,7 @@ QT_REQUIRE_CONFIG(sqlmodel);
#include <QtCore/qmetaobject.h>
QT_BEGIN_NAMESPACE
-// ### Qt6: QStyledItemDelegate
-class QSqlRelationalDelegate: public QItemDelegate
+class QSqlRelationalDelegate : public QStyledItemDelegate
{
static int fieldIndex(const QSqlTableModel *const model,
const QSqlDriver *const driver,
@@ -73,31 +36,31 @@ class QSqlRelationalDelegate: public QItemDelegate
public:
-explicit QSqlRelationalDelegate(QObject *aParent = nullptr)
- : QItemDelegate(aParent)
-{}
+ explicit QSqlRelationalDelegate(QObject *aParent = nullptr)
+ : QStyledItemDelegate(aParent)
+ {}
-~QSqlRelationalDelegate()
-{}
+ ~QSqlRelationalDelegate()
+ {}
-QWidget *createEditor(QWidget *aParent,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const override
-{
- const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
- QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : nullptr;
- if (!childModel)
- return QItemDelegate::createEditor(aParent, option, index);
- const QSqlDriver *const driver = childModel->database().driver();
-
- QComboBox *combo = new QComboBox(aParent);
- combo->setModel(childModel);
- combo->setModelColumn(fieldIndex(childModel, driver,
- sqlModel->relation(index.column()).displayColumn()));
- combo->installEventFilter(const_cast<QSqlRelationalDelegate *>(this));
-
- return combo;
-}
+ QWidget *createEditor(QWidget *aParent,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
+ {
+ const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
+ QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : nullptr;
+ if (!childModel)
+ return QStyledItemDelegate::createEditor(aParent, option, index);
+ const QSqlDriver *const driver = childModel->database().driver();
+
+ QComboBox *combo = new QComboBox(aParent);
+ combo->setModel(childModel);
+ combo->setModelColumn(fieldIndex(childModel, driver,
+ sqlModel->relation(index.column()).displayColumn()));
+ combo->installEventFilter(const_cast<QSqlRelationalDelegate *>(this));
+
+ return combo;
+ }
void setEditorData(QWidget *editor, const QModelIndex &index) const override
{
@@ -112,12 +75,12 @@ QWidget *createEditor(QWidget *aParent,
const QByteArray n = editor->metaObject()->userProperty().name();
if (!n.isEmpty()) {
if (!v.isValid())
- v = QVariant(editor->property(n.data()).userType(), nullptr);
+ v = QVariant(editor->property(n.data()).metaType());
editor->setProperty(n.data(), v);
return;
}
}
- QItemDelegate::setEditorData(editor, index);
+ QStyledItemDelegate::setEditorData(editor, index);
}
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
@@ -129,7 +92,7 @@ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : nullptr;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
- QItemDelegate::setModelData(editor, model, index);
+ QStyledItemDelegate::setModelData(editor, model, index);
return;
}
const QSqlDriver *const driver = childModel->database().driver();
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index 4f5f00bf96..c086d88ffe 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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 "qsqlrelationaltablemodel.h"
@@ -55,13 +19,15 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
class QSqlRelationalTableModelSql: public QSqlTableModelSql
{
public:
- inline const static QString relTablePrefix(int i) { return QString::number(i).prepend(QLatin1String("relTblAl_")); }
+ inline const static QString relTablePrefix(int i) { return QString::number(i).prepend("relTblAl_"_L1); }
};
-typedef QSqlRelationalTableModelSql Sql;
+using SqlrTm = QSqlRelationalTableModelSql;
/*!
\class QSqlRelation
@@ -275,7 +241,7 @@ public:
QString fullyQualifiedFieldName(const QString &tableName, const QString &fieldName) const;
int nameToIndex(const QString &name) const override;
- mutable QVector<QRelation> relations;
+ mutable QList<QRelation> relations;
QSqlRecord baseRec; // the record without relations
void clearChanges();
void clearCache() override;
@@ -287,7 +253,7 @@ public:
void QSqlRelationalTableModelPrivate::clearChanges()
{
- for (int i = 0; i < relations.count(); ++i) {
+ for (int i = 0; i < relations.size(); ++i) {
QRelation &rel = relations[i];
rel.clear();
}
@@ -311,7 +277,7 @@ int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const
void QSqlRelationalTableModelPrivate::clearCache()
{
- for (int i = 0; i < relations.count(); ++i)
+ for (int i = 0; i < relations.size(); ++i)
relations[i].clearDictionary();
QSqlTableModelPrivate::clearCache();
@@ -429,7 +395,7 @@ QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) cons
{
Q_D(const QSqlRelationalTableModel);
- if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.count() &&
+ if (role == Qt::DisplayRole && index.column() >= 0 && index.column() < d->relations.size() &&
d->relations.value(index.column()).isValid()) {
QRelation &relation = d->relations[index.column()];
if (!relation.isDictionaryInitialized())
@@ -472,7 +438,7 @@ bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant
int role)
{
Q_D(QSqlRelationalTableModel);
- if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.count()
+ if ( role == Qt::EditRole && index.column() > 0 && index.column() < d->relations.size()
&& d->relations.value(index.column()).isValid()) {
QRelation &relation = d->relations[index.column()];
if (!relation.isDictionaryInitialized())
@@ -528,7 +494,7 @@ QString QSqlRelationalTableModelPrivate::fullyQualifiedFieldName(const QString &
{
QString ret;
ret.reserve(tableName.size() + fieldName.size() + 1);
- ret.append(tableName).append(QLatin1Char('.')).append(fieldName);
+ ret.append(tableName).append(u'.').append(fieldName);
return ret;
}
@@ -574,12 +540,12 @@ QString QSqlRelationalTableModel::selectStatement() const
QString fList;
QString conditions;
- QString from = Sql::from(tableName());
+ QString from = SqlrTm::from(tableName());
for (int i = 0; i < d->baseRec.count(); ++i) {
QSqlRelation relation = d->relations.value(i).rel;
const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName));
if (relation.isValid()) {
- const QString relTableAlias = Sql::relTablePrefix(i);
+ const QString relTableAlias = SqlrTm::relTablePrefix(i);
QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn());
// Duplicate field names must be aliased
@@ -590,38 +556,40 @@ QString QSqlRelationalTableModel::selectStatement() const
QString displayColumn = relation.displayColumn();
if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName))
displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);
- const QString alias = QString::fromLatin1("%1_%2_%3")
+ QString alias = QString::fromLatin1("%1_%2_%3")
.arg(relTableName, displayColumn, QString::number(fieldNames.value(fieldList[i])));
- displayTableField = Sql::as(displayTableField, alias);
+ alias.truncate(d->db.driver()->maximumIdentifierLength(QSqlDriver::FieldName));
+ alias = d->db.driver()->escapeIdentifier(alias, QSqlDriver::FieldName);
+ displayTableField = SqlrTm::as(displayTableField, alias);
--fieldNames[fieldList[i]];
}
- fList = Sql::comma(fList, displayTableField);
+ fList = SqlrTm::comma(fList, displayTableField);
// Join related table
- const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias);
+ const QString tblexpr = SqlrTm::concat(relation.tableName(), relTableAlias);
const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn());
- const QString cond = Sql::eq(tableField, relTableField);
+ const QString cond = SqlrTm::eq(tableField, relTableField);
if (d->joinMode == QSqlRelationalTableModel::InnerJoin) {
// FIXME: InnerJoin code is known to be broken.
// Use LeftJoin mode if you want correct behavior.
- from = Sql::comma(from, tblexpr);
- conditions = Sql::et(conditions, cond);
+ from = SqlrTm::comma(from, tblexpr);
+ conditions = SqlrTm::et(conditions, cond);
} else {
- from = Sql::concat(from, Sql::leftJoin(tblexpr));
- from = Sql::concat(from, Sql::on(cond));
+ from = SqlrTm::concat(from, SqlrTm::leftJoin(tblexpr));
+ from = SqlrTm::concat(from, SqlrTm::on(cond));
}
} else {
- fList = Sql::comma(fList, tableField);
+ fList = SqlrTm::comma(fList, tableField);
}
}
if (fList.isEmpty())
return QString();
- const QString stmt = Sql::concat(Sql::select(fList), from);
- const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter())));
- return Sql::concat(Sql::concat(stmt, where), orderByClause());
+ const QString stmt = SqlrTm::concat(SqlrTm::select(fList), from);
+ const QString where = SqlrTm::where(SqlrTm::et(SqlrTm::paren(conditions), SqlrTm::paren(filter())));
+ return SqlrTm::concat(SqlrTm::concat(stmt, where), orderByClause());
}
/*!
@@ -636,7 +604,7 @@ QString QSqlRelationalTableModel::selectStatement() const
QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const
{
Q_D(const QSqlRelationalTableModel);
- if (column < 0 || column >= d->relations.count())
+ if (column < 0 || column >= d->relations.size())
return nullptr;
QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column];
@@ -676,7 +644,6 @@ void QSqlRelationalTableModel::clear()
\value LeftJoin - Left join mode, returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).
\sa QSqlRelationalTableModel::setJoinMode()
- \since 4.8
*/
/*!
@@ -685,7 +652,6 @@ void QSqlRelationalTableModel::clear()
LeftJoin mode if you want to show them.
\sa QSqlRelationalTableModel::JoinMode
- \since 4.8
*/
void QSqlRelationalTableModel::setJoinMode( QSqlRelationalTableModel::JoinMode joinMode )
{
@@ -765,9 +731,9 @@ QString QSqlRelationalTableModel::orderByClause() const
if (!rel.isValid())
return QSqlTableModel::orderByClause();
- QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn());
- f = d->sortOrder == Qt::AscendingOrder ? Sql::asc(f) : Sql::desc(f);
- return Sql::orderBy(f);
+ QString f = d->fullyQualifiedFieldName(SqlrTm::relTablePrefix(d->sortColumn), rel.displayColumn());
+ f = d->sortOrder == Qt::AscendingOrder ? SqlrTm::asc(f) : SqlrTm::desc(f);
+ return SqlrTm::orderBy(f);
}
/*!
@@ -782,10 +748,12 @@ bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModel
for (int i = 0; i < count; ++i) {
d->baseRec.remove(column);
- if (d->relations.count() > column)
+ if (d->relations.size() > column)
d->relations.remove(column);
}
return QSqlTableModel::removeColumns(column, count, parent);
}
QT_END_NAMESPACE
+
+#include "moc_qsqlrelationaltablemodel.cpp"
diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h
index 2ebadaabd1..814bae41bb 100644
--- a/src/sql/models/qsqlrelationaltablemodel.h
+++ b/src/sql/models/qsqlrelationaltablemodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLRELATIONALTABLEMODEL_H
#define QSQLRELATIONALTABLEMODEL_H
@@ -60,9 +24,9 @@ public:
void swap(QSqlRelation &other) noexcept
{
- qSwap(tName, other.tName);
- qSwap(iColumn, other.iColumn);
- qSwap(dColumn, other.dColumn);
+ tName.swap(other.tName);
+ iColumn.swap(other.iColumn);
+ dColumn.swap(other.dColumn);
}
inline QString tableName() const
@@ -76,7 +40,7 @@ public:
private:
QString tName, iColumn, dColumn;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QSqlRelation)
+Q_DECLARE_SHARED(QSqlRelation)
class QSqlRelationalTableModelPrivate;
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 4d20915c09..265d7782a0 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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 "qsqltablemodel.h"
@@ -53,7 +17,9 @@
QT_BEGIN_NAMESPACE
-typedef QSqlTableModelSql Sql;
+using namespace Qt::StringLiterals;
+
+using SqlTm = QSqlTableModelSql;
QSqlTableModelPrivate::~QSqlTableModelPrivate()
{
@@ -63,10 +29,10 @@ QSqlTableModelPrivate::~QSqlTableModelPrivate()
/*! \internal
Populates our record with values.
*/
-QSqlRecord QSqlTableModelPrivate::record(const QVector<QVariant> &values) const
+QSqlRecord QSqlTableModelPrivate::record(const QList<QVariant> &values) const
{
QSqlRecord r = rec;
- for (int i = 0; i < r.count() && i < values.count(); ++i)
+ for (int i = 0; i < r.count() && i < values.size(); ++i)
r.setValue(i, values.at(i));
return r;
}
@@ -211,7 +177,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
lower-level QSqlQuery and can be used to provide data to view
classes such as QTableView. For example:
- \snippet sqldatabase/sqldatabase.cpp 24
+ \snippet sqldatabase/sqldatabase_snippet.cpp 24
We set the SQL table's name and the edit strategy, then we set up
the labels displayed in the view header. The edit strategy
@@ -222,7 +188,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
QSqlTableModel can also be used to access a database
programmatically, without binding it to a view:
- \snippet sqldatabase/sqldatabase.cpp 21
+ \snippet sqldatabase/sqldatabase.cpp 25
The code snippet above extracts the \c salary field from record 4 in
the result set of the query \c{SELECT * from employee}.
@@ -239,7 +205,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
want to resolve foreign keys.
\sa QSqlRelationalTableModel, QSqlQuery, {Model/View Programming},
- {Table Model Example}, {Cached Table Example}
+ {Table Model Example}, {Cached SQL Table}
*/
/*!
@@ -333,7 +299,7 @@ void QSqlTableModel::setTable(const QString &tableName)
d->initRecordAndPrimaryIndex();
if (d->rec.count() == 0)
- d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(),
+ d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(),
QSqlError::StatementError);
// Remember the auto index column if there is one now.
@@ -376,10 +342,9 @@ bool QSqlTableModel::select()
d->clearCache();
- QSqlQuery qu(query, d->db);
- setQuery(qu);
+ this->QSqlQueryModel::setQuery(query, d->db);
- if (!qu.isActive() || lastError().isValid()) {
+ if (!d->query.isActive() || lastError().isValid()) {
// something went wrong - revert to non-select state
d->initRecordAndPrimaryIndex();
endResetModel();
@@ -414,9 +379,9 @@ bool QSqlTableModel::selectRow(int row)
d->tableName,
primaryValues(row),
false);
- static const QString wh = Sql::where() + Sql::sp();
+ static const QString wh = SqlTm::where() + SqlTm::sp();
if (d->filter.startsWith(wh, Qt::CaseInsensitive))
- d->filter.remove(0, wh.length());
+ d->filter.remove(0, wh.size());
QString stmt;
@@ -493,9 +458,9 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in
if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
const QSqlTableModelPrivate::Op op = d->cache.value(section).op();
if (op == QSqlTableModelPrivate::Insert)
- return QLatin1String("*");
+ return "*"_L1;
else if (op == QSqlTableModelPrivate::Delete)
- return QLatin1String("!");
+ return "!"_L1;
}
return QSqlQueryModel::headerData(section, orientation, role);
}
@@ -607,7 +572,6 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
return true;
}
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
/*!
\reimp
*/
@@ -615,19 +579,6 @@ bool QSqlTableModel::clearItemData(const QModelIndex &index)
{
return setData(index, QVariant(), Qt::EditRole);
}
-#endif
-
-/*!
- This function simply calls QSqlQueryModel::setQuery(\a query).
- You should normally not call it on a QSqlTableModel. Instead, use
- setTable(), setSort(), setFilter(), etc., to set up the query.
-
- \sa selectStatement()
-*/
-void QSqlTableModel::setQuery(const QSqlQuery &query)
-{
- QSqlQueryModel::setQuery(query);
-}
/*!
Updates the given \a row in the currently active database table
@@ -659,12 +610,11 @@ bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values)
whereValues, prepStatement);
if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) {
- d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError);
return false;
}
- return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);
+ return d->exec(SqlTm::concat(stmt, where), prepStatement, rec, whereValues);
}
@@ -692,8 +642,7 @@ bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values)
rec, prepStatement);
if (stmt.isEmpty()) {
- d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError);
return false;
}
@@ -729,12 +678,11 @@ bool QSqlTableModel::deleteRowFromTable(int row)
prepStatement);
if (stmt.isEmpty() || where.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to delete row"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("Unable to delete row"_L1, QString(), QSqlError::StatementError);
return false;
}
- return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues);
+ return d->exec(SqlTm::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues);
}
/*!
@@ -1003,10 +951,11 @@ QString QSqlTableModel::orderByClause() const
//we can safely escape the field because it would have been obtained from the database
//and have the correct case
- QString field = d->tableName + QLatin1Char('.')
+ QString field = d->db.driver()->escapeIdentifier(d->tableName, QSqlDriver::TableName)
+ + u'.'
+ d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName);
- field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field);
- return Sql::orderBy(field);
+ field = d->sortOrder == Qt::AscendingOrder ? SqlTm::asc(field) : SqlTm::desc(field);
+ return SqlTm::orderBy(field);
}
/*!
@@ -1030,12 +979,11 @@ QString QSqlTableModel::selectStatement() const
{
Q_D(const QSqlTableModel);
if (d->tableName.isEmpty()) {
- d->error = QSqlError(QLatin1String("No table name given"), QString(),
- QSqlError::StatementError);
+ d->error = QSqlError("No table name given"_L1, QString(), QSqlError::StatementError);
return QString();
}
if (d->rec.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(),
+ d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(),
QSqlError::StatementError);
return QString();
}
@@ -1045,11 +993,11 @@ QString QSqlTableModel::selectStatement() const
d->rec,
false);
if (stmt.isEmpty()) {
- d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName,
+ d->error = QSqlError("Unable to select fields from table "_L1 + d->tableName,
QString(), QSqlError::StatementError);
return stmt;
}
- return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());
+ return SqlTm::concat(SqlTm::concat(stmt, SqlTm::where(d->filter)), orderByClause());
}
/*!
@@ -1105,12 +1053,8 @@ bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &par
bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_D(QSqlTableModel);
- if (parent.isValid() || row < 0 || count <= 0)
+ if (parent.isValid() || row < 0 || count <= 0 || row + count > rowCount())
return false;
- else if (row + count > rowCount())
- return false;
- else if (!count)
- return true;
if (d->strategy != OnManualSubmit)
if (count > 1 || (d->cache.value(row).submitted() && isDirty()))
@@ -1471,3 +1415,5 @@ QSqlRecord QSqlTableModel::primaryValues(int row) const
}
QT_END_NAMESPACE
+
+#include "moc_qsqltablemodel.cpp"
diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h
index 1ac8bd9b04..8af3f84c59 100644
--- a/src/sql/models/qsqltablemodel.h
+++ b/src/sql/models/qsqltablemodel.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLTABLEMODEL_H
#define QSQLTABLEMODEL_H
@@ -58,6 +22,7 @@ class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel
{
Q_OBJECT
Q_DECLARE_PRIVATE(QSqlTableModel)
+ Q_MOC_INCLUDE(<QtSql/qsqlrecord.h>)
public:
enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit};
@@ -74,9 +39,7 @@ public:
QSqlRecord record(int row) const;
QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool clearItemData(const QModelIndex &index) override;
-#endif
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
@@ -136,7 +99,9 @@ protected:
virtual QString selectStatement() const;
void setPrimaryKey(const QSqlIndex &key);
+#if QT_SQL_REMOVED_SINCE(6, 5)
void setQuery(const QSqlQuery &query);
+#endif
QModelIndex indexInQuery(const QModelIndex &item) const override;
QSqlRecord primaryValues(int row) const;
};
diff --git a/src/sql/models/qsqltablemodel_p.h b/src/sql/models/qsqltablemodel_p.h
index 9ac34e7259..9c6425ded4 100644
--- a/src/sql/models/qsqltablemodel_p.h
+++ b/src/sql/models/qsqltablemodel_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 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
#ifndef QSQLTABLEMODEL_P_H
#define QSQLTABLEMODEL_P_H
@@ -75,7 +39,7 @@ public:
void clear();
virtual void clearCache();
- QSqlRecord record(const QVector<QVariant> &values) const;
+ QSqlRecord record(const QList<QVariant> &values) const;
bool exec(const QString &stmt, bool prepStatement,
const QSqlRecord &rec, const QSqlRecord &whereValues);
diff --git a/src/sql/qt_cmdline.cmake b/src/sql/qt_cmdline.cmake
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/src/sql/qt_cmdline.cmake
diff --git a/src/sql/sql.pro b/src/sql/sql.pro
deleted file mode 100644
index 1cd2a05250..0000000000
--- a/src/sql/sql.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-TARGET = QtSql
-QT = core-private
-
-DEFINES += QT_NO_USING_NAMESPACE
-msvc:equals(QT_ARCH, i386): QMAKE_LFLAGS += /BASE:0x62000000
-
-QMAKE_DOCS = $$PWD/doc/qtsql.qdocconf
-
-DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_FOREACH
-PRECOMPILED_HEADER = ../corelib/global/qt_pch.h
-SQL_P = sql
-
-include(kernel/kernel.pri)
-qtConfig(sqlmodel): include(models/models.pri)
-
-MODULE_PLUGIN_TYPES = \
- sqldrivers
-load(qt_module)