summaryrefslogtreecommitdiffstats
path: root/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-09-23 14:25:44 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-10-03 10:48:50 +0000
commit5f9a0d64b324abb8bf9baffabd7accb61a83a7e7 (patch)
treeff9c507ebd25b12ef0e9d35339a4731bccb3a8c8 /src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
parent91d43a48f7307938624d4ab11e488494456646f5 (diff)
QtSql: fix code snippets
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 <aha_1980@gmx.de> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
Diffstat (limited to 'src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp')
-rw-r--r--src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp12
1 files changed, 6 insertions, 6 deletions
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<sqlite3 **>(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<PGconn **>(v.data());
- if (handle != 0) ...
+ if (handle) ...
}
-if (qstrcmp(v.typeName(), "MYSQL*")) {
+if (qstrcmp(v.typeName(), "MYSQL*") == 0) {
MYSQL *handle = *static_cast<MYSQL **>(v.data());
- if (handle != 0) ...
+ if (handle) ...
}
//! [1]