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

#include <SqParam.h>

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

Public Member Functions

bool init (SQL::Query *_query, int _number, const char *_name)
bool onBeforeExecute ()
bool onAfterExecute ()
 SqParam ()
virtual ~SqParam ()
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 setInterval (const SQL::Interval *_val, size_t _size)
bool setBytes (_CONST void *_val, size_t _size, SQL::DataType _valType, SQL::DataType _sqlType)
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

SqQueryquery () const
SqConnectionconn () const
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 6 of file SqParam.h.

Constructor & Destructor Documentation

◆ SqParam()

SqParam::SqParam ( )

◆ ~SqParam()

SqParam::~SqParam ( )
virtual

Definition at line 54 of file SqParam.cpp.

55{
56}

Member Function Documentation

◆ __setData()

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

Implements SQL::Param.

Definition at line 130 of file SqParam.cpp.

136{
137 bool r = false;
138 switch(_valType) {
139 case SQL::typeInteger:
140 r = setInteger(_val, _size);
141 break;
143 r = setUInteger(_val, _size);
144 break;
145 case SQL::typeFloat:
146 r = setFloat(_val, _size);
147 break;
148 case SQL::typeDate:
149 r = setDate((const SQL::Date*)_val, _size);
150 break;
151 case SQL::typeTime:
152 r = setTime((const SQL::Time*)_val, _size);
153 break;
155 r = setTimeStamp((const SQL::TimeStamp*)_val, _size);
156 break;
158 r = setInterval((const SQL::Interval*)_val, _size);
159 break;
160 case SQL::typeText:
161 case SQL::typeBinary:
163 r = setBytes(_val, _size, _valType, _sqlType);
164 break;
165 default: {
167 return false;
168 }
169 }
170
171 if (r) {
172 Param::__dataType = _sqlType;
173 }
174 return r;
175}
IOException *size_t r
Definition MediaInfo.cpp:82
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
@ 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
@ typeInterval
Definition SQLCore.h:70
@ 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
bool setUInteger(const void *_val, size_t _size)
Definition SqParam.cpp:206
bool setDate(const SQL::Date *_val, size_t _size)
Definition SqParam.cpp:256
bool setFloat(const void *_val, size_t _size)
Definition SqParam.cpp:235
bool setTime(const SQL::Time *_val, size_t _size)
Definition SqParam.cpp:283
bool setBytes(_CONST void *_val, size_t _size, SQL::DataType _valType, SQL::DataType _sqlType)
Definition SqParam.cpp:405
bool setInteger(const void *_val, size_t _size)
Definition SqParam.cpp:177
bool setTimeStamp(const SQL::TimeStamp *_val, size_t _size)
Definition SqParam.cpp:319
bool setInterval(const SQL::Interval *_val, size_t _size)
Definition SqParam.cpp:366

◆ conn()

SqConnection * SqParam::conn ( ) const
inlineprotected

Definition at line 67 of file SqParam.h.

68{
69 return query()->conn();
70}
SqQuery * query() const
Definition SqParam.h:62

◆ init()

bool SqParam::init ( SQL::Query * _query,
int _number,
const char * _name )

Definition at line 58 of file SqParam.cpp.

59{
60 __DCL_ASSERT(Param::__queryHandle == NULL);
61 __DCL_ASSERT(_queryHandle != NULL);
62
63 Param::__queryHandle = _queryHandle;
64
65 __number = _number;
66 __name.assign(_name);
67
68 return true;
69}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ onAfterExecute()

bool SqParam::onAfterExecute ( )

Definition at line 107 of file SqParam.cpp.

108{
109 setNull();
110 return true;
111}
virtual void setNull()
Definition SqParam.cpp:118

◆ onBeforeExecute()

bool SqParam::onBeforeExecute ( )

Definition at line 71 of file SqParam.cpp.

72{
73 int rc = SQLITE_OK;
74 switch (__type) {
75 case SQLITE_INTEGER: {
76 rc = sqlite3_bind_int64(query()->stmt(), __number, __data.n);
77 break;
78 }
79 case SQLITE_FLOAT: {
80 rc = sqlite3_bind_double(query()->stmt(), __number, __data.d);
81 break;
82 }
83 case SQLITE_TEXT: {
84 rc = sqlite3_bind_text64(query()->stmt(), __number, (const char*)__data.p,
85 __size, NULL, SQLITE_UTF8);
86 break;
87 }
88 case SQLITE_BLOB: {
89 rc = sqlite3_bind_blob(query()->stmt(), __number, __data.p, (int)__size, NULL);
90 break;
91 }
92 case SQLITE_NULL:
93 default: {
94 rc = sqlite3_bind_null(query()->stmt(), __number);
95 }
96 }
97
98 if (rc != SQLITE_OK) {
99 ByteStringBuilder sb = sqlite3_errmsg(conn()->connHandle());
100 sb.append(' ').append(__name);
101 __SET_ERROR_MSG(sb.toByteString());
102 return false;
103 }
104
105 return true;
106}
#define __SET_ERROR_MSG(_message)
SqConnection * conn() const
Definition SqParam.h:67

◆ query()

SqQuery * SqParam::query ( ) const
inlineprotected

Definition at line 62 of file SqParam.h.

63{
64 return (SqQuery*)Param::__queryHandle;
65}

◆ serverDataTypeName()

const wchar_t * SqParam::serverDataTypeName ( ) const
virtual

Implements SQL::Field.

Definition at line 113 of file SqParam.cpp.

114{
115 return __dataTypeName(__type);
116}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:304

◆ setBytes()

bool SqParam::setBytes ( _CONST void * _val,
size_t _size,
SQL::DataType _valType,
SQL::DataType _sqlType )

Definition at line 405 of file SqParam.cpp.

411{
412 const char* val = (const char*)_val;
413 size_t size = _size;
414 SQL::DataType valType = _valType;
415 if (_valType == SQL::typeInputStream) {
416 try {
417 __bytes = Files::readBytes(*(InputStream*)_val, _size);
418 val = __bytes;
419 size = __bytes.length();
420 }
421 catch (IOException* _e) {
422 __SET_ERROR_MSG(UTF8Encoder::encode(_e->toStringAll()));
423 _e->destroy();
424 return false;
425 }
426 if (_sqlType == SQL::typeText
427 || _sqlType == SQL::typeLongText
428 || _sqlType == SQL::typeClob) {
429 valType = SQL::typeText;
430 }
431 else {
432 valType = SQL::typeBinary;
433 }
434 }
435
436 __data.p = (const void*)val;
437 __size = size;
438
439 __type = valType == SQL::typeText ? SQLITE_TEXT : SQLITE_BLOB;
440 return true;
441}
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
static ByteString readBytes(InputStream &_input, size_t _n=(size_t) -1) __DCL_THROWS1(IOException *)
Definition Files.cpp:397
DataType
Definition SQLCore.h:59
@ typeClob
Definition SQLCore.h:77
@ typeLongText
Definition SQLCore.h:75

◆ setDate()

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

Definition at line 256 of file SqParam.cpp.

257{
258 if (_size != sizeof(SQL::Date)) {
260 return false;
261 }
262
263 const SQL::Date* val = (const SQL::Date*)_val;
264 ByteStringBuilder sb;
265 sb.format(
266 "%04d-%02d-%02d",
267 __ABS(val->year),
268 val->month,
269 val->day
270 );
271 if (val->year < 0) {
272 sb += " BC";
273 }
274 __bytes = sb.toByteString();
275
276 __data.p = (void*) __bytes.data();
277 __size = __bytes.length();
278
279 __type = SQLITE_TEXT;
280 return true;
281}
#define __ABS(n)
Definition MyParam.cpp:145
@ 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 SqParam::setFloat ( const void * _val,
size_t _size )

Definition at line 235 of file SqParam.cpp.

236{
237 switch (_size) {
238 case sizeof(float) : {
239 __data.d = *(float*)_val;
240 break;
241 }
242 case sizeof(double) : {
243 __data.d = *(double*)_val;
244 break;
245 }
246 default: {
248 return false;
249 }
250 }
251
252 __type = SQLITE_FLOAT;
253 return true;
254}

◆ setInteger()

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

Definition at line 177 of file SqParam.cpp.

178{
179 switch (_size) {
180 case sizeof(int8_t) : {
181 __data.n = *(int8_t*)_val;
182 break;
183 }
184 case sizeof(int16_t) : {
185 __data.n = *(int16_t*)_val;
186 break;
187 }
188 case sizeof(int32_t) : {
189 __data.n = *(int32_t*)_val;
190 break;
191 }
192 case sizeof(int64_t) : {
193 __data.n = *(int64_t*)_val;
194 break;
195 }
196 default: {
198 return false;
199 }
200 }
201
202 __type = SQLITE_INTEGER;
203 return true;
204}

◆ setInterval()

bool SqParam::setInterval ( const SQL::Interval * _val,
size_t _size )

Definition at line 366 of file SqParam.cpp.

367{
368 if (_size != sizeof(SQL::Interval)) {
370 return false;
371 }
372
373 const SQL::Interval* val = (const SQL::Interval*)_val;
374 if (val->secs || val->fracs >= 0) {
375 __bytes = ByteString::format(
376 "P%dY%dM%dDT%dH%dM%d.%dS",
377 val->years,
378 val->months,
379 val->days,
380 val->hours,
381 val->mins,
382 val->secs,
383 __ABS(val->fracs)
384 );
385 }
386 else {
387 __bytes = ByteString::format(
388 "P%dY%dM%dDT%dH%dM%-0.%dS",
389 val->years,
390 val->months,
391 val->days,
392 val->hours,
393 val->mins,
394 __ABS(val->fracs)
395 );
396 }
397
398 __data.p = (void*)__bytes.data();
399 __size = __bytes.length();
400
401 __type = SQLITE_TEXT;
402 return true;
403}
int32_t years
Definition SQLCore.h:126
int32_t days
Definition SQLCore.h:128
int8_t hours
Definition SQLCore.h:129
int8_t mins
Definition SQLCore.h:130
int32_t fracs
Definition SQLCore.h:132
int8_t months
Definition SQLCore.h:127
int8_t secs
Definition SQLCore.h:131

◆ setNull()

void SqParam::setNull ( )
virtual

Implements SQL::Param.

Definition at line 118 of file SqParam.cpp.

119{
120 Param::__dataType = SQL::typeUnknown;
121 __type = SQLITE_NULL;
122
123}
@ typeUnknown
Definition SQLCore.h:60

◆ setTime()

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

Definition at line 283 of file SqParam.cpp.

284{
285 if (_size != sizeof(SQL::Time)) {
287 return false;
288 }
289
290 const SQL::Time* val = (const SQL::Time*)_val;
291 if (val->tzoff == INT16_MIN) {
292 __bytes = ByteString::format(
293 "%02d:%02d:%02d.%06d",
294 val->hour,
295 val->min,
296 val->sec,
297 val->frac / 1000
298 );
299 }
300 else {
301 __bytes = ByteString::format(
302 "%02d:%02d:%02d.%06d %+03d:%02d",
303 val->hour,
304 val->min,
305 val->sec,
306 val->frac / 1000,
307 val->tzoff / 60,
308 __ABS(val->tzoff % 60)
309 );
310 }
311
312 __data.p = (void*)__bytes.data();
313 __size = __bytes.length();
314
315 __type = SQLITE_TEXT;
316 return true;
317}
#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 SqParam::setTimeStamp ( const SQL::TimeStamp * _val,
size_t _size )

Definition at line 319 of file SqParam.cpp.

320{
321 if (_size != sizeof(SQL::TimeStamp)) {
323 return false;
324 }
325
326 const SQL::TimeStamp* val = (const SQL::TimeStamp*)_val;
327 ByteStringBuilder sb;
328 if (val->tzoff == INT16_MIN) {
329 sb.format(
330 "%04d-%02d-%02d %02d:%02d:%02d.%06d",
331 __ABS(val->year),
332 val->month,
333 val->day,
334 val->hour,
335 val->min,
336 val->sec,
337 val->frac / 1000
338 );
339 }
340 else {
341 sb.format(
342 "%04d-%02d-%02d %02d:%02d:%02d.%06d %+03d:%02d",
343 __ABS(val->year),
344 val->month,
345 val->day,
346 val->hour,
347 val->min,
348 val->sec,
349 val->frac / 1000,
350 val->tzoff / 60,
351 __ABS(val->tzoff % 60)
352 );
353 }
354 if (val->year < 0) {
355 sb += " BC";
356 }
357 __bytes = sb.toByteString();
358
359 __data.p = (void*)__bytes.data();
360 __size = __bytes.length();
361
362 __type = SQLITE_TEXT;
363 return true;
364}
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 SqParam::setUInteger ( const void * _val,
size_t _size )

Definition at line 206 of file SqParam.cpp.

207{
208 switch (_size) {
209 case sizeof(uint8_t) : {
210 __data.n = *(uint8_t*)_val;
211 break;
212 }
213 case sizeof(uint16_t) : {
214 __data.n = *(uint16_t*)_val;
215 break;
216 }
217 case sizeof(uint32_t) : {
218 __data.n = *(uint32_t*)_val;
219 break;
220 }
221 case sizeof(uint64_t) : {
222 __data.n = *(uint64_t*)_val;
223 break;
224 }
225 default: {
227 return false;
228 }
229 }
230
231 __type = SQLITE_INTEGER;
232 return true;
233}

Member Data Documentation

◆ d

double SqParam::d

Definition at line 16 of file SqParam.h.

◆ n

int64_t SqParam::n

Definition at line 15 of file SqParam.h.

◆ p

const void* SqParam::p

Definition at line 17 of file SqParam.h.


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