12
12
#ifndef PGQUERYTHREAD_H
13
13
#define PGQUERYTHREAD_H
17
#include "db/pgConn.h"
19
// Forward declaration
24
// Support for the IN & INOUT parameters type
25
class pgParam : public wxObject
33
PG_PARAM_VARIADIC = 4,
39
// This constructor won't call the functions - 'htonl' or 'htons'
40
// It will be the responsibility of the caller to take care
41
// to call 'htonl' or 'htons' depending on requirements.
44
// This data will be owned by pgParam object and will be released.
45
pgParam(Oid _type, void *_val, int _len, short mode = PG_PARAM_IN);
48
pgParam(Oid _type, wxString *_val, wxMBConv *_conv = NULL,
49
short mode = PG_PARAM_IN);
53
// Returns 0 for text type and 1 for otherwise
70
// Modes are required by EnterpriseDB's callable statement
73
// Do not allow copy construction and shadow-copy
75
// Force to use an pointer
76
pgParam(const pgParam &)
80
pgParam &operator= (const pgParam &)
86
friend class pgQueryThread;
89
WX_DEFINE_ARRAY_PTR(pgParam *, pgParamsArray);
91
class pgBatchQuery : public wxObject
94
pgBatchQuery(const wxString &_query, pgParamsArray *_params = NULL,
95
long _eventId = -1, void *_data = NULL, bool _useCallable = false,
96
int _resultToRetrieve = 0)
97
: m_query(_query), m_params(_params), m_eventID(_eventId), m_data(_data),
98
m_useCallable(_useCallable), m_resToRetrieve(_resultToRetrieve),
99
m_returnCode(-1), m_resultSet(NULL), m_rowsInserted(-1), m_insertedOid(-1)
101
// Do not honour the empty query string
102
wxASSERT(!_query.IsEmpty());
118
const wxString &GetMessage()
125
return m_rowsInserted;
128
const wxString &GetErrorMessage();
131
wxString m_query; // Query
132
pgParamsArray *m_params; // parameters
133
long m_eventID; // Event ID
134
void *m_data; // Data to be send with event
135
bool m_useCallable; // Use EnterpriseDB callable statement if possible
136
int m_resToRetrieve; // Which result to be retrieved
137
int m_returnCode; // Return code
138
pgSet *m_resultSet; // Result-Set
139
long m_rowsInserted; // No of rows inserted
140
Oid m_insertedOid; // Inserted Oid
141
wxString m_message; // Message generated during query execution
142
pgError m_err; // Error
145
// Do not allow copy construction and '=' operator (shadow copying)
146
// to avoid ownership of parameters and result-set
148
// This will force this class to be used as an pointer only.
149
pgBatchQuery(const pgBatchQuery &)
153
pgBatchQuery &operator= (const pgBatchQuery &)
158
friend class pgQueryThread;
160
WX_DEFINE_ARRAY_PTR(pgBatchQuery *, pgBatchQueryArray);
17
162
class pgQueryThread : public wxThread
20
pgQueryThread(pgConn *_conn, const wxString &qry, int resultToRetrieve = -1, wxWindow *_caller = 0, long eventId = 0, void *_data = 0);
165
// For running a single query (Used by few components)
166
pgQueryThread(pgConn *_conn, const wxString &qry, int resultToRetrieve = -1,
167
wxWindow *_caller = 0, long eventId = 0, void *_data = 0);
169
// Support for multiple queries support
170
pgQueryThread(pgConn *_conn, wxEvtHandler *_caller = NULL,
171
PQnoticeProcessor _processor = NULL, void *_noticeHandler = NULL);
175
bool HasMultipleQueriesSupport()
177
return m_multiQueries;
180
bool SupportCallableStatement()
182
return m_useCallable;
185
void SetEventOnCancellation(bool eventOnCancelled);
188
const wxString &_qry, pgParamsArray *_params = NULL,
189
long _eventId = 0, void *_data = NULL, bool _useCallable = false,
190
int _resultToRetrieve = -1);
23
192
virtual void *Entry();
24
bool DataValid() const
26
return dataSet != NULL;
32
int ReturnCode() const
36
long RowsInserted() const
40
OID InsertedOid() const
44
wxString GetMessagesAndClear();
45
void appendMessage(const wxString &str);
193
bool DataValid(int _idx = -1) const
197
return (_idx >= 0 && _idx > m_currIndex ? false : (m_queries[_idx]->m_resultSet != NULL));
205
pgSet *DataSet(int _idx = -1)
209
return (_idx >= 0 && _idx > m_currIndex ? NULL : m_queries[_idx]->m_resultSet);
212
int ReturnCode(int _idx = -1) const
216
return (_idx >= 0 && _idx > m_currIndex ? -1 : m_queries[_idx]->m_returnCode);
219
long RowsInserted(int _idx = -1) const
223
return (_idx >= 0 && _idx > m_currIndex ? -1L : m_queries[_idx]->m_rowsInserted);
226
Oid InsertedOid(int _idx = -1) const
230
return (_idx >= 0 && _idx > m_currIndex ? -1L : m_queries[_idx]->m_insertedOid);
233
inline void CancelExecution()
238
inline size_t GetNumberQueries()
240
return m_queries.GetCount();
243
size_t QueriesExecuted()
245
return m_currIndex + 1;
248
wxString GetMessagesAndClear(int _idx = -1);
249
void AppendMessage(const wxString &_str);
251
int DeleteReleasedQueries();
253
pgError GetResultError(int idx = -1);
58
wxCriticalSection criticalSection;
65
int raiseEvent(int retval = 0);
67
void appendMessageRaw(const wxString &str);
257
int RaiseEvent(int _retval = 0);
259
// Queries to be exectued
260
pgBatchQueryArray m_queries;
261
// Current running query index
265
// Execution cancelled?
267
// Raise events even when cancelled the execution
268
bool m_eventOnCancellation;
269
// Does this thread support multiple queries
271
// Use EDB callable statement (if available and require)
273
// Is executing a query
275
// Queries are being accessed at this time
276
wxMutex m_queriesLock;
277
// When one thread is accesing messages, other should not be able to access it
278
wxCriticalSection m_criticalSection;
280
wxEvtHandler *m_caller;
281
// Database server notice-processor
282
PQnoticeProcessor m_processor;
284
void *m_noticeHandler;