Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_sql_kernel_qsqlresult.cpp
Go to the documentation of this file.
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 <QSqlError>
7#include <QSqlResult>
8#include <QDebug>
9
10// dummy typedef
11typedef void *sqlite3_stmt;
12
14{
17q.prepare("insert into test (i1, i2, s) values (?, ?, ?)");
18
19QVariantList col1;
20QVariantList col2;
21QVariantList col3;
22
23col1 << 1 << 3;
24col2 << 2 << 4;
25col3 << "hello" << "world";
26
27q.bindValue(0, col1);
28q.bindValue(1, col2);
29q.bindValue(2, col3);
30
31if (!q.execBatch())
32 qDebug() << q.lastError();
34}
35
37{
40QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
41
42QVariant v = query.result()->handle();
43if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*") == 0) {
44 // v.data() returns a pointer to the handle
45 sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
46 if (handle) {
47 // ...
48 }
49}
51}
The QSqlDatabase class handles a connection to a database.
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:24
bool prepare(const QString &query)
Prepares the SQL query query for execution.
\inmodule QtCore
Definition qvariant.h:65
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define qDebug
[1]
Definition qlogging.h:164
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLenum query
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
QMimeDatabase db
[0]
void querySqlite()
void insertVariants()
void * sqlite3_stmt