DCL 4.0
Loading...
Searching...
No Matches
MyParam Class Reference

#include <MyParam.h>

Inheritance diagram for MyParam:
SQL::Param SQL::Field Object

Public Member Functions

bool init (SQL::Query *_query, unsigned int _index, MYSQL_BIND *_bind)
bool onBeforeExecute ()
void onAfterExecute ()
 MyParam ()
virtual ~MyParam ()
virtual const wchar_t * serverDataTypeName () const
virtual void setNull ()
virtual bool __setData (_CONST void *_pv, size_t _size, SQL::DataType _dataType, SQL::DataType _assignType)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

void setErrorStatus (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorStatus (const ByteString &_message, const wchar_t *_filename, int _line)
MyQueryquery () const
Protected Member Functions inherited from SQL::Param
 Param (Query *_queryHandle)
virtual ~Param ()
virtual bool isNull () const
virtual bool __setDataType (DataType _dataType)
virtual bool __getDataSize (size_t *_pn, bool _maxSize)
virtual bool __getData (void *_pv, size_t *_pn, DataType _dataType)
Protected Member Functions inherited from SQL::Field
 Field (Query *_queryHandle)
virtual ~Field ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Additional Inherited Members

Protected Attributes inherited from SQL::Field
Query__queryHandle
String __name
DataType __dataType
short __precision
short __scale

Detailed Description

Definition at line 8 of file MyParam.h.

Constructor & Destructor Documentation

◆ MyParam()

MyParam::MyParam ( )

◆ ~MyParam()

MyParam::~MyParam ( )
virtual

Definition at line 52 of file MyParam.cpp.

53{
54
55}

Member Function Documentation

◆ __setData()

bool MyParam::__setData ( _CONST void * _pv,
size_t _size,
SQL::DataType _dataType,
SQL::DataType _assignType )
virtual

Implements SQL::Param.

Definition at line 145 of file MyParam.cpp.

151{
152 switch(_dataType) {
153 case SQL::typeInteger: {
154 switch (_size) {
155 case sizeof(int8_t) : {
156 __data.i32 = (int32_t) * (int8_t*)_pv;
157 __bind->buffer_type = MYSQL_TYPE_LONG;
158 __bind->buffer_length = sizeof(int32_t);
159 __bind->buffer = &__data;
160 break;
161 }
162 case sizeof(int16_t) : {
163 __data.i32 = (int32_t) * (int16_t*)_pv;
164 __bind->buffer_type = MYSQL_TYPE_LONG;
165 __bind->buffer_length = sizeof(int32_t);
166 __bind->buffer = &__data;
167 break;
168 }
169 case sizeof(int32_t) : {
170 __data.i32 = (int32_t) * (int32_t*)_pv;
171 __bind->buffer_type = MYSQL_TYPE_LONG;
172 __bind->buffer_length = sizeof(int32_t);
173 __bind->buffer = &__data;
174 break;
175 }
176 case sizeof(int64_t) : {
177 __data.i64 = (int64_t) * (int64_t*)_pv;
178 __bind->buffer_type = MYSQL_TYPE_LONGLONG;
179 __bind->buffer_length = sizeof(int64_t);
180 __bind->buffer = &__data;
181 break;
182 }
183 default: {
185 return false;
186 }
187 }
188 __bind->is_unsigned = 0;
189 break;
190 }
191 case SQL::typeUInteger : {
192 switch (_size) {
193 case sizeof(uint8_t) : {
194 __data.u32 = (uint32_t) * (uint8_t*)_pv;
195 __bind->buffer_type = MYSQL_TYPE_LONG;
196 __bind->buffer_length = sizeof(uint32_t);
197 __bind->buffer = &__data;
198 break;
199 }
200 case sizeof(uint16_t) : {
201 __data.u32 = (uint32_t) * (uint16_t*)_pv;
202 __bind->buffer_type = MYSQL_TYPE_LONG;
203 __bind->buffer_length = sizeof(uint32_t);
204 __bind->buffer = &__data;
205 break;
206 }
207 case sizeof(uint32_t) : {
208 __data.u32 = (uint32_t) * (uint32_t*)_pv;
209 __bind->buffer_type = MYSQL_TYPE_LONG;
210 __bind->buffer_length = sizeof(uint32_t);
211 __bind->buffer = &__data;
212 break;
213 }
214 case sizeof(uint64_t) : {
215 __data.u64 = (uint64_t) * (uint64_t*)_pv;
216 __bind->buffer_type = MYSQL_TYPE_LONGLONG;
217 __bind->buffer_length = sizeof(uint64_t);
218 __bind->buffer = &__data;
219 break;
220 }
221 default: {
223 return false;
224 }
225 }
226 __bind->is_unsigned = 1;
227 break;
228 }
229 case SQL::typeFloat: {
230 switch (_size) {
231 case sizeof(float) : {
232 __data.f32 = *(float*)_pv;
233 __bind->buffer_type = MYSQL_TYPE_FLOAT;
234 __bind->buffer_length = sizeof(float);
235 __bind->buffer = &__data;
236 break;
237 }
238 case sizeof(double) : {
239 __data.f64 = *(double*)_pv;
240 __bind->buffer_type = MYSQL_TYPE_DOUBLE;
241 __bind->buffer_length = sizeof(double);
242 __bind->buffer = &__data;
243 break;
244 }
245 default: {
247 return false;
248 }
249 }
250 break;
251 }
252 case SQL::typeDate: {
253 if (_size == sizeof(SQL::Date)) {
254 const SQL::Date* p = (const SQL::Date*)_pv;
255 memset(&__data.time, 0, sizeof(MYSQL_TIME));
256 __data.time.year = __ABS(p->nYear);
257 __data.time.month = p->nMonth;
258 __data.time.day = p->nDay;
259 __data.time.neg = p->nYear < 0 ? 1 : 0;
260 __data.time.time_type = MYSQL_TIMESTAMP_DATE;
261 __bind->buffer_type = MYSQL_TYPE_DATE;
262 __bind->buffer_length = sizeof(MYSQL_TIME);
263 __bind->buffer = &__data;
264 }
265 else {
267 return false;
268 }
269 break;
270 }
271 case SQL::typeTime: {
272 if (_size == sizeof(SQL::Time)) {
273 const SQL::Time* p = (const SQL::Time*)_pv;
274 memset(&__data.time, 0, sizeof(MYSQL_TIME));
275 __data.time.hour = p->nHour;
276 __data.time.minute = p->nMin;
277 __data.time.second = p->nSec;
278 __data.time.second_part = p->nFrac / 1000;
279 __data.time.neg = 0;
280 __data.time.time_type = MYSQL_TIMESTAMP_TIME;
281 __bind->buffer_type = MYSQL_TYPE_TIME;
282 __bind->buffer_length = sizeof(MYSQL_TIME);
283 __bind->buffer = &__data;
284 }
285 else {
287 return false;
288 }
289 break;
290 }
291 case SQL::typeTimeStamp: {
292 if (_size == sizeof(SQL::TimeStamp)) {
293 const SQL::TimeStamp* p = (const SQL::TimeStamp*)_pv;
294 //if (p->nTzMin != INT16_MIN) {
295 // __SET_ERROR(SQL::eInvalidData);
296 // return false;
297 //}
298 __data.time.year = __ABS(p->nYear);
299 __data.time.month = p->nMonth;
300 __data.time.day = p->nDay;
301 __data.time.hour = p->nHour;
302 __data.time.minute = p->nMin;
303 __data.time.second = p->nSec;
304 __data.time.second_part = p->nFrac / 1000;
305 __data.time.neg = p->nYear < 0 ? 1 : 0;
306 __data.time.time_type = MYSQL_TIMESTAMP_DATETIME;
307 __bind->buffer_type = MYSQL_TYPE_DATETIME;
308 __bind->buffer_length = sizeof(MYSQL_TIME);
309 __bind->buffer = &__data;
310 }
311 else {
313 return false;
314 }
315 break;
316 }
319 case SQL::typeIntervalDs: {
320 if (_size == sizeof(SQL::Interval)) {
321 const SQL::Interval* p = (const SQL::Interval*)_pv;
322 __data.time.year = 0;
323 __data.time.month = 0;
324 __data.time.day = __ABS(p->nYears * 365 + p->nMonths * 30 + p->nDays);
325 __data.time.hour = __ABS(p->nHours);
326 __data.time.minute = __ABS(p->nMins);
327 __data.time.second = __ABS(p->nSecs);
328 __data.time.second_part = __ABS(p->nFracs) / 1000;
329 __data.time.neg = p->nYears < 0 || p->nMonths < 0 || p->nDays
330 || p->nHours < 0 || p->nMins || p->nSecs || p->nFracs < 0 ? 1 : 0;
331 __data.time.time_type = MYSQL_TIMESTAMP_TIME;
332 __bind->buffer_type = MYSQL_TYPE_TIME;
333 __bind->buffer_length = sizeof(MYSQL_TIME);
334 __bind->buffer = &__data;
335 }
336 else {
338 return false;
339 }
340 break;
341 }
342 case SQL::typeText :
343 case SQL::typeBinary: {
344 if (_size > UINT32_MAX) {
346 return false;
347 }
348 __bind->buffer_type = MYSQL_TYPE_STRING;
349 __bind->buffer_length = (unsigned int) _size;
350 __bind->buffer = _pv;
351 break;
352 }
353 case SQL::typeInputStream : {
354 if (_size != (size_t)-1 && _size > UINT32_MAX) {
356 return false;
357 }
358 __bind->buffer_type = MYSQL_TYPE_STRING;
359 __bind->buffer_length = 0;
360 __bind->buffer = NULL;
361 __input = (InputStream*)_pv;
362 __size = _size;
363 break;
364 }
365 default:
368 return false;
369 }
370 }
371
372 __bind->is_null_value = 0;
373 Param::__dataType = _assignType;
374 return true;
375}
#define NULL
Definition Config.h:340
#define UINT32_MAX
Definition Config.h:323
#define __ABS(n)
Definition MyParam.cpp:143
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:150
@ typeBinary
Definition SQLCore.h:76
@ typeTime
Definition SQLCore.h:69
@ typeUInteger
Definition SQLCore.h:65
@ typeTimeStamp
Definition SQLCore.h:70
@ typeInputStream
Definition SQLCore.h:83
@ typeTimeStampTz
Definition SQLCore.h:71
@ typeInterval
Definition SQLCore.h:72
@ typeIntervalDs
Definition SQLCore.h:74
@ typeDate
Definition SQLCore.h:68
@ typeText
Definition SQLCore.h:75
@ typeFloat
Definition SQLCore.h:66
@ typeInteger
Definition SQLCore.h:64
@ typeIntervalYm
Definition SQLCore.h:73
@ eNotSupportDataType
Definition SQLCore.h:48
@ eInvalidDataSize
Definition SQLCore.h:57
uint8_t nMonth
Definition SQLCore.h:97
int16_t nYear
Definition SQLCore.h:96
uint8_t nDay
Definition SQLCore.h:98
int8_t nHours
Definition SQLCore.h:128
int32_t nFracs
Definition SQLCore.h:131
int8_t nSecs
Definition SQLCore.h:130
int8_t nMins
Definition SQLCore.h:129
int32_t nYears
Definition SQLCore.h:125
int8_t nMonths
Definition SQLCore.h:126
int32_t nDays
Definition SQLCore.h:127
uint8_t nHour
Definition SQLCore.h:103
uint8_t nMin
Definition SQLCore.h:104
uint8_t nSec
Definition SQLCore.h:105
uint32_t nFrac
Definition SQLCore.h:106
int16_t nYear
Definition SQLCore.h:111
uint8_t nDay
Definition SQLCore.h:113
uint8_t nHour
Definition SQLCore.h:114
uint8_t nSec
Definition SQLCore.h:116
uint8_t nMonth
Definition SQLCore.h:112
uint8_t nMin
Definition SQLCore.h:115
uint32_t nFrac
Definition SQLCore.h:117

