DCL 3.7.4
Loading...
Searching...
No Matches
SqTypes.cpp File Reference
#include <dcl/Config.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#include <dcl/Object.h>
#include <dcl/SQLCore.h>
#include "SqTypes.h"

Go to the source code of this file.

Classes

struct  DateTime

Macros

#define __TRACE_THIS   0
#define __DCL_TRACE0_N(fmt)
#define __DCL_TRACE1_N(fmt, arg)
#define __DCL_TRACE2_N(fmt, arg1, arg2)
#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
#define __START   0
#define __yyyy   1
#define __MM   2
#define __dd   3
#define __HH   4
#define __mm   5
#define __ss   6
#define __SSS   7
#define __ZH   8
#define __Zm   9
#define __Zs   10
#define __BC   11
#define __DONE   12
#define __P0   0
#define __PT   1
#define __PTDOT   2
#define __PDONE   3
#define SQLTYPE_NAME(_type, _name)
#define INT_464269060799999   ((((i64)0x1a640)<<32)|0x1072fdff)

Typedefs

typedef sqlite_int64 i64

Functions

bool __decode_timestamp_iso (const char *_s, const char **_endptr, SQL::TimeStamp &_r)
bool __decode_interval_iso (const char *_s, const char **_endptr, SQL::Interval &_r)
const wchar_t * __dataTypeName (int _type)
bool __decode_timestamp_julianday (double _julianday, SQL::TimeStamp &_r)
bool __decode_timestamp_unixepoch (int64_t _unixepoch, SQL::TimeStamp &_r)

Macro Definition Documentation

◆ __BC

#define __BC   11

◆ __DCL_TRACE0_N

#define __DCL_TRACE0_N ( fmt)

Definition at line 26 of file SqTypes.cpp.

◆ __DCL_TRACE1_N

#define __DCL_TRACE1_N ( fmt,
arg )

Definition at line 27 of file SqTypes.cpp.

◆ __DCL_TRACE2_N

#define __DCL_TRACE2_N ( fmt,
arg1,
arg2 )

Definition at line 28 of file SqTypes.cpp.

◆ __DCL_TRACE3_N

#define __DCL_TRACE3_N ( fmt,
arg1,
arg2,
arg3 )

Definition at line 29 of file SqTypes.cpp.

◆ __DCL_TRACE4_N

#define __DCL_TRACE4_N ( fmt,
arg1,
arg2,
arg3,
arg4 )

Definition at line 30 of file SqTypes.cpp.

◆ __dd

#define __dd   3

◆ __DONE

#define __DONE   12

◆ __HH

#define __HH   4

◆ __MM

#define __MM   2

◆ __mm

#define __mm   5

◆ __P0

#define __P0   0

◆ __PDONE

#define __PDONE   3

◆ __PT

#define __PT   1

◆ __PTDOT

#define __PTDOT   2

◆ __ss

#define __ss   6

◆ __SSS

#define __SSS   7

◆ __START

#define __START   0

◆ __TRACE_THIS

#define __TRACE_THIS   0

Definition at line 18 of file SqTypes.cpp.

◆ __yyyy

#define __yyyy   1

◆ __ZH

#define __ZH   8

◆ __Zm

#define __Zm   9

◆ __Zs

#define __Zs   10

◆ INT_464269060799999

#define INT_464269060799999   ((((i64)0x1a640)<<32)|0x1072fdff)

Definition at line 320 of file SqTypes.cpp.

◆ SQLTYPE_NAME

#define SQLTYPE_NAME ( _type,
_name )
Value:
case _type : return L ## _name

Definition at line 295 of file SqTypes.cpp.

Typedef Documentation

◆ i64

typedef sqlite_int64 i64

Definition at line 309 of file SqTypes.cpp.

Function Documentation

◆ __dataTypeName()

const wchar_t * __dataTypeName ( int _type)

Definition at line 297 of file SqTypes.cpp.

298{
299 switch (_type) {
300 SQLTYPE_NAME(SQLITE_INTEGER, "INTEGER"); // 1
301 SQLTYPE_NAME(SQLITE_FLOAT, "FLOAT"); // 2
302 SQLTYPE_NAME(SQLITE_TEXT, "TEXT"); // 3
303 SQLTYPE_NAME(SQLITE_BLOB, "BLOB"); // 4
304 SQLTYPE_NAME(SQLITE_NULL, "NULL"); // 5
305 default: return L"Unknown Type (Binary Mapped)";
306 }
307}
#define SQLTYPE_NAME(_type, _name)
Definition SqTypes.cpp:295

