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
49QT_BEGIN_HEADER
50
51QT_BEGIN_NAMESPACE
52
53QT_MODULE(Sql)
54
55class QVariant;
56class QSqlDriver;
57class QSqlError;
58class QSqlResult;
59class QSqlRecord;
60template <class Key, class T> class QMap;
61class QSqlQueryPrivate;
62
63class Q_SQL_EXPORT QSqlQuery
64{
65public:
66 QSqlQuery(QSqlResult *r);
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
122private:
123 QSqlQueryPrivate* d;
124};
125
126QT_END_NAMESPACE
127
128QT_END_HEADER
129
130#endif // QSQLQUERY_H
131