From 5f9a0d64b324abb8bf9baffabd7accb61a83a7e7 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 23 Sep 2018 14:25:44 +0200 Subject: QtSql: fix code snippets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code snippets retrieving the native database driver handles was using qstrcmp() wrong since that is returning 0 when the strings are equal. In some snippets there was even a plain char * comparison which would not work at all. Fix all the places by correctly using qstrcmp() and replace the checks for the valid pointer by not checking for 0. Fixes: QTBUG-70598 Change-Id: I5c53dcfc51c958203fc60fa6a23dd6b27faa1d96 Reviewed-by: André Hartmann Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar --- src/sql/doc/snippets/code/doc_src_sql-driver.cpp | 2 +- src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp | 12 ++++++------ src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/sql') 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 2c0e824db3..54576733bf 100644 --- a/src/sql/doc/snippets/code/doc_src_sql-driver.cpp +++ b/src/sql/doc/snippets/code/doc_src_sql-driver.cpp @@ -106,7 +106,7 @@ while (query.next()) { QVariant v = query.result()->handle(); if (qstrcmp(v.typeName(), "PGresult*") == 0) { PGresult *handle = *static_cast(v.data()); - if (handle != 0) { + if (handle) { // Do something... } } 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 ffae690769..a13cf86d3f 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp @@ -51,10 +51,10 @@ //! [0] QSqlDatabase db = ...; 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(v.data()); - if (handle != 0) { // check that it is not NULL + if (handle) { ... } } @@ -62,13 +62,13 @@ if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")==0) { //! [1] -if (qstrcmp(v.typeName(), "PGconn*")) { +if (qstrcmp(v.typeName(), "PGconn*") == 0) { PGconn *handle = *static_cast(v.data()); - if (handle != 0) ... + if (handle) ... } -if (qstrcmp(v.typeName(), "MYSQL*")) { +if (qstrcmp(v.typeName(), "MYSQL*") == 0) { MYSQL *handle = *static_cast(v.data()); - if (handle != 0) ... + if (handle) ... } //! [1] 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 3424a9140e..8ab2baf2a1 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlresult.cpp @@ -72,10 +72,10 @@ if (!q.execBatch()) //! [1] QSqlQuery query = ... QVariant v = query.result()->handle(); -if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*")) { +if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*") == 0) { // v.data() returns a pointer to the handle sqlite3_stmt *handle = *static_cast(v.data()); - if (handle != 0) { // check that it is not NULL + if (handle) { ... } } @@ -83,13 +83,13 @@ if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*")) { //! [2] -if (v.typeName() == "PGresult*") { +if (qstrcmp(v.typeName(), "PGresult*") == 0) { PGresult *handle = *static_cast(v.data()); - if (handle != 0) ... + if (handle) ... } -if (v.typeName() == "MYSQL_STMT*") { +if (qstrcmp(v.typeName(), "MYSQL_STMT*") == 0) { MYSQL_STMT *handle = *static_cast(v.data()); - if (handle != 0) ... + if (handle) ... } //! [2] -- cgit v1.2.3