◆ __decode_interval_iso()

bool __decode_interval_iso ( const char * _s,
const char ** _endptr,
SQL::Interval & _r )

Definition at line 187 of file SqTypes.cpp.

191{
192 __DCL_ASSERT(_s);
193#ifndef __DCL_DEBUG
194 if (!_s) {
195 if (_endptr) {
196 *_endptr = _s;
197 }
198 return false;
199 }
200#endif
201
202 if (*_s != 'P') {
203 // invalid string
204 if (_endptr) {
205 *_endptr = _s;
206 }
207 return false;
208 }
209 _s++;
210
211#define __P0 0
212#define __PT 1
213#define __PTDOT 2
214#define __PDONE 3
215
216 bool r = true;
217 int state = __P0; // P3Y6M4DT12H30M5S
218 memset(&_r, 0, sizeof(_r));
219
220 char dotsign = '+'; // '.'에서 부호를 보관해야 SSS 사용할 수 있다.
221 char* endptr = (char*)_s;
222 for (; ; ) {
223 errno = 0;
224 const char* nptr = endptr;
225 long n = strtol(nptr, &endptr, 10);
226 if (errno == ERANGE) {
227 // invalid string
228 r = false;
229 break;
230 }
231 __DCL_TRACE4_N(L"state[%d] [%p][%hc] [%d]\n",
232 state, endptr, (*endptr ? *endptr : '$'), n);
233 switch (*endptr) {
234 case 'Y':
235 _r.years = (int32_t)n;
236 break;
237 case 'M':
238 if (state == __PT) {
239 _r.mins = (int8_t)n;
240 }
241 else {
242 _r.months = (int8_t)n;
243 }
244 break;
245 case 'D':
246 _r.days = (int32_t)n;
247 break;
248 case 'T':
249 state = __PT;
250 break;
251 case 'H':
252 _r.hours = (int8_t)n;
253 break;
254 case '.':
255 state = __PTDOT;
256 dotsign = *nptr;
257 _r.secs = (int8_t)n;
258 break;
259 case 'S': {
260 if (state == __PTDOT) {
261 _r.fracs = __fraction_normalize(n)
262 * (dotsign == '-' ? -1 : 1);
263 }
264 else {
265 _r.secs = (int8_t)n;
266 }
267 state = __PDONE;
268 break;
269 }
270 case '\0': {
271 state = __PDONE;
272 break;
273 }
274 default: {
275 // invalid string
276 r = false;
277 state = __PDONE;
278 }
279 }
280
281 if (state == __PDONE) {
282 break;
283 }
284 else {
285 endptr++;
286 }
287 }
288
289 if (_endptr) {
290 *_endptr = endptr;
291 }
292 return r;
293}
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __PTDOT
#define __P0
#define __PDONE
#define __PT
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
Definition SqTypes.cpp:30
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

◆ __decode_timestamp_iso()

bool __decode_timestamp_iso ( const char * _s,
const char ** _endptr,
SQL::TimeStamp & _r )

Definition at line 55 of file SqTypes.cpp.

