DCL 3.7.4
Loading...
Searching...
No Matches
IBParam Class Reference

#include <IBParam.h>

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

Public Member Functions

bool init (SQL::Query *_query, XSQLVAR *_sqlvar)
void onAfterExecute ()
 IBParam ()
virtual ~IBParam ()
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

IBQueryquery () const
IBConnectionconn () const
virtual const wchar_t * serverDataTypeName () const
virtual void setNull ()
virtual bool __setData (_CONST void *_val, size_t _size, SQL::DataType _valType, SQL::DataType _sqlType)
bool setInteger (const void *_val, size_t _size)
bool setUInteger (const void *_val, size_t _size)
bool setFloat (const void *_val, size_t _size)
bool setDate (const SQL::Date *_val, size_t _size)
bool setTime (const SQL::Time *_val, size_t _size)
bool setTimeStamp (const SQL::TimeStamp *_val, size_t _size)
bool setBytesToBlob (const byte_t *_val, size_t _size)
bool setInputStreamToBlob (_CONST InputStream *_input, size_t _size)
bool cancelBlob ()
Protected Member Functions inherited from SQL::Param
 Param (Query *_queryHandle)
virtual ~Param ()
virtual bool __setOutputType (DataType _sqlType)
virtual bool __getDataSize (size_t *_size, bool _maxsize)
virtual bool __getData (void *_buf, size_t *_size, DataType _bufType)
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 IBParam.h.

Constructor & Destructor Documentation

◆ IBParam()

IBParam::IBParam ( )

◆ ~IBParam()

IBParam::~IBParam ( )
virtual

Definition at line 43 of file IBParam.cpp.

44{
45 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
47 }
48}
#define __SQLTYPE_IS(_sqltype)
Definition IFXField.cpp:68
#define __DCL_VERIFY(expr)
Definition Object.h:396
bool cancelBlob()
Definition IBParam.cpp:456

Member Function Documentation

◆ __setData()

bool IBParam::__setData ( _CONST void * _val,
size_t _size,
SQL::DataType _valType,
SQL::DataType _sqlType )
protectedvirtual

Implements SQL::Param.

Definition at line 93 of file IBParam.cpp.

99{
100 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
101 if (!cancelBlob())
102 return false;
103 }
104
105 bool r = false;
106 switch(_valType) {
107 case SQL::typeInteger: {
108 r = setInteger(_val, _size);
109 break;
110 }
111 case SQL::typeUInteger: {
112 r = setUInteger(_val, _size);
113 break;
114 }
115 case SQL::typeFloat: {
116 r = setFloat(_val, _size);
117 break;
118 }
119 case SQL::typeDate: {
120 r = setDate((const SQL::Date*)_val, _size);
121 break;
122 }
123 case SQL::typeTime: {
124 r = setTime((const SQL::Time*)_val, _size);
125 break;
126 }
127 case SQL::typeTimeStamp: {
128 r = setTimeStamp((const SQL::TimeStamp*)_val, _size);
129 break;
130 }
131 case SQL::typeText:
132 case SQL::typeBinary: {
133 if (__SQLTYPE_IS(SQL_BLOB))
134 r = setBytesToBlob((const byte_t*)_val, _size);
135 else {
136 __sqlvar->sqldata = (char*)_val;
137 __sqlvar->sqllen = _size;
138 __sqlvar->sqltype = SQL_TEXT + 1;
139 r = true;
140 }
141 break;
142 }
144 if (__SQLTYPE_IS(SQL_BLOB))
145 r = setInputStreamToBlob((_CONST InputStream*)_val, _size);
146 else {
148 return false;
149 }
150 break;
151 }
152 // case SQL::typeInterval:
153 default: {
155 return false;
156 }
157 }
158
159 if (r) {
160 __indicator = 0;
161 Param::__dataType = _sqlType;
162 }
163
164 return r;
165}
unsigned char byte_t
Definition Config.h:246
#define _CONST
Definition Config.h:325
IOException *size_t r
Definition MediaInfo.cpp:82
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
bool setTimeStamp(const SQL::TimeStamp *_val, size_t _size)
Definition IBParam.cpp:300
bool setTime(const SQL::Time *_val, size_t _size)
Definition IBParam.cpp:271
bool setInputStreamToBlob(_CONST InputStream *_input, size_t _size)
Definition IBParam.cpp:384
bool setUInteger(const void *_val, size_t _size)
Definition IBParam.cpp:197
bool setInteger(const void *_val, size_t _size)
Definition IBParam.cpp:167
bool setFloat(const void *_val, size_t _size)
Definition IBParam.cpp:227
bool setBytesToBlob(const byte_t *_val, size_t _size)
Definition IBParam.cpp:337
bool setDate(const SQL::Date *_val, size_t _size)
Definition IBParam.cpp:251
@ typeBinary
Definition SQLCore.h:74
@ typeTime
Definition SQLCore.h:66
@ typeUInteger
Definition SQLCore.h:62
@ typeTimeStamp
Definition SQLCore.h:68
@ typeInputStream
Definition SQLCore.h:81
@ typeDate
Definition SQLCore.h:65
@ typeText
Definition SQLCore.h:73
@ typeFloat
Definition SQLCore.h:63
@ typeInteger
Definition SQLCore.h:61
@ eNotSupportDataType
Definition SQLCore.h:48
@ eInvalidDataType
Definition SQLCore.h:49

◆ cancelBlob()

bool IBParam::cancelBlob ( )
protected

Definition at line 456 of file IBParam.cpp.

457{
458// __DCL_ASSERT(__indicator == 0 && __SQLTYPE_IS(SQL_BLOB));
459 isc_blob_handle hBlob = NULL_HANDLE;
460
461 if(isc_open_blob2(
462 conn()->statusVector(),
463 conn()->dbHandlePtr(),
464 conn()->trHandlePtr(),
465 &hBlob,
466 &__data.blob_id,
467 0,
468 NULL
469 )) {
471 return false;
472 }
473
474 if (isc_cancel_blob(
475 conn()->statusVector(),
476 &hBlob
477 )) {
479 return false;
480 }
481
482 return true;
483}
#define NULL
Definition Config.h:312
#define NULL_HANDLE
IBConnection * conn() const
Definition IBParam.h:72
@ eServerError
Definition SQLCore.h:21

◆ conn()

IBConnection * IBParam::conn ( ) const
inlineprotected

Definition at line 72 of file IBParam.h.

73{
74 return query()->conn();
75}
IBQuery * query() const
Definition IBParam.h:67

◆ init()

bool IBParam::init ( SQL::Query * _query,
XSQLVAR * _sqlvar )

Definition at line 50 of file IBParam.cpp.

51{
52 __DCL_ASSERT(__sqlvar == NULL);
53
54 Param::__queryHandle = _queryHandle;
55
56 __indicator = -1;
57 __sqltype = _sqlvar->sqltype;
58
59 __sqlvar = _sqlvar;
60 __sqlvar->sqldata = NULL;
61 __sqlvar->sqlind = &__indicator;
62 __sqlvar->sqlscale = 0;
63
64 return true;
65}
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ onAfterExecute()

void IBParam::onAfterExecute ( )

Definition at line 67 of file IBParam.cpp.

68{
69 Param::__dataType = SQL::typeUnknown;
70 __indicator = -1; // set null
71 __sqlvar->sqldata = NULL;
72}
@ typeUnknown
Definition SQLCore.h:60

◆ query()

IBQuery * IBParam::query ( ) const
inlineprotected

Definition at line 67 of file IBParam.h.

68{
69 return (IBQuery*)Param::__queryHandle;
70}

◆ serverDataTypeName()

const wchar_t * IBParam::serverDataTypeName ( ) const
protectedvirtual

Implements SQL::Field.

Definition at line 77 of file IBParam.cpp.

78{
79 return __dataTypeName(__sqlvar);
80}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:304

◆ setBytesToBlob()

bool IBParam::setBytesToBlob ( const byte_t * _val,
size_t _size )
protected

Definition at line 337 of file IBParam.cpp.

338{
339 isc_blob_handle hBlob = NULL_HANDLE;
340 if(isc_create_blob2(
341 conn()->statusVector(),
342 conn()->dbHandlePtr(),
343 conn()->trHandlePtr(),
344 &hBlob,
345 &__data.blob_id,
346 0,
347 NULL
348 )) {
350 return false;
351 }
352
353 size_t nTotal = 0;
354 size_t nBytes = 0;
355 while(nTotal < _size) {
356 nBytes = __MIN(_size - nTotal, USHRT_MAX);
357 if (isc_put_segment(
358 conn()->statusVector(),
359 &hBlob,
360 nBytes,
361 (char*)_val
362 )) {
364 ISC_STATUS status2[ISC_STATUS_VECTOR_LENGTH];
365 isc_close_blob(status2, &hBlob);
366 return false;
367 }
368
369 nTotal += nBytes;
370 _val += nBytes;
371 }
372
373 if (isc_close_blob(conn()->statusVector(), &hBlob)) {
375 return false;
376 }
377
378 __sqlvar->sqldata = (char*)&__data.blob_id;
379 __sqlvar->sqllen = sizeof(ISC_QUAD);
380 __sqlvar->sqltype = SQL_BLOB + 1;
381 return true;
382}
#define ISC_STATUS_VECTOR_LENGTH
size_t __MIN(size_t x, size_t y)
Definition size_t.h:27

◆ setDate()

bool IBParam::setDate ( const SQL::Date * _val,
size_t _size )
protected

Definition at line 251 of file IBParam.cpp.

252{
253 if (_size != sizeof(SQL::Date)) {
255 return false;
256 }
257
258 struct tm tm;
259 tm.tm_year = _val->year - 1900;
260 tm.tm_mon = _val->month - 1;
261 tm.tm_mday = _val->day;
262
263 isc_encode_sql_date(&tm, &__data.date);
264
265 __sqlvar->sqldata = (char*)&__data;
266 __sqlvar->sqllen = sizeof(ISC_DATE);
267 __sqlvar->sqltype = SQL_TYPE_DATE + 1;
268 return true;
269}
@ eInvalidDataSize
Definition SQLCore.h:55
int16_t year
Definition SQLCore.h:96
uint8_t month
Definition SQLCore.h:97
uint8_t day
Definition SQLCore.h:98

◆ setFloat()

bool IBParam::setFloat ( const void * _val,
size_t _size )
protected

Definition at line 227 of file IBParam.cpp.

228{
229 switch(_size) {
230 case sizeof(float) : {
231 __data.f32 = *(float*)_val;
232 __sqlvar->sqllen = sizeof(float);
233 __sqlvar->sqltype = SQL_FLOAT + 1;
234 break;
235 }
236 case sizeof(double) : {
237 __data.f64 = *(double*)_val;
238 __sqlvar->sqllen = sizeof(double);
239 __sqlvar->sqltype = SQL_DOUBLE + 1;
240 break;
241 }
242 default: {
244 return false;
245 }
246 }
247 __sqlvar->sqldata = (char*)&__data;
248 return true;
249}

◆ setInputStreamToBlob()

bool IBParam::setInputStreamToBlob ( _CONST InputStream * _input,
size_t _size )
protected

Definition at line 384 of file IBParam.cpp.

385{
386 isc_blob_handle hBlob = NULL_HANDLE;
387 if(isc_create_blob2(
388 conn()->statusVector(),
389 conn()->dbHandlePtr(),
390 conn()->trHandlePtr(),
391 &hBlob,
392 &__data.blob_id,
393 0,
394 NULL
395 )) {
397 return false;
398 }
399
400 char* _pbuf = (char*)malloc(USHRT_MAX);
401 if (!_pbuf) {
403 ISC_STATUS status2[ISC_STATUS_VECTOR_LENGTH];
404 isc_close_blob(status2, &hBlob);
405 return false;
406 }
407
408 try {
409 size_t nTotal = 0;
410 size_t nBytes = 0;
411 for (; ; ) {
412 nBytes = __MIN(_size - nTotal, USHRT_MAX);
413 if (nBytes && (nBytes = _input->read(_pbuf, nBytes))) {
414 if (isc_put_segment(
415 conn()->statusVector(),
416 &hBlob,
417 nBytes,
418 _pbuf
419 )) {
421 free(_pbuf);
422 ISC_STATUS status2[ISC_STATUS_VECTOR_LENGTH];
423 isc_close_blob(status2, &hBlob);
424 return false;
425 }
426 nTotal += nBytes;
427 }
428 else {
429 // done
430 break;
431 }
432 }
433 }
434 catch (IOException* e) {
435 __SET_ERROR_MSG(UTF8Encoder::encode(e->toStringAll()));
436 e->destroy();
437 free(_pbuf);
438 ISC_STATUS status2[ISC_STATUS_VECTOR_LENGTH];
439 isc_close_blob(status2, &hBlob);
440 return false;
441 }
442
443 free(_pbuf);
444
445 if (isc_close_blob(conn()->statusVector(), &hBlob)) {
447 return false;
448 }
449
450 __sqlvar->sqldata = (char*)&__data.blob_id;
451 __sqlvar->sqllen = sizeof(ISC_QUAD);
452 __sqlvar->sqltype = SQL_BLOB + 1;
453 return true;
454}
#define __SET_ERROR_MSG(_message)
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
@ eOutOfMemory
Definition SQLCore.h:24

◆ setInteger()

bool IBParam::setInteger ( const void * _val,
size_t _size )
protected

Definition at line 167 of file IBParam.cpp.

168{
169 switch(_size) {
170 case sizeof(int16_t): {
171 __data.i16 = *(int16_t*)_val;
172 __sqlvar->sqllen = sizeof(int16_t);
173 __sqlvar->sqltype = SQL_SHORT + 1;
174 break;
175 }
176 case sizeof(int32_t): {
177 __data.i32 = *(int32_t*)_val;
178 __sqlvar->sqllen = sizeof(int32_t);
179 __sqlvar->sqltype = SQL_LONG + 1;
180 break;
181 }
182 case sizeof(int64_t): {
183 __data.i64 = *(int64_t*)_val;
184 __sqlvar->sqllen = sizeof(int64_t);
185 __sqlvar->sqltype = SQL_INT64 + 1;
186 break;
187 }
188 default: {
190 return false;
191 }
192 }
193 __sqlvar->sqldata = (char*)&__data;
194 return true;
195}

◆ setNull()

void IBParam::setNull ( )
protectedvirtual

Implements SQL::Param.

Definition at line 82 of file IBParam.cpp.

83{
84 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
86 }
87
88 Param::__dataType = SQL::typeUnknown;
89 __indicator = -1; // set null
90 __sqlvar->sqldata = NULL;
91}

◆ setTime()

bool IBParam::setTime ( const SQL::Time * _val,
size_t _size )
protected

Definition at line 271 of file IBParam.cpp.

272{
273 if (_size != sizeof(SQL::Time)) {
275 return false;
276 }
277
278 struct tm tm;
279 tm.tm_hour = _val->hour;
280 tm.tm_min = _val->min;
281 tm.tm_sec = _val->sec;
282
283 isc_encode_sql_time(&tm, &__data.time);
284 __data.time += _val->frac / 100000;
285
286 __sqlvar->sqldata = (char*)&__data;
287 __sqlvar->sqllen = sizeof(ISC_TIME);
288 __sqlvar->sqltype = SQL_TYPE_TIME + 1;
289#if defined(FIREBIRD_IBASE_H) && FB_API_VER >= 40
290 if (_val->tzoff != INT16_MIN) {
291 __data.time_tz.time_zone = 0;
292 __data.time_tz.ext_offset = _val->tzoff;
293 __sqlvar->sqllen = sizeof(ISC_TIME_TZ_EX);
294 __sqlvar->sqltype = SQL_TIME_TZ_EX + 1;
295 }
296#endif
297 return true;
298}
#define INT16_MIN
Definition Config.h:284
uint8_t hour
Definition SQLCore.h:103
uint8_t sec
Definition SQLCore.h:105
uint32_t frac
Definition SQLCore.h:106
uint8_t min
Definition SQLCore.h:104
int16_t tzoff
Definition SQLCore.h:107

