9#if __DCL_HAVE_ALLOC_DEBUG
10#undef __DCL_ALLOC_LEVEL
11#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
23#define __DCL_TRACE0_N __DCL_TRACE0
24#define __DCL_TRACE1_N __DCL_TRACE1
25#define __DCL_TRACE2_N __DCL_TRACE2
26#define __DCL_TRACE3_N __DCL_TRACE3
27#define __DCL_TRACE4_N __DCL_TRACE4
29#define __DCL_TRACE0_N(fmt)
30#define __DCL_TRACE1_N(fmt, arg)
31#define __DCL_TRACE2_N(fmt, arg1, arg2)
32#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
33#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
41#define __SET_ERROR_HANDLE(_error) \
42 conn()->setErrorHandle(_error, __THIS_FILE__, __LINE__)
43#define __SET_ERROR_MSG(_msg) \
44 conn()->setErrorMessage(_msg, __THIS_FILE__, __LINE__)
64 size_t buflen =
sizeof(buf) - 1;
65 bool b = conn()->__getErrorMessage(buf, &buflen);
66 buf[b ? buflen : 0] =
'\0';
82 Query::__affectedRows = -1;
88 Query::__fieldCount = 0;
95 Query::__paramCount = 0;
112 if (
__stmt->state >= MYSQL_STMT_USE_OR_STORE_CALLED) {
113 if (mysql_stmt_free_result(
__stmt)) {
121 if (mysql_stmt_close(
__stmt)) {
123 mysql_errno(conn()->connHandle()),
124 mysql_error(conn()->connHandle()))
134static unsigned long __TYPE_SIZE(
const MYSQL_FIELD* _field)
136 unsigned long size = 0;
137 switch (_field->type) {
138 case MYSQL_TYPE_TINY :
139 size =
sizeof(int8_t);
141 case MYSQL_TYPE_YEAR :
142 case MYSQL_TYPE_SHORT :
143 size =
sizeof(int16_t);
145 case MYSQL_TYPE_INT24 :
146 case MYSQL_TYPE_LONG :
147 size =
sizeof(int32_t);
149 case MYSQL_TYPE_LONGLONG :
150 size =
sizeof(int64_t);
152 case MYSQL_TYPE_FLOAT :
153 size =
sizeof(float);
155 case MYSQL_TYPE_DOUBLE :
156 size =
sizeof(double);
158 case MYSQL_TYPE_DATE:
159 case MYSQL_TYPE_TIME:
160 case MYSQL_TYPE_DATETIME:
161 case MYSQL_TYPE_TIMESTAMP:
162 size =
sizeof(MYSQL_TIME);
165 size =
sizeof(int64_t);
171 size = _field->length <= 3000 ? _field->length : 0;
176static size_t __TYPE_ALIGN(
size_t _offset,
const MYSQL_FIELD* _field)
179 switch (_field->type) {
180 case MYSQL_TYPE_TINY:
181 size =
sizeof(int8_t);
183 case MYSQL_TYPE_YEAR:
184 case MYSQL_TYPE_SHORT:
185 size =
sizeof(int16_t);
187 case MYSQL_TYPE_INT24:
188 case MYSQL_TYPE_LONG:
189 size =
sizeof(int32_t);
191 case MYSQL_TYPE_LONGLONG:
192 size =
sizeof(int64_t);
194 case MYSQL_TYPE_FLOAT:
195 size =
sizeof(float);
197 case MYSQL_TYPE_DOUBLE:
198 size =
sizeof(double);
200 case MYSQL_TYPE_DATE:
201 case MYSQL_TYPE_TIME:
202 case MYSQL_TYPE_DATETIME:
203 case MYSQL_TYPE_TIMESTAMP:
209 return (_offset + size - 1) & ~(size - 1);
215 && (
__stmt->field_count > 0)
216 && (Query::__fieldCount == 0)
221 size_t alloc =
sizeof(MYSQL_BIND) *
__stmt->field_count;
232 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
233 MYSQL_FIELD* field =
__stmt->fields + i;
234 offset = __TYPE_ALIGN(offset, field);
237 offset, __TYPE_SIZE(field), field.name);
238 offset += __TYPE_SIZE(field);
256 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
257 MYSQL_FIELD* field =
__stmt->fields + i;
260 offset = __TYPE_ALIGN(offset, field);
261 bind->buffer_length = __TYPE_SIZE(field);
262 bind->buffer_type = field->type;
263 bind->buffer = outBuffer + offset;
264 offset += bind->buffer_length;
266 bind->length = &(bind->length_value);
267 bind->is_null = &(bind->is_null_value);
268 bind->error = &(bind->error_value);
279 Query::__fieldCount =
__stmt->field_count;
286 for(
unsigned int i = 0; i < Query::__fieldCount; i++) {
287 MYSQL_FIELD* field =
__stmt->fields + i;
289 if (!
__fields[i].init(
this, i, field, bind))
301 && (
__stmt->param_count > 0));
304 Query::__paramCount =
__stmt->param_count;
305 size_t alloc =
sizeof(MYSQL_BIND) * Query::__paramCount;
319 for(
unsigned int i = 0; i < Query::__paramCount; i++) {
321 bind->is_null = &bind->is_null_value;
322 if (!
__params[i].init(
this, i, bind))
335 if ((
__stmt = mysql_stmt_init(conn()->connHandle())) ==
NULL) {
340 int r = mysql_stmt_prepare(
__stmt, _sql, (
unsigned long)_sqllen);
355 for (
unsigned int i = 0; i <
__stmt->param_count; i++) {
356 MYSQL_BIND* e = &(
__stmt->params[i]);
358 i, e->buffer, e->buffer_length,
__dataTypeName(e->buffer_type, e->flags));
360 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
361 MYSQL_FIELD* e = &(
__stmt->fields[i]);
367 if (_paramCount > 0) {
379 if (Query::__paramCount) {
391 for (
size_t i = 0; i < Query::__paramCount; i++) {
392 if (!
__params[i].onBeforeExecute()) {
397 if (mysql_stmt_execute(
__stmt)) {
406 for (
size_t i = 0; i < Query::__paramCount; i++) {
415 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
416 MYSQL_FIELD* e = &(
__stmt->fields[i]);
420 if (conn()->connHandle()->server_status & SERVER_PS_OUT_PARAMS) {
427 Query::__eof =
__stmt->field_count == 0;
428 Query::__affectedRows = -1;
430 if (
__stmt->field_count) {
434 if (conn()->storeResult()) {
436 if (mysql_stmt_store_result(
__stmt)) {
447 Query::__affectedRows = mysql_stmt_affected_rows(
__stmt);
457 int r = mysql_stmt_fetch(
__stmt);
459 case MYSQL_NO_DATA: {
464 case MYSQL_DATA_TRUNCATED: {
472 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
473 MYSQL_BIND& b =
__stmt->bind[i];
474 __DCL_TRACE2(L
"field[%u] [%u]\n", i, b.error ? *b.error : 0);
502 Query::__fieldCount = 0;
512 if (
__stmt->state >= MYSQL_STMT_USE_OR_STORE_CALLED) {
513 if (mysql_stmt_free_result(
__stmt)) {
522 int r = mysql_stmt_next_result(
__stmt);
530 Query::__affectedRows = (size_t)-1;
532 *_moreResults =
false;
536 *_moreResults =
true;
553 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
554 MYSQL_FIELD* e = &(
__stmt->fields[i]);
558 if (conn()->connHandle()->server_status & SERVER_PS_OUT_PARAMS) {
565 Query::__eof =
__stmt->field_count == 0;
566 Query::__affectedRows = -1;
568 if (
__stmt->field_count) {
572 if (conn()->storeResult()) {
574 if (mysql_stmt_store_result(
__stmt)) {
585 Query::__affectedRows = mysql_stmt_affected_rows(
__stmt);
593 *_moreResults = !Query::__eof;
600 __DCL_ASSERT((0 <= _index) && (_index < Query::__fieldCount));
601 *_fieldHandleOut = &
__fields[_index];
608 __DCL_ASSERT((0 <= _index) && (_index < Query::__paramCount));
609 *_paramHandleOut = &
__params[_index];
#define __DCL_TRACE1_N(fmt, arg)
#define __DCL_TRACE2_N(fmt, arg1, arg2)
#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
#define __SET_ERROR_MSG(_message)
#define __DCL_TRACE0_N(fmt)
#define __SET_ERROR_HANDLE(_SQLCODE)
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
#define __DCL_TRACE1(fmt, arg1)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
#define __DCL_TRACE2(fmt, arg1, arg2)
MyQuery(MyConnection *pConnection)
virtual bool __moreResults(bool *_moreResults)
virtual bool __getParam(size_t _index, SQL::Param **_paramHandleOut)
bool initParams(size_t _paramCount)
virtual bool __prepare(const char *_sql, size_t _sqllen, size_t _paramCount)
virtual bool __getField(size_t _index, SQL::Field **_fieldHandleOut)