◆ init()

bool MyParam::init ( SQL::Query * _query,
unsigned int _index,
MYSQL_BIND * _bind )

Definition at line 57 of file MyParam.cpp.

58{
59 __DCL_ASSERT(Param::__queryHandle == NULL);
60 Param::__queryHandle = _query;
61 __index = _index;
62 __bind = _bind;
63
64 return true;
65}
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ onAfterExecute()

void MyParam::onAfterExecute ( )

Definition at line 99 of file MyParam.cpp.

100{
101 Param::__dataType = SQL::typeUnknown;
102 __bind->buffer_length = 0;
103 __bind->buffer = NULL;
104 __bind->length_value = 0;
105 __bind->is_null_value = 1;
106 __input = NULL;
107 __size = 0;
108}
@ typeUnknown
Definition SQLCore.h:63

◆ onBeforeExecute()

bool MyParam::onBeforeExecute ( )

Definition at line 67 of file MyParam.cpp.

68{
69 if (__input) {
70 try {
71 char buf[4096];
72 size_t total = 0;
73 for (; ; ) {
74 size_t n = __MIN(__size - total, sizeof(buf));
75 if (n && (n = __input->read(buf, n))) {
76 __DCL_TRACE1_N(L"mysql_stmt_send_long_data [%u]\n", n);
77 if (mysql_stmt_send_long_data(query()->stmt(),
78 __index, buf, (unsigned int) n)) {
79 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
80 mysql_stmt_errno(query()->stmt()),
81 mysql_stmt_error(query()->stmt())));
82 return false;
83 }
84 }
85 else {
86 break;
87 }
88 }
89 }
90 catch (IOException* e) {
91 __SET_ERROR_MSG(UTF8Encoder::encode(e->toStringAll()));
92 e->destroy();
93 return false;
94 }
95 }
96 return true;
97}
#define __DCL_TRACE1_N(fmt, arg)
#define __SET_ERROR_MSG(_message)
ByteBuffer * buf
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
MyQuery * query() const
Definition MyParam.h:74
size_t __MIN(size_t x, size_t y)
Definition size_t.h:27