◆ setTimeStamp()

bool IBParam::setTimeStamp ( const SQL::TimeStamp * _val,
size_t _size )
protected

Definition at line 300 of file IBParam.cpp.

301{
302 if (_size != sizeof(SQL::TimeStamp)) {
304 return false;
305 }
306
307 struct tm tm;
308 tm.tm_year = _val->year - 1900;
309 tm.tm_mon = _val->month - 1;
310 tm.tm_mday = _val->day;
311 tm.tm_hour = _val->hour;
312 tm.tm_min = _val->min;
313 tm.tm_sec = _val->sec;
314
315 isc_encode_timestamp(&tm, &__data.ts);
316 __data.ts.timestamp_time += _val->frac / 100000;
317
318 __sqlvar->sqldata = (char*)&__data;
319 __sqlvar->sqllen = sizeof(ISC_TIMESTAMP);
320 __sqlvar->sqltype = SQL_TIMESTAMP + 1;
321#if defined(FIREBIRD_IBASE_H) && FB_API_VER >= 40
322 if (_val->tzoff != INT16_MIN) {
323 __data.ts_tz.time_zone = 0;
324 __data.ts_tz.ext_offset = _val->tzoff;
325 __sqlvar->sqllen = sizeof(ISC_TIMESTAMP_TZ_EX);
326 __sqlvar->sqltype = SQL_TIMESTAMP_TZ_EX + 1;
327 }
328#endif
329 return true;
330}
uint32_t frac
Definition SQLCore.h:118
int16_t tzoff
Definition SQLCore.h:119
uint8_t min
Definition SQLCore.h:116
uint8_t sec
Definition SQLCore.h:117
uint8_t hour
Definition SQLCore.h:115
uint8_t day
Definition SQLCore.h:114
int16_t year
Definition SQLCore.h:112
uint8_t month
Definition SQLCore.h:113

◆ setUInteger()

bool IBParam::setUInteger ( const void * _val,
size_t _size )
protected

Definition at line 197 of file IBParam.cpp.

198{
199 switch(_size) {
200 case sizeof(uint16_t): {
201 __data.i16 = (int16_t) * (uint16_t*)_val;
202 __sqlvar->sqllen = sizeof(int16_t);
203 __sqlvar->sqltype = SQL_SHORT + 1;
204 break;
205 }
206 case sizeof(uint32_t): {
207 __data.i32 = (int32_t) * (uint32_t*)_val;
208 __sqlvar->sqllen = sizeof(int32_t);
209 __sqlvar->sqltype = SQL_LONG + 1;
210 break;
211 }
212 case sizeof(uint64_t) : {
213 __data.i64 = (int64_t) * (uint64_t*)_val;
214 __sqlvar->sqllen = sizeof(int64_t);
215 __sqlvar->sqltype = SQL_INT64 + 1;
216 break;
217 }
218 default: {
220 return false;
221 }
222 }
223 __sqlvar->sqldata = (char*)&__data;
224 return true;
225}

Member Data Documentation

◆ blob_id

ISC_QUAD IBParam::blob_id

Definition at line 28 of file IBParam.h.

◆ date

ISC_DATE IBParam::date

Definition at line 21 of file IBParam.h.

◆ f32

float IBParam::f32

Definition at line 19 of file IBParam.h.

◆ f64

double IBParam::f64

Definition at line 20 of file IBParam.h.

◆ i16

int16_t IBParam::i16

Definition at line 16 of file IBParam.h.

◆ i32

int32_t IBParam::i32

Definition at line 17 of file IBParam.h.

◆ i64

int64_t IBParam::i64

Definition at line 18 of file IBParam.h.

◆ time

ISC_TIME IBParam::time

Definition at line 22 of file IBParam.h.

◆ ts

ISC_TIMESTAMP IBParam::ts

Definition at line 23 of file IBParam.h.


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