DCL 4.0
Loading...
Searching...
No Matches
IFXTypes.cpp File Reference
#include <dcl/Config.h>
#include <sqlhdr.h>
#include <sqliapi.h>
#include <stdio.h>
#include <string.h>
#include <dcl/Object.h>
#include <dcl/SQLCore.h>
#include "IFXTypes_.h"

Go to the source code of this file.

Macros

#define __GET_UNIT_VALUE(TU_VAR, TU_NAME, TU_EXP)
#define MIN_PER_DAY   1440
#define SEC_PER_DAY   86400
#define SEC_PER_HOUR   3600

Functions

__DCL_BEGIN_NAMESPACE size_t __get_dec_strlen (const dec_t *p)
void __decode_intrvl (const intrvl_t *_s, SQL::Interval *_r)
void __decode_dtime (const dtime_t *_s, SQL::TimeStamp *_r)
void __decode_dtime (const dtime_t *_s, SQL::Date *_r)
void __decode_dtime (const dtime_t *_s, SQL::Time *_r)
int __encode_dtime (const SQL::TimeStamp *_s, dtime_t *_r)
int __encode_dtime (const SQL::Date *_s, dtime_t *_r)
int __encode_dtime (const SQL::Time *_s, dtime_t *_r)
int __ABS (int n)
int __encode_intrvl (const SQL::Interval *_s, SQL::DataType _dataType, intrvl_t *_r)

Macro Definition Documentation

◆ __GET_UNIT_VALUE

#define __GET_UNIT_VALUE ( TU_VAR,
TU_NAME,
TU_EXP )
Value:
if (_s->in_dec.dec_exp >= TU_EXP) \
{ \
if (TU_START(_s->in_qual) == TU_NAME) \
{ \
int n = _s->in_dec.dec_exp - (TU_EXP - 1); \
while(n-- > 0) \
{ \
TU_VAR *= 100; \
if (ndgts > 0) \
{ \
TU_VAR += *p++; \
ndgts--; \
} \
} \
} \
else \
{ \
TU_VAR += *p++; \
ndgts--; \
} \
} \
if (TU_END(_s->in_qual) == TU_NAME || ndgts == 0) \
break;
void CharsetConvertException *size_t n
Definition SQLField.cpp:253

Definition at line 93 of file IFXTypes.cpp.

93#define __GET_UNIT_VALUE(TU_VAR, TU_NAME, TU_EXP) \
94 if (_s->in_dec.dec_exp >= TU_EXP) \
95 { \
96 if (TU_START(_s->in_qual) == TU_NAME) \
97 { \
98 int n = _s->in_dec.dec_exp - (TU_EXP - 1); \
99 while(n-- > 0) \
100 { \
101 TU_VAR *= 100; \
102 if (ndgts > 0) \
103 { \
104 TU_VAR += *p++; \
105 ndgts--; \
106 } \
107 } \
108 } \
109 else \
110 { \
111 TU_VAR += *p++; \
112 ndgts--; \
113 } \
114 } \
115 if (TU_END(_s->in_qual) == TU_NAME || ndgts == 0) \
116 break;

◆ MIN_PER_DAY

#define MIN_PER_DAY   1440

◆ SEC_PER_DAY

#define SEC_PER_DAY   86400

◆ SEC_PER_HOUR

#define SEC_PER_HOUR   3600

Function Documentation

◆ __ABS()

int __ABS ( int n)
inline

Definition at line 394 of file IFXTypes.cpp.

395{
396 return n < 0 ? -n : n;
397}

◆ __decode_dtime() [1/3]

void __decode_dtime ( const dtime_t * _s,
SQL::Date * _r )

Definition at line 313 of file IFXTypes.cpp.

314{
316 __decode_dtime(_s, &t);
317 _r->nYear = t.nYear;
318 _r->nMonth = t.nMonth;
319 _r->nDay = t.nDay;
320}
void __decode_dtime(const dtime_t *_s, SQL::TimeStamp *_r)
Definition IFXTypes.cpp:221
_r
Definition SQLField.cpp:260
int16_t nYear
Definition SQLCore.h:111
uint8_t nDay
Definition SQLCore.h:113
uint8_t nMonth
Definition SQLCore.h:112

◆ __decode_dtime() [2/3]

void __decode_dtime ( const dtime_t * _s,
SQL::Time * _r )

Definition at line 322 of file IFXTypes.cpp.

323{
325 __decode_dtime(_s, &t);
326 _r->nHour = t.nHour;
327 _r->nMin = t.nMin;
328 _r->nSec = t.nSec;
329 _r->nFrac = t.nFrac;
330}
uint8_t nHour
Definition SQLCore.h:114
uint8_t nSec
Definition SQLCore.h:116
uint8_t nMin
Definition SQLCore.h:115
uint32_t nFrac
Definition SQLCore.h:117

