DCL 4.0
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

void setErrorStatus (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorStatus (const ByteString &_message, const wchar_t *_filename, int _line)
IBQueryquery () const
virtual const wchar_t * serverDataTypeName () const
virtual void setNull ()
virtual bool __setData (_CONST void *_pv, size_t _size, SQL::DataType _dataType, SQL::DataType _assignType)
bool setInteger (const void *_pv, size_t _size)
bool setUInteger (const void *_pv, size_t _size)
bool setFloat (const void *_pv, size_t _size)
bool setDate (const SQL::Date *p, size_t _size)
bool setTime (const SQL::Time *p, size_t _size)
bool setTimeStamp (const SQL::TimeStamp *p, size_t _size)
bool setBytesToBlob (const byte_t *p, size_t _size)
bool setInputStreamToBlob (_CONST InputStream *pInput, size_t _size)
bool cancelBlob ()
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 IBParam.h.

Constructor & Destructor Documentation

◆ IBParam()

IBParam::IBParam ( )

◆ ~IBParam()

IBParam::~IBParam ( )
virtual

Definition at line 38 of file IBParam.cpp.

39{
40 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
42 }
43}
#define __SQLTYPE_IS(_sqltype)
Definition IFXField.cpp:61
#define __DCL_VERIFY(expr)
Definition Object.h:373
bool cancelBlob()
Definition IBParam.cpp:446

Member Function Documentation

◆ __setData()

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

Implements SQL::Param.

Definition at line 88 of file IBParam.cpp.

94{
95 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
96 if (!cancelBlob())
97 return false;
98 }
99
100 bool r = false;
101 switch(_dataType) {
102 case SQL::typeInteger: {
103 r = setInteger(_pv, _size);
104 break;
105 }
106 case SQL::typeUInteger: {
107 r = setUInteger(_pv, _size);
108 break;
109 }
110 case SQL::typeFloat: {
111 r = setFloat(_pv, _size);
112 break;
113 }
114 case SQL::typeDate: {
115 r = setDate((const SQL::Date*)_pv, _size);
116 break;
117 }
118 case SQL::typeTime: {
119 r = setTime((const SQL::Time*)_pv, _size);
120 break;
121 }
122 case SQL::typeTimeStamp: {
123 r = setTimeStamp((const SQL::TimeStamp*)_pv, _size);
124 break;
125 }
126 case SQL::typeText :
127 case SQL::typeBinary :
128 case SQL::typeLongText :
129 case SQL::typeLongBinary: {
130 if (__SQLTYPE_IS(SQL_BLOB))
131 r = setBytesToBlob((const byte_t*)_pv, _size);
132 else {
133 __sqlvar->sqldata = (char*)_pv;
134 __sqlvar->sqllen = _size;
135 __sqlvar->sqltype = SQL_TEXT + 1;
136 r = true;
137 }
138 break;
139 }
141 if (__SQLTYPE_IS(SQL_BLOB))
142 r = setInputStreamToBlob((_CONST InputStream*)_pv, _size);
143 else {
145 return false;
146 }
147 break;
148 }
149 // case SQL::typeTimeStampTz :
150 // case SQL::typeInterva
151 // case SQL::typeIntervalYm :
152 // case SQL::typeIntervalDs :
153 default: {
155 return false;
156 }
157 }
158
159 if (r) {
160 __indicator = 0;
161 Param::__dataType = _dataType;
162 }
163
164 return r;
165}
unsigned char byte_t
Definition Config.h:274
#define _CONST
Definition Config.h:353
ByteString r
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:150
bool setBytesToBlob(const byte_t *p, size_t _size)
Definition IBParam.cpp:321
bool setTimeStamp(const SQL::TimeStamp *p, size_t _size)
Definition IBParam.cpp:292
bool setFloat(const void *_pv, size_t _size)
Definition IBParam.cpp:227
bool setUInteger(const void *_pv, size_t _size)
Definition IBParam.cpp:197
bool setDate(const SQL::Date *p, size_t _size)
Definition IBParam.cpp:251
bool setTime(const SQL::Time *p, size_t _size)
Definition IBParam.cpp:271
bool setInputStreamToBlob(_CONST InputStream *pInput, size_t _size)
Definition IBParam.cpp:370
bool setInteger(const void *_pv, size_t _size)
Definition IBParam.cpp:167
@ typeBinary
Definition SQLCore.h:76
@ typeTime
Definition SQLCore.h:69
@ typeLongBinary
Definition SQLCore.h:78
@ typeUInteger
Definition SQLCore.h:65
@ typeTimeStamp
Definition SQLCore.h:70
@ typeInputStream
Definition SQLCore.h:83
@ typeDate
Definition SQLCore.h:68
@ typeText
Definition SQLCore.h:75
@ typeFloat
Definition SQLCore.h:66
@ typeInteger
Definition SQLCore.h:64
@ typeLongText
Definition SQLCore.h:77
@ eNotSupportDataType
Definition SQLCore.h:48
@ eInvalidDataType
Definition SQLCore.h:49

