Merge remote-tracking branch 'gerrit/master' into containers
[profile/ivi/qtbase.git] / src / sql / kernel / qsqlresult.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtSql module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSQLRESULT_H
43 #define QSQLRESULT_H
44
45 #include <QtCore/qvariant.h>
46 #include <QtCore/qvector.h>
47 #include <QtSql/qsql.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 QT_MODULE(Sql)
54
55 class QString;
56 class QSqlRecord;
57 template <typename T> class QVector;
58 class QVariant;
59 class QSqlDriver;
60 class QSqlError;
61 class QSqlResultPrivate;
62
63 class Q_SQL_EXPORT QSqlResult
64 {
65     friend class QSqlQuery;
66     friend class QSqlTableModelPrivate;
67     friend class QSqlResultPrivate;
68
69 public:
70     virtual ~QSqlResult();
71     virtual QVariant handle() const;
72
73 protected:
74     enum BindingSyntax {
75         PositionalBinding,
76         NamedBinding
77     };
78
79     explicit QSqlResult(const QSqlDriver * db);
80     int at() const;
81     QString lastQuery() const;
82     QSqlError lastError() const;
83     bool isValid() const;
84     bool isActive() const;
85     bool isSelect() const;
86     bool isForwardOnly() const;
87     const QSqlDriver* driver() const;
88     virtual void setAt(int at);
89     virtual void setActive(bool a);
90     virtual void setLastError(const QSqlError& e);
91     virtual void setQuery(const QString& query);
92     virtual void setSelect(bool s);
93     virtual void setForwardOnly(bool forward);
94
95     // prepared query support
96     virtual bool exec();
97     virtual bool prepare(const QString& query);
98     virtual bool savePrepare(const QString& sqlquery);
99     virtual void bindValue(int pos, const QVariant& val, QSql::ParamType type);
100     virtual void bindValue(const QString& placeholder, const QVariant& val,
101                            QSql::ParamType type);
102     void addBindValue(const QVariant& val, QSql::ParamType type);
103     QVariant boundValue(const QString& placeholder) const;
104     QVariant boundValue(int pos) const;
105     QSql::ParamType bindValueType(const QString& placeholder) const;
106     QSql::ParamType bindValueType(int pos) const;
107     int boundValueCount() const;
108     QVector<QVariant>& boundValues() const;
109     QString executedQuery() const;
110     QString boundValueName(int pos) const;
111     void clear();
112     bool hasOutValues() const;
113
114     BindingSyntax bindingSyntax() const;
115
116     virtual QVariant data(int i) = 0;
117     virtual bool isNull(int i) = 0;
118     virtual bool reset(const QString& sqlquery) = 0;
119     virtual bool fetch(int i) = 0;
120     virtual bool fetchNext();
121     virtual bool fetchPrevious();
122     virtual bool fetchFirst() = 0;
123     virtual bool fetchLast() = 0;
124     virtual int size() = 0;
125     virtual int numRowsAffected() = 0;
126     virtual QSqlRecord record() const;
127     virtual QVariant lastInsertId() const;
128
129     enum VirtualHookOperation { BatchOperation, DetachFromResultSet, SetNumericalPrecision, NextResult };
130     virtual void virtual_hook(int id, void *data);
131     bool execBatch(bool arrayBind = false);
132     void detachFromResultSet();
133     void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy);
134     QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
135     bool nextResult();
136
137 private:
138     QSqlResultPrivate* d;
139     void resetBindCount(); // HACK
140
141 private:
142     Q_DISABLE_COPY(QSqlResult)
143 };
144
145 QT_END_NAMESPACE
146
147 QT_END_HEADER
148
149 #endif // QSQLRESULT_H