◆ __decode_dtime() [3/3]

void __decode_dtime ( const dtime_t * _s,
SQL::TimeStamp * _r )

Definition at line 221 of file IFXTypes.cpp.

222{
223 // assert(0 <= _s->dt_dec.dec_exp && _s->dt_dec.dec_exp <= 7)
224 // assert(_s->dt_dec.dec_ndgts > 0)
225 __DCL_ASSERT(0 <= _s->dt_dec.dec_exp && _s->dt_dec.dec_exp <= 7);
226 __DCL_ASSERT(_s->dt_dec.dec_ndgts > 0);
227
228 int nYear, nMonth, nDay, nHour, nMin, nSec, nFSec;
229 nYear = nMonth = nDay = nHour = nMin = nSec = nFSec = 0;
230
231 const char* p = _s->dt_dec.dec_dgts;
232 int ndgts = _s->dt_dec.dec_ndgts;
233 switch(TU_START(_s->dt_qual))
234 {
235 case TU_YEAR :
236 if (_s->dt_dec.dec_exp >= 7)
237 {
238 nYear = (*p++) * 100;
239 if (--ndgts == 0)
240 break;
241 }
242 if (_s->dt_dec.dec_exp >= 6)
243 {
244 nYear += (*p++);
245 if (--ndgts == 0)
246 break;
247 }
248 case TU_MONTH :
249 if (_s->dt_dec.dec_exp >= 5)
250 {
251 nMonth = *p++;
252 if (--ndgts == 0)
253 break;
254 }
255 case TU_DAY :
256 if (_s->dt_dec.dec_exp >= 4)
257 {
258 nDay = *p++;
259 if (--ndgts == 0)
260 break;
261 }
262 case TU_HOUR :
263 if (_s->dt_dec.dec_exp >= 3)
264 {
265 nHour = *p++;
266 if (--ndgts == 0)
267 break;
268 }
269 case TU_MINUTE :
270 if (_s->dt_dec.dec_exp >= 2)
271 {
272 nMin = *p++;
273 if (--ndgts == 0)
274 break;
275 }
276 case TU_SECOND :
277 if (_s->dt_dec.dec_exp >= 1)
278 {
279 nSec = *p++;
280 if (--ndgts == 0)
281 break;
282 }
283 case TU_FRAC :
284 // TU_F1, TU_F2
285 if (_s->dt_dec.dec_exp >= 0)
286 {
287 nFSec = *p++ * 10000;
288 if (--ndgts == 0)
289 break;
290 }
291 // TU_F3, TU_F4
292 if (_s->dt_dec.dec_exp >= -1)
293 {
294 nFSec += *p * 100;
295 if (--ndgts == 0)
296 break;
297 }
298 // TU_F5
299 if (_s->dt_dec.dec_exp >= -2)
300 nFSec += *p;
301 }
302
303 _r->nYear = nYear;
304 _r->nMonth = nMonth;
305 _r->nDay = nDay;
306 _r->nHour = nHour;
307 _r->nMin = nMin;
308 _r->nSec = nSec;
309 _r->nFrac = nFSec * 1000;
310 _r->nTzMin = 0;
311}
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ __decode_intrvl()

void __decode_intrvl ( const intrvl_t * _s,
SQL::Interval * _r )

Definition at line 118 of file IFXTypes.cpp.

119{
120 __DCL_ASSERT(_s->in_dec.dec_pos >= 0);
121
122 int nYears, nMonths, nDays, nHours, nMins, nSecs, nFSecs;
123 nYears = nMonths = nDays = nHours = nMins = nSecs = nFSecs = 0;
124
125 const char* p = _s->in_dec.dec_dgts;
126 int ndgts = _s->in_dec.dec_ndgts;
127
128 switch(TU_START(_s->in_qual))
129 {
130 case TU_YEAR :
131 __GET_UNIT_VALUE(nYears, TU_YEAR, 6)
132 case TU_MONTH :
133 __GET_UNIT_VALUE(nMonths, TU_MONTH, 5)
134 case TU_DAY :
135 __GET_UNIT_VALUE(nDays, TU_DAY, 4)
136 case TU_HOUR :
137 __GET_UNIT_VALUE(nHours, TU_HOUR, 3)
138 case TU_MINUTE :
139 __GET_UNIT_VALUE(nMins, TU_MINUTE, 2)
140 case TU_SECOND :
141 __GET_UNIT_VALUE(nSecs, TU_SECOND, 1)
142 case TU_FRAC :
143 // TU_F1, TU_F2
144 if (_s->in_dec.dec_exp >= 0)
145 {
146 nFSecs += *p++ * 10000;
147 ndgts--;
148 }
149 if (ndgts == 0)
150 break;
151 // TU_F3, TU_F4
152 if (_s->in_dec.dec_exp >= -1)
153 {
154 nFSecs += *p * 100;
155 ndgts--;
156 }
157 if (ndgts == 0)
158 break;
159 // TU_F5
160 if (_s->in_dec.dec_exp >= -2)
161 nFSecs += *p;
162 }
163
164#define MIN_PER_DAY 1440
165#define SEC_PER_DAY 86400
166#define SEC_PER_HOUR 3600
167
168 switch(TU_START(_s->in_qual))
169 {
170 case TU_YEAR :
171 break;
172 case TU_MONTH :
173 nYears = nMonths / 12;
174 nMonths = nMonths % 12;
175 break;
176 case TU_DAY :
177 break;
178 case TU_HOUR :
179 nDays = nHours / 24;
180 nHours = nHours % 24;
181 break;
182 case TU_MINUTE :
183 nDays = nMins / MIN_PER_DAY;
184 nHours = (nMins % MIN_PER_DAY) / 60;
185 nMins = nMins % 60;
186 break;
187 case TU_SECOND :
188 nDays = nSecs / SEC_PER_DAY;
189 nHours = (nSecs % SEC_PER_DAY) / SEC_PER_HOUR;
190 nMins = (nSecs % SEC_PER_HOUR) / 60;
191 nSecs = nSecs % 60;
192 break;
193 case TU_FRAC :
194 break;
195 default :
196 __DCL_ASSERT(false);
197 }
198
199 if (_s->in_dec.dec_pos == 1)
200 {
201 _r->nYears = nYears;
202 _r->nMonths = nMonths;
203 _r->nDays = nDays;
204 _r->nHours = nHours;
205 _r->nMins = nMins;
206 _r->nSecs = nSecs;
207 _r->nFracs = nFSecs * 1000;
208 }
209 else
210 {
211 _r->nYears = -nYears;
212 _r->nMonths = -nMonths;
213 _r->nDays = -nDays;
214 _r->nHours = -nHours;
215 _r->nMins = -nMins;
216 _r->nSecs = -nSecs;
217 _r->nFracs = -(nFSecs * 1000);
218 }
219}
#define SEC_PER_HOUR
Definition DateTime.cpp:391
#define SEC_PER_DAY
Definition DateTime.cpp:389
#define __GET_UNIT_VALUE(TU_VAR, TU_NAME, TU_EXP)
Definition IFXTypes.cpp:93
#define MIN_PER_DAY
if(!__handle->open(bs, bs.length()))

◆ __encode_dtime() [1/3]

int __encode_dtime ( const SQL::Date * _s,
dtime_t * _r )

Definition at line 358 of file IFXTypes.cpp.

359{
360 char sz[30]; // YYYY-MM-DD 10
361 int n = snprintf(
362 sz,
363 sizeof(sz),
364 "%04d-%02d-%02d",
365 _s->nYear, _s->nMonth, _s->nDay
366 );
367 if (n < 0)
368 return -1263;
369 else
370 sz[n] = '\0';
371
372 _r->dt_qual = TU_DTENCODE(TU_YEAR, TU_DAY);
373 return dtcvasc(sz, _r);
374}
uint8_t nMonth
Definition SQLCore.h:97
int16_t nYear
Definition SQLCore.h:96
uint8_t nDay
Definition SQLCore.h:98

◆ __encode_dtime() [2/3]

int __encode_dtime ( const SQL::Time * _s,
dtime_t * _r )

Definition at line 376 of file IFXTypes.cpp.

377{
378 char sz[30]; // HH:MM:SS.FFF 12
379 int n = snprintf(
380 sz,
381 sizeof(sz),
382 "%02u:%02u:%02u.%05u",
383 _s->nHour, _s->nMin, _s->nSec, _s->nFrac / 10000
384 );
385 if (n < 0)
386 return -1263;
387 else
388 sz[n] = '\0';
389
390 _r->dt_qual = TU_DTENCODE(TU_HOUR, TU_F5);
391 return dtcvasc(sz, _r);
392}
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

◆ __encode_dtime() [3/3]

int __encode_dtime ( const SQL::TimeStamp * _s,
dtime_t * _r )

Definition at line 336 of file IFXTypes.cpp.

337{
338 char sz[40]; // YYYY-MM-DD HH:MM:SS.FFF 23
339 int n = snprintf(
340 sz,
341 sizeof(sz),
342 "%04d-%02u-%02u %02u:%02u:%02u.%05u",
343 _s->nYear, _s->nMonth, _s->nDay,
344 _s->nHour, _s->nMin, _s->nSec, _s->nFrac / 10000
345 );
346
347 // -1263 A field in a datetime or interval value
348 // is out of range or incorrect.
349 if (n < 0)
350 return -1263;
351 else
352 sz[n] = '\0';
353
354 _r->dt_qual = TU_DTENCODE(TU_YEAR, TU_F5);
355 return dtcvasc(sz, _r);
356}

◆ __encode_intrvl()

int __encode_intrvl ( const SQL::Interval * _s,
SQL::DataType _dataType,
intrvl_t * _r )

Definition at line 399 of file IFXTypes.cpp.

404{
405 if (_dataType == SQL::typeIntervalYm)
406 {
407 int fn = 1;
408 int d = 10;
409 for( ; _s->nYears / d; fn++)
410 d *= 10;
411
412 const char* fmt = "%d-%d";
413 if (_s->nYears < 0 || _s->nMonths < 0)
414 fmt = "-%d-%d";
415
416 char sz[30]; // YYYYYYYYY-MM
417 int n = snprintf(
418 sz,
419 sizeof(sz),
420 fmt,
421 __ABS(_s->nYears),
422 __ABS(_s->nMonths)
423 );
424 if (n < 0)
425 return -1263;
426 else
427 sz[n] = '\0';
428
429 _r->in_qual = TU_IENCODE(fn, TU_YEAR, TU_MONTH);
430 return incvasc(sz, _r);
431 }
432 else
433 {
434 __DCL_ASSERT(_dataType == SQL::typeIntervalDs);
435
436 int fn = 1; // FIRST LENGTH
437 int d = 10;
438 for( ; _s->nDays / d; fn++)
439 d *= 10;
440
441 const char* fmt = "%d %02d:%02d:%02d.%05d";
442 if (_s->nDays < 0 || _s->nHours < 0 || _s->nMins < 0
443 || _s->nSecs < 0 || _s->nFracs < 0)
444 fmt = "-%d %02d:%02d:%02d.%05d";
445
446 char sz[40]; // DDDDDDDDDD HH:MM:SS.FFF + sign = 24
447 int n = snprintf(
448 sz,
449 sizeof(sz),
450 fmt,
451 __ABS(_s->nDays),
452 __ABS(_s->nHours),
453 __ABS(_s->nMins),
454 __ABS(_s->nSecs),
455 __ABS(_s->nFracs / 10000)
456 );
457 if (n < 0)
458 return -1263;
459 else
460 sz[n] = '\0';
461
462 _r->in_qual = TU_IENCODE(fn, TU_DAY, TU_F5);
463 return incvasc(sz, _r);
464 }
465}
#define __ABS(n)
Definition MyParam.cpp:143
@ typeIntervalDs
Definition SQLCore.h:74
@ typeIntervalYm
Definition SQLCore.h:73
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

◆ __get_dec_strlen()

__DCL_BEGIN_NAMESPACE size_t __get_dec_strlen ( const dec_t * p)

Definition at line 26 of file IFXTypes.cpp.

27{
28 // assert(p->dec_pos != -1);
29 // assert(p->dec_ndgts >= 0);
30 __DCL_ASSERT(p->dec_pos != -1);
31 __DCL_ASSERT(p->dec_ndgts >= 0);
32
33 if (p->dec_ndgts == 0)
34 return 1; // "0"
35
36 size_t n = p->dec_pos == 0 ? 1 : 0;
37
38 int __n = p->dec_exp - p->dec_ndgts;
39 if (__n < 0)
40 {
41 // 소숫점 아래 포함
42
43 if (p->dec_exp > 0)
44 {
45 // 소숫점 위 포함
46 // 소숫점 아래와 소숫점 위 모두 포함
47
48 n += p->dec_ndgts * 2;
49
50 // 첫번째가 10보다 작으면
51 if (p->dec_dgts[0] < 10)
52 n--;
53
54 // 소숫점아래 마지막이 0이면
55 if ((p->dec_dgts[p->dec_ndgts - 1] % 10) == 0)
56 n--;
57
58 n++; // 소숫점
59 }
60 else
61 {
62 // 소숫점 아래만 있음
63 n += 2; // "0."
64 n += (-__n) * 2;
65
66 // 소숫점아래 마지막이 0이면
67 if ((p->dec_dgts[p->dec_ndgts - 1] % 10) == 0)
68 n--;
69 }
70 }
71 else
72 {
73 // 소숫점을 포함하지 않음
74
75 if (__n > 0)
76 n += (p->dec_ndgts + __n) * 2;
77 else
78 n += p->dec_ndgts * 2;
79
80 // 첫번째가 10보다 작으면
81 if (p->dec_dgts[0] < 10)
82 n--;
83
84 // dectoasc 에서 소숫점 없는 수는 ".0"을 추가함
85 n += 2;
86 }
87
88 return n;
89}