~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/toeventquery.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-04-07 13:16:05 UTC
  • mfrom: (1.2.7 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090407131605-u422yigfv7jgg0l0
Tags: 2.0.0-3
* Cleaned up packaging a little bit.
* Added homepage information to control file.
* Bumped Standards-Version to 3.8.1.
* Released to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
3
 *
 
4
 * TOra - An Oracle Toolkit for DBA's and developers
 
5
 * 
 
6
 * Shared/mixed copyright is held throughout files in this product
 
7
 * 
 
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
 
11
 * 
 
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.
 
16
 * 
 
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.
 
21
 * 
 
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.
 
25
 * 
 
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.
 
30
 * 
 
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
 
34
 *      these libraries. 
 
35
 * 
 
36
 *      You may link this product with any GPL'd Qt library.
 
37
 * 
 
38
 * All trademarks belong to their respective owners.
 
39
 *
 
40
 * END_COMMON_COPYRIGHT_HEADER */
 
41
 
 
42
#ifndef TOEVENTQUERY_H
 
43
#define TOEVENTQUERY_H
 
44
 
 
45
#include "config.h"
 
46
#include "toconnection.h"
 
47
#include "toeventquerytask.h"
 
48
 
 
49
#include <QObject>
 
50
#include <QPointer>
 
51
 
 
52
class toResultStats;
 
53
 
 
54
 
 
55
/**
 
56
 * Run a query in the background without blocking. This class should
 
57
 * always be in the main thread, it uses toEventQueryTask to actually
 
58
 * run the sql.
 
59
 *
 
60
 */
 
61
class toEventQuery : public QObject {
 
62
    Q_OBJECT;
 
63
 
 
64
private:
 
65
 
 
66
    ValuesList Values;
 
67
 
 
68
    // SQL to execute.
 
69
    QString SQL;
 
70
 
 
71
    // Bind parameters
 
72
    toQList Param;
 
73
 
 
74
    // Number of rows processed.
 
75
    int Processed;
 
76
 
 
77
    // Statistics to be used if any.
 
78
    QPointer<toResultStats> Statistics;
 
79
 
 
80
    // Description of result
 
81
    toQDescList Description;
 
82
 
 
83
    // Number of columns in Description
 
84
    int Columns;
 
85
 
 
86
    // QThread instance that will do actual reading
 
87
    QPointer<toEventQueryTask> Task;
 
88
 
 
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
 
93
    // waiting.
 
94
    volatile bool TaskDone;
 
95
 
 
96
    // connection for this query
 
97
    toConnection *Connection;
 
98
 
 
99
public:
 
100
 
 
101
    /** 
 
102
     * Create a new query.
 
103
     *
 
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.
 
108
     */
 
109
    toEventQuery(toConnection &conn,
 
110
                 const QString &sql,
 
111
                 const toQList &param,
 
112
                 toResultStats *statistics = NULL);
 
113
 
 
114
 
 
115
    /**
 
116
     * Create a new query.
 
117
     *
 
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
 
123
     * values from query.
 
124
     */
 
125
    toEventQuery(toConnection &conn,
 
126
                   toQuery::queryMode mode,
 
127
                   const QString &sql,
 
128
                   const toQList &param,
 
129
                   toResultStats *statistics = NULL);
 
130
 
 
131
    /**
 
132
     * Undefined copy contructor. Don't copy me.
 
133
     *
 
134
     */
 
135
    toEventQuery(toEventQuery &other);
 
136
 
 
137
 
 
138
    virtual ~toEventQuery();
 
139
 
 
140
 
 
141
    /**
 
142
     * Start the query. Must be called prior to any other function.
 
143
     *
 
144
     */
 
145
    void start(void);
 
146
 
 
147
 
 
148
    /**
 
149
     * Get description of columns.
 
150
     *
 
151
     * @return Description of columns list.
 
152
     */
 
153
    inline toQDescList describe(void) const {
 
154
        return Description;
 
155
    }
 
156
 
 
157
 
 
158
    /**
 
159
     * Get column count
 
160
     *
 
161
     */
 
162
    inline int columns(void) const {
 
163
        return Columns;
 
164
    }
 
165
 
 
166
 
 
167
    /**
 
168
     * Read the next value from the query.
 
169
     *
 
170
     * @return The next available value.
 
171
     */
 
172
    toQValue readValue(void);
 
173
 
 
174
 
 
175
    /**
 
176
     * Read the next value from the query. Don't send NULL as string.
 
177
     *
 
178
     * @return The next available value.
 
179
     */
 
180
    toQValue readValueNull(void);
 
181
 
 
182
 
 
183
    /**
 
184
     * Get the number of rows processed.
 
185
     *
 
186
     * @return Number of rows processed.
 
187
     */
 
188
    inline int rowsProcessed(void) const {
 
189
        return Processed;
 
190
    }
 
191
 
 
192
 
 
193
    /**
 
194
     * Check if at end of query.
 
195
     *
 
196
     * @return True if query is done.
 
197
     */
 
198
    bool eof(void) const;
 
199
 
 
200
 
 
201
    /**
 
202
     * return query's sql command
 
203
     *
 
204
     */
 
205
    inline const QString sql(void) const {
 
206
        return SQL;
 
207
    }
 
208
 
 
209
 
 
210
    /**
 
211
     * Returns true if more data is available for readValue()
 
212
     *
 
213
     */
 
214
    bool hasMore(void) const {
 
215
        return !Values.isEmpty();
 
216
    }
 
217
 
 
218
 
 
219
private slots:
 
220
 
 
221
    // handle tasks's data() signal. emits dataAvailable()
 
222
    void taskData(ValuesList &values);
 
223
 
 
224
    // handle tasks's headers() signal emits descriptionAvailable()
 
225
    void taskDesc(toQDescList &desc, int columns);
 
226
 
 
227
    // handle tasks's error() signal
 
228
    void taskError(const toConnection::exception &msg);
 
229
 
 
230
    // handle task finished
 
231
    void taskFinished(void);
 
232
 
 
233
public slots:
 
234
 
 
235
    /**
 
236
     * Stop reading query
 
237
     *
 
238
     */
 
239
    void stop(void);
 
240
 
 
241
 
 
242
    /**
 
243
     * Read all data
 
244
     *
 
245
     */
 
246
    void readAll(void) {
 
247
        if(Task)
 
248
            Task->read(true);
 
249
    }
 
250
 
 
251
 
 
252
signals:
 
253
 
 
254
 
 
255
    /**
 
256
     * Emitted when header descriptions are available
 
257
     *
 
258
     */
 
259
    void descriptionAvailable();
 
260
 
 
261
 
 
262
    /**
 
263
     * Emitted when data has been read.
 
264
     *
 
265
     * @param rows Number of rows to be read
 
266
     */
 
267
    void dataAvailable();
 
268
 
 
269
 
 
270
    /**
 
271
     * Emitted with error string
 
272
     *
 
273
     */
 
274
    void error(const toConnection::exception &);
 
275
 
 
276
 
 
277
    /**
 
278
     * Emitted when done
 
279
     *
 
280
     */
 
281
    void done();
 
282
};
 
283
 
 
284
#endif