◆ query()

MyQuery * MyParam::query ( ) const
inlineprotected

Definition at line 74 of file MyParam.h.

75{
76 return (MyQuery*)Param::__queryHandle;
77}

◆ serverDataTypeName()

const wchar_t * MyParam::serverDataTypeName ( ) const
virtual

Implements SQL::Field.

Definition at line 113 of file MyParam.cpp.

114{
115 unsigned int flags = 0;
116 switch (SQL::Param::__dataType) {
117 case SQL::typeUInteger :
118 flags = UNSIGNED_FLAG;
119 break;
120 case SQL::typeBinary :
122 case SQL::typeBlob :
123 flags = BINARY_FLAG;
124 break;
125 default:
126 ;
127 }
128
129 return __dataTypeName(__bind->buffer_type, flags);
130}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:290
DataType __dataType
Definition SQLCore.h:184
@ typeLongBinary
Definition SQLCore.h:78
@ typeBlob
Definition SQLCore.h:80

◆ setErrorStatus() [1/2]

void MyParam::setErrorStatus ( const ByteString & _message,
const wchar_t * _filename,
int _line )
inlineprotected

Definition at line 64 of file MyParam.h.

66{
67 ((MyConnection*)Param::connection())->setErrorStatus(
68 _message,
69 _filename,
70 _line
71 );
72}