◆ cancelBlob()

bool IBParam::cancelBlob ( )
protected

Definition at line 446 of file IBParam.cpp.

447{
448// __DCL_ASSERT(__indicator == 0 && __SQLTYPE_IS(SQL_BLOB));
449
450 IBConnection* connHandle = (IBConnection*)Param::connection();
451 ISC_STATUS* statusVector = connHandle->statusVector();
452 isc_blob_handle hBlob = NULL;
453
454 if(isc_open_blob2(
455 statusVector,
456 connHandle->dbHandlePtr(),
457 connHandle->trHandlePtr(),
458 &hBlob,
459 &__data.blob_id,
460 0,
461 NULL)) {
463 return false;
464 }
465
466 if (isc_cancel_blob(
467 statusVector,
468 &hBlob
469 )) {
471 return false;
472 }
473
474 return true;
475}
#define NULL
Definition Config.h:340
isc_tr_handle * trHandlePtr()
ISC_STATUS * statusVector()
isc_db_handle * dbHandlePtr()
@ eServerError
Definition SQLCore.h:21

◆ init()

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

Definition at line 45 of file IBParam.cpp.

46{
47 __DCL_ASSERT(__sqlvar == NULL);
48
49 Param::__queryHandle = _queryHandle;
50
51 __indicator = -1;
52 __sqltype = _sqlvar->sqltype;
53
54 __sqlvar = _sqlvar;
55 __sqlvar->sqldata = NULL;
56 __sqlvar->sqlind = &__indicator;
57 __sqlvar->sqlscale = 0;
58
59 return true;
60}
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ onAfterExecute()

void IBParam::onAfterExecute ( )

Definition at line 62 of file IBParam.cpp.

63{
64 Param::__dataType = SQL::typeUnknown;
65 __indicator = -1; // set null
66 __sqlvar->sqldata = NULL;
67}
@ typeUnknown
Definition SQLCore.h:63

◆ query()

IBQuery * IBParam::query ( ) const
inlineprotected

Definition at line 81 of file IBParam.h.

82{
83 return (IBQuery*)Param::__queryHandle;
84}

◆ serverDataTypeName()

const wchar_t * IBParam::serverDataTypeName ( ) const
protectedvirtual

Implements SQL::Field.

Definition at line 72 of file IBParam.cpp.

73{
74 return __dataTypeName(__sqlvar);
75}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:290

◆ setBytesToBlob()

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

Definition at line 321 of file IBParam.cpp.

322{
323 IBConnection* connHandle = (IBConnection*)Param::connection();
324 ISC_STATUS* statusVector = connHandle->statusVector();
325 isc_blob_handle hBlob = NULL;
326
327 if(isc_create_blob2(
328 statusVector,
329 connHandle->dbHandlePtr(),
330 connHandle->trHandlePtr(),
331 &hBlob,
332 &__data.blob_id,
333 0,
334 NULL)) {
336 return false;
337 }
338
339 size_t nTotal = 0;
340 size_t nBytes = 0;
341 while(nTotal < _size) {
342 nBytes = __MIN(_size - nTotal, USHRT_MAX);
343 if (isc_put_segment(
344 statusVector,
345 &hBlob,
346 nBytes,
347 (char*)p
348 )) {
350 ISC_STATUS statusVector[ISC_STATUS_VECTOR_LENGTH];
351 isc_close_blob(statusVector, &hBlob);
352 return false;
353 }
354
355 nTotal += nBytes;
356 p += nBytes;
357 }
358
359 if (isc_close_blob(statusVector, &hBlob)) {
361 return false;
362 }
363
364 __sqlvar->sqldata = (char*)&__data.blob_id;
365 __sqlvar->sqllen = sizeof(ISC_QUAD);
366 __sqlvar->sqltype = SQL_BLOB + 1;
367 return true;
368}
#define ISC_STATUS_VECTOR_LENGTH
Definition IBConnection.h:6
size_t __MIN(size_t x, size_t y)
Definition size_t.h:27

◆ setDate()

