Qt 4.8
qsqlquery.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSQLQUERY_H
43 #define QSQLQUERY_H
44 
45 #include <QtSql/qsql.h>
46 #include <QtSql/qsqldatabase.h>
47 #include <QtCore/qstring.h>
48 
50 
52 
53 QT_MODULE(Sql)
54 
55 class QVariant;
56 class QSqlDriver;
57 class QSqlError;
58 class QSqlResult;
59 class QSqlRecord;
60 template <class Key, class T> class QMap;
61 class QSqlQueryPrivate;
62 
64 {
65 public:
67  QSqlQuery(const QString& query = QString(), QSqlDatabase db = QSqlDatabase());
68  explicit QSqlQuery(QSqlDatabase db);
69  QSqlQuery(const QSqlQuery& other);
70  QSqlQuery& operator=(const QSqlQuery& other);
71  ~QSqlQuery();
72 
73  bool isValid() const;
74  bool isActive() const;
75  bool isNull(int field) const;
76  int at() const;
77  QString lastQuery() const;
78  int numRowsAffected() const;
79  QSqlError lastError() const;
80  bool isSelect() const;
81  int size() const;
82  const QSqlDriver* driver() const;
83  const QSqlResult* result() const;
84  bool isForwardOnly() const;
85  QSqlRecord record() const;
86 
87  void setForwardOnly(bool forward);
88  bool exec(const QString& query);
89  QVariant value(int i) const;
90 
91  void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
92  QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
93 
94  bool seek(int i, bool relative = false);
95  bool next();
96  bool previous();
97 #ifdef QT3_SUPPORT
98  inline QT3_SUPPORT bool prev() { return previous(); }
99 #endif
100  bool first();
101  bool last();
102 
103  void clear();
104 
105  // prepared query support
106  bool exec();
107  enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns };
108  bool execBatch(BatchExecutionMode mode = ValuesAsRows);
109  bool prepare(const QString& query);
110  void bindValue(const QString& placeholder, const QVariant& val,
111  QSql::ParamType type = QSql::In);
112  void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In);
113  void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In);
114  QVariant boundValue(const QString& placeholder) const;
115  QVariant boundValue(int pos) const;
116  QMap<QString, QVariant> boundValues() const;
117  QString executedQuery() const;
118  QVariant lastInsertId() const;
119  void finish();
120  bool nextResult();
121 
122 private:
124 };
125 
127 
129 
130 #endif // QSQLQUERY_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
NumericalPrecisionPolicy
Definition: qsql.h:82
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define at(className, varName)
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QSqlDatabase class represents a connection to a database.
Definition: qsqldatabase.h:78
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
Definition: qsqldriver.h:68
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_SQL_EXPORT
Definition: qglobal.h:1451
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Definition: qsql.h:67
QSqlQueryPrivate * d
Definition: qsqlquery.h:123
BatchExecutionMode
Definition: qsqlquery.h:107
#define QT_END_HEADER
Definition: qglobal.h:137
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
Definition: qsqlresult.h:63
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300