1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
3 | #include <QSqlDatabase> |
4 | #include <QSqlQuery> |
5 | #include <QSqlDriver> |
6 | #include <QVariant> |
7 | |
8 | void checkHandle() |
9 | { |
10 | //dummy definitions |
11 | typedef void sqlite3; |
12 | typedef void PGconn; |
13 | typedef void MYSQL; |
14 | //! [0] |
15 | QSqlDatabase db = QSqlDatabase::database(); |
16 | QVariant v = db.driver()->handle(); |
17 | if (v.isValid() && (qstrcmp(str1: v.typeName(), str2: "sqlite3*" ) == 0)) { |
18 | // v.data() returns a pointer to the handle |
19 | sqlite3 *handle = *static_cast<sqlite3 **>(v.data()); |
20 | if (handle) { |
21 | // ... |
22 | } |
23 | } |
24 | //! [0] |
25 | |
26 | //! [1] |
27 | if (qstrcmp(str1: v.typeName(), str2: "PGconn*" ) == 0) { |
28 | PGconn *handle = *static_cast<PGconn **>(v.data()); |
29 | if (handle) { |
30 | // ... |
31 | } |
32 | } |
33 | |
34 | if (qstrcmp(str1: v.typeName(), str2: "MYSQL*" ) == 0) { |
35 | MYSQL *handle = *static_cast<MYSQL **>(v.data()); |
36 | if (handle) { |
37 | // ... |
38 | } |
39 | } |
40 | //! [1] |
41 | } |
42 | |