summaryrefslogtreecommitdiffstats
path: root/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp
blob: 3d955cbac9f3d48fcddc6b54604fed90dc9b4828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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::database();
QVariant v = db.driver()->handle();
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 (qstrcmp(v.typeName(), "MYSQL*") == 0) {
    MYSQL *handle = *static_cast<MYSQL **>(v.data());
    if (handle) {
        // ...
    }
}
//! [1]
}