diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-04-07 01:00:12 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-04-08 20:11:39 +0200 |
commit | 8823bb8d306d78dd6a2e121a708dc607beff58c8 (patch) | |
tree | 5ca170aa36aa1381b0f31dae6709fd2ce68be344 /src/sql/doc/snippets/code | |
parent | 5422fb79486a1818d6355d75f019fe63120a43d0 (diff) | |
parent | 14c55e29794b4f1d6e010fdf7082ef55cbf8f275 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
examples/opengl/doc/src/cube.qdoc
src/corelib/global/qlibraryinfo.cpp
src/corelib/text/qbytearray_p.h
src/corelib/text/qlocale_data_p.h
src/corelib/time/qhijricalendar_data_p.h
src/corelib/time/qjalalicalendar_data_p.h
src/corelib/time/qromancalendar_data_p.h
src/network/ssl/qsslcertificate.h
src/widgets/doc/src/graphicsview.qdoc
src/widgets/widgets/qcombobox.cpp
src/widgets/widgets/qcombobox.h
tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp
tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro
tests/manual/diaglib/debugproxystyle.cpp
tests/manual/diaglib/qwidgetdump.cpp
tests/manual/diaglib/qwindowdump.cpp
tests/manual/diaglib/textdump.cpp
util/locale_database/cldr2qlocalexml.py
util/locale_database/qlocalexml.py
util/locale_database/qlocalexml2cpp.py
Resolution of util/locale_database/ are based on:
https://codereview.qt-project.org/c/qt/qtbase/+/294250
and src/corelib/{text,time}/*_data_p.h were then regenerated by
running those scripts.
Updated CMakeLists.txt in each of
tests/auto/corelib/serialization/qcborstreamreader/
tests/auto/corelib/serialization/qcborvalue/
tests/auto/gui/kernel/
and generated new ones in each of
tests/auto/gui/kernel/qaddpostroutine/
tests/auto/gui/kernel/qhighdpiscaling/
tests/libfuzzer/corelib/text/qregularexpression/optimize/
tests/libfuzzer/gui/painting/qcolorspace/fromiccprofile/
tests/libfuzzer/gui/text/qtextdocument/sethtml/
tests/libfuzzer/gui/text/qtextdocument/setmarkdown/
tests/libfuzzer/gui/text/qtextlayout/beginlayout/
by running util/cmake/pro2cmake.py on their changed .pro files.
Changed target name in
tests/auto/gui/kernel/qaction/qaction.pro
tests/auto/gui/kernel/qaction/qactiongroup.pro
tests/auto/gui/kernel/qshortcut/qshortcut.pro
to ensure unique target names for CMake
Changed tst_QComboBox::currentIndex to not test the
currentIndexChanged(QString), as that one does not exist in Qt 6
anymore.
Change-Id: I9a85705484855ae1dc874a81f49d27a50b0dcff7
Diffstat (limited to 'src/sql/doc/snippets/code')
11 files changed, 391 insertions, 111 deletions
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 3757ba2eff..acfd31ee3a 100644 --- a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp +++ b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp @@ -47,25 +47,38 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - +#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] @@ -74,61 +87,57 @@ db.setDatabaseName("C:\\test.gdb"); //! [25] // connect to database using the Latin-1 character set db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1"); -db.open(); +if (db.open()) + qDebug("The database connection is 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( \ //! [31] -QSqlDatabase: QMYSQL driver not loaded -QSqlDatabase: available drivers: QMYSQL +"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] +} +void setConnString() +{ //! [39] QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString connectString = QStringLiteral( @@ -139,3 +148,4 @@ QString connectString = QStringLiteral( "SCROLLABLERESULT=true"); db.setDatabaseName(connectString); //! [39] +} 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..7cffe58ff1 --- /dev/null +++ b/src/sql/doc/snippets/code/doc_src_sql-driver_snippet.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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$ +** +****************************************************************************/ +//! [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..c7ceb847da 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase.cpp @@ -47,18 +47,25 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#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 +74,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 +129,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..a53880fee1 --- /dev/null +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldatabase_snippet.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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$ +** +****************************************************************************/ + +//! [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..47e8701149 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp @@ -47,28 +47,42 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#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..d442768fe2 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlerror.cpp @@ -47,10 +47,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#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..496c971621 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp @@ -47,12 +47,13 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QSqlDatabase> +#include <QSqlQuery> +#include <QSqlDriver> +#include <QDebug> -//! [0] -SELECT forename, surname FROM people; -//! [0] - - +void selectEmployees() +{ //! [1] QSqlQuery q("select * from employees"); QSqlRecord rec = q.record(); @@ -63,8 +64,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 (?, ?)"); @@ -80,11 +79,4 @@ 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..d7d2a14d56 --- /dev/null +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery_snippet.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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] +//! [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..606b6d19fa 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp @@ -47,7 +47,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#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 +78,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..2b1891f6c1 --- /dev/null +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult_snippet.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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$ +** +****************************************************************************/ + +//! [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..cb2bde6c7d 100644 --- a/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp +++ b/src/sql/doc/snippets/code/src_sql_models_qsqlquerymodel.cpp @@ -47,16 +47,24 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#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] +} |