2
/* BEGIN_COMMON_COPYRIGHT_HEADER
4
* TOra - An Oracle Toolkit for DBA's and developers
6
* Shared/mixed copyright is held throughout files in this product
8
* Portions Copyright (C) 2000-2001 Underscore AB
9
* Portions Copyright (C) 2003-2005 Quest Software, Inc.
10
* Portions Copyright (C) 2004-2008 Numerous Other Contributors
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; only version 2 of
15
* the License is valid for this program.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
* As a special exception, you have permission to link this program
27
* with the Oracle Client libraries and distribute executables, as long
28
* as you follow the requirements of the GNU GPL in regard to all of the
29
* software in the executable aside from Oracle client libraries.
31
* Specifically you are not permitted to link this program with the
32
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
33
* And you are not permitted to distribute binaries compiled against
36
* You may link this product with any GPL'd Qt library.
38
* All trademarks belong to their respective owners.
40
* END_COMMON_COPYRIGHT_HEADER */
42
#ifndef TOEVENTQUERY_H
43
#define TOEVENTQUERY_H
46
#include "toconnection.h"
47
#include "toeventquerytask.h"
56
* Run a query in the background without blocking. This class should
57
* always be in the main thread, it uses toEventQueryTask to actually
61
class toEventQuery : public QObject {
74
// Number of rows processed.
77
// Statistics to be used if any.
78
QPointer<toResultStats> Statistics;
80
// Description of result
81
toQDescList Description;
83
// Number of columns in Description
86
// QThread instance that will do actual reading
87
QPointer<toEventQueryTask> Task;
89
// true when task finishes. this set from a slot called by a
90
// queued message. the problem is that sometimes the thread can
91
// finish before it's messages have all been processed, making
92
// Task->isRunning() useless for detecting if there's data
94
volatile bool TaskDone;
96
// connection for this query
97
toConnection *Connection;
102
* Create a new query.
104
* @param conn Connection to run on.
105
* @param sql SQL to execute.
106
* @param param Parameters to pass to query.
107
* @param statistics Optional statistics widget to update with values from query.
109
toEventQuery(toConnection &conn,
111
const toQList ¶m,
112
toResultStats *statistics = NULL);
116
* Create a new query.
118
* @param conn Connection to run on.
119
* @param mode Query mode to execute query in.
120
* @param sql SQL to execute.
121
* @param param Parameters to pass to query.
122
* @param statistics Optional statistics widget to update with
125
toEventQuery(toConnection &conn,
126
toQuery::queryMode mode,
128
const toQList ¶m,
129
toResultStats *statistics = NULL);
132
* Undefined copy contructor. Don't copy me.
135
toEventQuery(toEventQuery &other);
138
virtual ~toEventQuery();
142
* Start the query. Must be called prior to any other function.
149
* Get description of columns.
151
* @return Description of columns list.
153
inline toQDescList describe(void) const {
162
inline int columns(void) const {
168
* Read the next value from the query.
170
* @return The next available value.
172
toQValue readValue(void);
176
* Read the next value from the query. Don't send NULL as string.
178
* @return The next available value.
180
toQValue readValueNull(void);
184
* Get the number of rows processed.
186
* @return Number of rows processed.
188
inline int rowsProcessed(void) const {
194
* Check if at end of query.
196
* @return True if query is done.
198
bool eof(void) const;
202
* return query's sql command
205
inline const QString sql(void) const {
211
* Returns true if more data is available for readValue()
214
bool hasMore(void) const {
215
return !Values.isEmpty();
221
// handle tasks's data() signal. emits dataAvailable()
222
void taskData(ValuesList &values);
224
// handle tasks's headers() signal emits descriptionAvailable()
225
void taskDesc(toQDescList &desc, int columns);
227
// handle tasks's error() signal
228
void taskError(const toConnection::exception &msg);
230
// handle task finished
231
void taskFinished(void);
256
* Emitted when header descriptions are available
259
void descriptionAvailable();
263
* Emitted when data has been read.
265
* @param rows Number of rows to be read
267
void dataAvailable();
271
* Emitted with error string
274
void error(const toConnection::exception &);