7#if __DCL_HAVE_ALLOC_DEBUG
8#undef __DCL_ALLOC_LEVEL
9#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
21#define __DCL_TRACE0_N __DCL_TRACE0
22#define __DCL_TRACE1_N __DCL_TRACE1
23#define __DCL_TRACE2_N __DCL_TRACE2
24#define __DCL_TRACE3_N __DCL_TRACE3
25#define __DCL_TRACE4_N __DCL_TRACE4
27#define __DCL_TRACE0_N(fmt)
28#define __DCL_TRACE1_N(fmt, arg)
29#define __DCL_TRACE2_N(fmt, arg1, arg2)
30#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
31#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
34#if __DCL_HAVE_THIS_FILE__
61 ByteBuffer*
buf = ByteBuffer::create(
n);
62 bool b = conn()->__getErrorMessage(
buf->data(), &
n);
64 buf->__dataLength =
n;
89 Query::__affectedRows = -1;
95 Query::__fieldCount = 0;
102 Query::__paramCount = 0;
124 if (
__stmt->state >= MYSQL_STMT_USE_OR_STORE_CALLED) {
125 if (mysql_stmt_free_result(
__stmt)) {
128 mysql_stmt_error(
__stmt)));
132 if (mysql_stmt_close(
__stmt)) {
134 mysql_errno(conn()->connHandle()),
135 mysql_error(conn()->connHandle())));
144static unsigned int __TYPE_SIZE(
const MYSQL_FIELD& _field)
146 unsigned int size = 0;
147 switch (_field.type) {
148 case MYSQL_TYPE_TINY :
149 size =
sizeof(int8_t);
151 case MYSQL_TYPE_YEAR :
152 case MYSQL_TYPE_SHORT :
153 size =
sizeof(int16_t);
155 case MYSQL_TYPE_INT24 :
156 case MYSQL_TYPE_LONG :
157 size =
sizeof(int32_t);
159 case MYSQL_TYPE_LONGLONG :
160 size =
sizeof(int64_t);
162 case MYSQL_TYPE_FLOAT :
163 size =
sizeof(float);
165 case MYSQL_TYPE_DOUBLE :
166 size =
sizeof(double);
168 case MYSQL_TYPE_DATE:
169 case MYSQL_TYPE_TIME:
170 case MYSQL_TYPE_DATETIME:
171 case MYSQL_TYPE_TIMESTAMP:
172 size =
sizeof(MYSQL_TIME);
175 size =
sizeof(int64_t);
181 size = _field.length <= 3000 ? _field.length : 0;
186static size_t __TYPE_ALIGN(
size_t _offset,
const MYSQL_FIELD& _field)
189 switch (_field.type) {
190 case MYSQL_TYPE_TINY:
191 size =
sizeof(int8_t);
193 case MYSQL_TYPE_YEAR:
194 case MYSQL_TYPE_SHORT:
195 size =
sizeof(int16_t);
197 case MYSQL_TYPE_INT24:
198 case MYSQL_TYPE_LONG:
199 size =
sizeof(int32_t);
201 case MYSQL_TYPE_LONGLONG:
202 size =
sizeof(int64_t);
204 case MYSQL_TYPE_FLOAT:
205 size =
sizeof(float);
207 case MYSQL_TYPE_DOUBLE:
208 size =
sizeof(double);
210 case MYSQL_TYPE_DATE:
211 case MYSQL_TYPE_TIME:
212 case MYSQL_TYPE_DATETIME:
213 case MYSQL_TYPE_TIMESTAMP:
219 return (_offset + size - 1) & ~(size - 1);
229 && (
__stmt->field_count > 0)
232 Query::__fieldCount =
__stmt->field_count;
233 size_t alloc =
sizeof(MYSQL_BIND) * Query::__fieldCount;
243 for (
size_t i = 0; i < Query::__fieldCount; i++) {
244 MYSQL_FIELD& field =
__stmt->fields[i];
245 offset = __TYPE_ALIGN(offset, field);
247 offset, __TYPE_SIZE(field), field.name);
248 offset += __TYPE_SIZE(field);
265 for (
size_t i = 0; i < Query::__fieldCount; i++) {
266 MYSQL_FIELD& field =
__stmt->fields[i];
269 offset = __TYPE_ALIGN(offset, field);
270 bind.buffer_length = __TYPE_SIZE(field);
271 bind.buffer_type = field.type;
273 offset += bind.buffer_length;
275 bind.length = &bind.length_value;
276 bind.is_null = &bind.is_null_value;
277 bind.error = &bind.error_value;
283 mysql_stmt_error(
__stmt)));
293 for(
unsigned int i = 0; i < Query::__fieldCount; i++) {
294 MYSQL_FIELD* field =
__stmt->fields + i;
296 if (!
__fields[i].init(
this, i, field, bind))
308 && (
__stmt->param_count > 0));
311 Query::__paramCount =
__stmt->param_count;
312 size_t alloc =
sizeof(MYSQL_BIND) * Query::__paramCount;
326 for(
unsigned int i = 0; i < Query::__paramCount; i++) {
328 bind->is_null = &bind->is_null_value;
329 if (!
__params[i].init(
this, i, bind))
342 if ((
__stmt = mysql_stmt_init(conn()->connHandle())) ==
NULL) {
347 int r = mysql_stmt_prepare(
__stmt, _sql, (
unsigned long)_sqllen);
351 mysql_stmt_error(
__stmt)));
361 for (
unsigned int i = 0; i <
__stmt->param_count; i++) {
362 MYSQL_BIND* e = &(
__stmt->params[i]);
364 i, e->buffer, e->buffer_length,
__dataTypeName(e->buffer_type, e->flags));
366 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
367 MYSQL_FIELD* e = &(
__stmt->fields[i]);
373 if (_paramCount > 0) {
386 if (Query::__paramCount) {
391 mysql_stmt_error(
__stmt)));
397 for (
size_t i = 0; i < Query::__paramCount; i++) {
398 if (!
__params[i].onBeforeExecute()) {
403 if (mysql_stmt_execute(
__stmt)) {
406 mysql_stmt_error(
__stmt)));
411 Query::__affectedRows = mysql_stmt_affected_rows(
__stmt);
415 for (
size_t i = 0; i < Query::__paramCount; i++) {
424 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
425 MYSQL_FIELD* e = &(
__stmt->fields[i]);
429 if (conn()->connHandle()->server_status & SERVER_PS_OUT_PARAMS) {
436 Query::__eof =
__stmt->field_count == 0;
438 if (
__stmt->field_count) {
442 if (conn()->storeResult()) {
444 if (mysql_stmt_store_result(
__stmt)) {
447 mysql_stmt_error(
__stmt)));
459 int r = mysql_stmt_fetch(
__stmt);
461 case MYSQL_NO_DATA: {
466 case MYSQL_DATA_TRUNCATED: {
474 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
475 MYSQL_BIND& b =
__stmt->bind[i];
476 __DCL_TRACE2(L
"field[%u] [%u]\n", i, b.error ? *b.error : 0);
493 mysql_stmt_error(
__stmt)));
503 Query::__fieldCount = 0;
518 if (
__stmt->state >= MYSQL_STMT_USE_OR_STORE_CALLED) {
519 if (mysql_stmt_free_result(
__stmt)) {
522 mysql_stmt_error(
__stmt)));
527 int r = mysql_stmt_next_result(
__stmt);
531 mysql_stmt_error(
__stmt)));
539 for (
unsigned int i = 0; i <
__stmt->field_count; i++) {
540 MYSQL_FIELD* e = &(
__stmt->fields[i]);
544 if (conn()->connHandle()->server_status & SERVER_PS_OUT_PARAMS) {
550 Query::__eof =
__stmt->field_count == 0;
552 if (
__stmt->field_count) {
556 if (conn()->storeResult()) {
558 if (mysql_stmt_store_result(
__stmt)) {
561 mysql_stmt_error(
__stmt)));
573 __DCL_ASSERT((0 <= _index) && (_index < Query::__fieldCount));
574 *_fieldHandleOut = &
__fields[_index];
581 __DCL_ASSERT((0 <= _index) && (_index < Query::__paramCount));
582 *_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 __SET_ERROR_MSG(_message)
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
#define __DCL_TRACE0_N(fmt)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
#define __DCL_TRACE2(fmt, arg1, arg2)
#define __SET_ERROR(_errorCode)
void CharsetConvertException *size_t n
MyQuery(MyConnection *pConnection)
virtual bool __nextResult()
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)