◆ setErrorStatus() [2/2]

void MyParam::setErrorStatus ( SQL::Error _error,
const wchar_t * _filename,
int _line )
inlineprotected

Definition at line 54 of file MyParam.h.

56{
57 ((MyConnection*)Param::connection())->setErrorStatus(
58 _error,
59 _filename,
60 _line
61 );
62}

◆ setNull()

void MyParam::setNull ( )
virtual

Implements SQL::Param.

Definition at line 132 of file MyParam.cpp.

133{
134 Param::__dataType = SQL::typeUnknown;
135 __bind->buffer_length = 0;
136 __bind->buffer = NULL;
137 __bind->length_value = 0;
138 __bind->is_null_value = 1;
139 __input = NULL;
140 __size = 0;
141}

Member Data Documentation

◆ f32

float MyParam::f32

Definition at line 19 of file MyParam.h.

◆ f64

double MyParam::f64

Definition at line 20 of file MyParam.h.

◆ i32

int32_t MyParam::i32

Definition at line 15 of file MyParam.h.

◆ i64

int64_t MyParam::i64

Definition at line 16 of file MyParam.h.

◆ time

MYSQL_TIME MyParam::time

Definition at line 21 of file MyParam.h.

◆ u32

uint32_t MyParam::u32

Definition at line 17 of file MyParam.h.

◆ u64

uint64_t MyParam::u64

Definition at line 18 of file MyParam.h.


The documentation for this class was generated from the following files: