Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
src_sql_kernel_qsqlquery.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
<
QDebug
>
7
8
void
selectEmployees
()
9
{
10
//! [1]
11
QSqlQuery q(
"select * from employees"
);
12
QSqlRecord rec = q.record();
13
14
qDebug() <<
"Number of columns: "
<< rec.count();
15
16
int
nameCol = rec.indexOf(
"name"
);
// index of the field "name"
17
while
(q.next())
18
qDebug() << q.value(nameCol).toString();
// output all names
19
//! [1]
20
//! [2]
21
QSqlQuery q;
22
q.prepare(
"insert into myTable values (?, ?)"
);
23
24
QVariantList ints;
25
ints << 1 << 2 << 3 << 4;
26
q.addBindValue(ints);
27
28
QVariantList names;
29
names <<
"Harald"
<<
"Boris"
<<
"Trond"
<< QVariant(QMetaType::fromType<QString>());
30
q.addBindValue(names);
31
32
if
(!q.execBatch())
33
qDebug() << q.lastError();
34
//! [2]
35
}
selectEmployees
void selectEmployees()
Definition
src_sql_kernel_qsqlquery.cpp:8
qtbase
src
sql
doc
snippets
code
src_sql_kernel_qsqlquery.cpp
Generated on
for Qt by
1.18.0