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_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
9{
11QSqlQuery q("select * from employees");
12QSqlRecord rec = q.record();
13
14qDebug() << "Number of columns: " << rec.count();
15
16int nameCol = rec.indexOf("name"); // index of the field "name"
17while (q.next())
18 qDebug() << q.value(nameCol).toString(); // output all names
22q.prepare("insert into myTable values (?, ?)");
23
25ints << 1 << 2 << 3 << 4;
26q.addBindValue(ints);
27
29names << "Harald" << "Boris" << "Trond" << QVariant(QMetaType::fromType<QString>());
30q.addBindValue(names);
31
32if (!q.execBatch())
33 qDebug() << q.lastError();
35}
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.
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
int count() const
Returns the number of fields in the record.
int indexOf(const QString &name) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore
Definition qvariant.h:65
EGLint EGLint EGLint EGLint int int * ints
#define qDebug
[1]
Definition qlogging.h:164
GLuint GLuint * names
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
void selectEmployees()