59{
60 __DCL_ASSERT(_s);
61#ifndef __DCL_DEBUG
62 if (!_s) {
63 if (_endptr) {
64 *_endptr = _s;
65 }
66 return false;
67 }
68#endif
69
70#define __START 0
71#define __yyyy 1
72#define __MM 2
73#define __dd 3
74#define __HH 4
75#define __mm 5
76#define __ss 6
77#define __SSS 7
78#define __ZH 8
79#define __Zm 9
80#define __Zs 10
81#define __BC 11
82#define __DONE 12
83
84 int state = __START; // yyyy-MM-dd'T'HH:mm:ss.SSSZ
85 memset(&_r, 0, sizeof(_r));
86 _r.tzoff = INT16_MIN;
87
88 bool r = true;
89 char* endptr = (char*)_s;
90 for (; ; ) {
91 errno = 0;
92 const char* nptr = endptr;
93 long n = strtol(nptr, &endptr, 10);
94 if (errno == ERANGE) {
95 // invalid string
96 r = false;
97 break;
98 }
99 if (state == __START) {
100 if (*endptr == '-') {
101 state = __yyyy;
102 }
103 else if (*endptr == ':') {
104 state = __HH;
105 }
106 else {
107 // invalid string
108 r = false;
109 break;
110 }
111 }
112 else if (*endptr == 'B') {
113 state = __BC;
114 }
115 else {
116 // '\0' == *endptr || strchr("- T:.+", *endptr)
117 state++;
118 }
119
120 __DCL_TRACE4_N(L"state[%2d] n[%10d] [%p][%hc]\n",
121 state, n, endptr, *endptr ? *endptr : '$');
122 switch (state) {
123 case __yyyy:
124 _r.year = (int16_t)n;
125 break;
126 case __MM:
127 _r.month = (uint8_t)n;
128 break;
129 case __dd:
130 _r.day = (uint8_t)n;
131 break;
132 case __HH:
133 _r.hour = (uint8_t)n;
134 break;
135 case __mm:
136 _r.min = (uint8_t)n;
137 break;
138 case __ss:
139 _r.sec = (uint8_t)n;
140 break;
141 case __SSS:
142 _r.frac = __fraction_normalize(n);
143 break;
144 case __ZH:
145 _r.tzoff = (int16_t)(n * 60);
146 break;
147 case __Zm:
148 _r.tzoff += (int16_t)n;
149 break;
150 case __Zs:
151 // +08:27:52 BC PostgreSQL Bug!! ignore
152 break;
153 case __BC: {
154 __DCL_ASSERT(*(endptr + 1) == 'C');
155 _r.year *= -1;
156 state = __DONE;
157 break;
158 }
159 default: {
160 __DCL_ASSERT(false);
161 }
162 }
163
164 if (*endptr == '\0' || state == __DONE) {
165 break;
166 }
167 else {
168 __DCL_TRACE1_N(L"[%hs]\n", (*endptr ? endptr : "(nil)"));
169 if ((state == __ss || state == __SSS)
170 && (*endptr == '+' || *endptr == '-')
171 ) {
172 state = __SSS;
173 // 부호와 함께 strtol 후 __ZH 상태가 된다.
174 }
175 else {
176 endptr++;
177 }
178 }
179 }
180
181 if (_endptr) {
182 *_endptr = endptr;
183 }
184 return r;
185}
#define INT16_MIN
Definition Config.h:284
#define __SSS
#define __DONE
#define __yyyy
#define __Zm
#define __MM
#define __BC
#define __dd
#define __mm
#define __START
#define __Zs
#define __ZH
#define __HH
#define __ss
#define __DCL_TRACE1_N(fmt, arg)
Definition SqTypes.cpp:27
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

◆ __decode_timestamp_julianday()

bool __decode_timestamp_julianday ( double _julianday,
SQL::TimeStamp & _r )

Definition at line 354 of file SqTypes.cpp.

355{
356 DateTime dt;
357 // setRawDateNumber
358 dt.iJD = (sqlite3_int64)(_julianday * 86400000.0 + 0.5);
359 if (!validJulianDay(dt.iJD)) {
360 return false;
361 }
362 computeYMD_HMS(&dt);
363
364 _r.year = dt.Y;
365 _r.month = dt.M;
366 _r.day = dt.D;
367
368 _r.hour = dt.h;
369 _r.min = dt.m;
370 _r.sec = (uint8_t) dt.s;
371 _r.frac = dt.ms * 1000000;
372 _r.tzoff = INT16_MIN;
373
374 return true;
375}
double s
Definition SqTypes.cpp:316
sqlite3_int64 iJD
Definition SqTypes.cpp:312

◆ __decode_timestamp_unixepoch()

bool __decode_timestamp_unixepoch ( int64_t _unixepoch,
SQL::TimeStamp & _r )

Definition at line 380 of file SqTypes.cpp.

381{
382 DateTime dt;
383 dt.iJD = (_unixepoch + 21086676 * (i64)10000) * 1000;
384 __DCL_TRACE2_N(L"[%lld] [%lld]\n", _unixepoch, dt.iJD);
385 if (!validJulianDay(dt.iJD)) {
386 return false;
387 }
388 computeYMD_HMS(&dt);
389
390 _r.year = dt.Y;
391 _r.month = dt.M;
392 _r.day = dt.D;
393
394 _r.hour = dt.h;
395 _r.min = dt.m;
396 _r.sec = (uint8_t)dt.s;
397 _r.frac = dt.ms * 1000000;
398 _r.tzoff = INT16_MIN;
399
400 return true;
401}
sqlite_int64 i64
Definition SqTypes.cpp:309
#define __DCL_TRACE2_N(fmt, arg1, arg2)
Definition SqTypes.cpp:28