bool IBParam::setDate ( const SQL::Date * p,
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 = p->nYear - 1900;
260 tm.tm_mon = p->nMonth - 1;
261 tm.tm_mday = p->nDay;
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:57
uint8_t nMonth
Definition SQLCore.h:97
int16_t nYear
Definition SQLCore.h:96
uint8_t nDay
Definition SQLCore.h:98

◆ setErrorStatus() [1/2]

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

Definition at line 74 of file IBParam.h.

76{
77 ((IBConnection*)Param::connection())
78 ->setErrorStatus(_message, _filename, _line);
79}

◆ setErrorStatus() [2/2]

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

Definition at line 67 of file IBParam.h.

69{
70 ((IBConnection*)Param::connection())
71 ->setErrorStatus(_error, _filename, _line);
72}

◆ setFloat()

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

Definition at line 227 of file IBParam.cpp.

228{
229 switch(_size) {
230 case sizeof(float) : {
231 __data.f32 = *(float*)_pv;
232 __sqlvar->sqllen = sizeof(float);
233 __sqlvar->sqltype = SQL_FLOAT + 1;
234 break;
235 }
236 case sizeof(double) : {
237 __data.f64 = *(double*)_pv;
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 * pInput,
size_t _size )
protected

Definition at line 370 of file IBParam.cpp.

372{
373 IBConnection* connHandle = (IBConnection*)Param::connection();
374 ISC_STATUS* statusVector = connHandle->statusVector();
375 isc_blob_handle hBlob = NULL;
376
377 if(isc_create_blob2(
378 statusVector,
379 connHandle->dbHandlePtr(),
380 connHandle->trHandlePtr(),
381 &hBlob,
382 &__data.blob_id,
383 0,
384 NULL)) {
386 return false;
387 }
388
389 char* _pbuf = (char*)malloc(USHRT_MAX);
390 if (!_pbuf) {
392 ISC_STATUS statusVector[ISC_STATUS_VECTOR_LENGTH];
393 isc_close_blob(statusVector, &hBlob);
394 return false;
395 }
396
397 try {
398 size_t nTotal = 0;
399 size_t nBytes = 0;
400 for (; ; ) {
401 nBytes = __MIN(_size - nTotal, USHRT_MAX);
402 if (nBytes && (nBytes = pInput->read(_pbuf, nBytes))) {
403 if (isc_put_segment(
404 statusVector,
405 &hBlob,
406 nBytes,
407 _pbuf
408 )) {
410 free(_pbuf);
411 ISC_STATUS statusVector[ISC_STATUS_VECTOR_LENGTH];
412 isc_close_blob(statusVector, &hBlob);
413 return false;
414 }
415
416 nTotal += nBytes;
417 }
418 else {
419 // done
420 break;
421 }
422 }
423 }
424 catch (IOException* e) {
425 __SET_ERROR_MSG(UTF8Encoder::encode(e->toStringAll()));
426 e->destroy();
427 free(_pbuf);
428 ISC_STATUS statusVector[ISC_STATUS_VECTOR_LENGTH];
429 isc_close_blob(statusVector, &hBlob);
430 return false;
431 }
432
433 free(_pbuf);
434
435 if (isc_close_blob(statusVector, &hBlob)) {
437 return false;
438 }
439
440 __sqlvar->sqldata = (char*)&__data.blob_id;
441 __sqlvar->sqllen = sizeof(ISC_QUAD);
442 __sqlvar->sqltype = SQL_BLOB + 1;
443 return true;
444}
#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 * _pv,
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*)_pv;
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*)_pv;
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*)_pv;
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 77 of file IBParam.cpp.

78{
79 if (__indicator == 0 && __SQLTYPE_IS(SQL_BLOB)) {
81 }
82
83 Param::__dataType = SQL::typeUnknown;
84 __indicator = -1; // set null
85 __sqlvar->sqldata = NULL;
86}

◆ setTime()

bool IBParam::setTime ( const SQL::Time * p,
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 = p->nHour;
280 tm.tm_min = p->nMin;
281 tm.tm_sec = p->nSec;
282
283 isc_encode_sql_time(&tm, &__data.time);
284 __data.time += p->nFrac / 100000;
285
286 __sqlvar->sqldata = (char*)&__data;
287 __sqlvar->sqllen = sizeof(ISC_TIME);
288 __sqlvar->sqltype = SQL_TYPE_TIME + 1;
289 return true;
290}
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

◆ setTimeStamp()

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

Definition at line 292 of file IBParam.cpp.

293{
294 if (_size != sizeof(SQL::TimeStamp)) {
296 return false;
297 }
298
299 struct tm tm;
300 tm.tm_year = p->nYear - 1900;
301 tm.tm_mon = p->nMonth - 1;
302 tm.tm_mday = p->nDay;
303 tm.tm_hour = p->nHour;
304 tm.tm_min = p->nMin;
305 tm.tm_sec = p->nSec;
306
307 isc_encode_timestamp(&tm, &__data.ts);
308 __data.ts.timestamp_time += p->nFrac / 100000;
309
310 __sqlvar->sqldata = (char*)&__data;
311 __sqlvar->sqllen = sizeof(ISC_TIMESTAMP);
312 __sqlvar->sqltype = SQL_TIMESTAMP + 1;
313 return true;
314}
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

◆ setUInteger()

bool IBParam::setUInteger ( const void * _pv,
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*)_pv;
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*)_pv;
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*)_pv;
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 24 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: