DCL 3.7.4
Loading...
Searching...
No Matches
SqTypes.h File Reference

Go to the source code of this file.

Macros

#define __DCL_SQ_TYPES_H__   20260117

Functions

__DCL_BEGIN_NAMESPACE 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

◆ __DCL_SQ_TYPES_H__

#define __DCL_SQ_TYPES_H__   20260117

Definition at line 2 of file SqTypes.h.

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 308 of file PqTypes.cpp.

312{
313 __DCL_ASSERT(_s);
314#ifndef __DCL_DEBUG
315 if (!_s) {
316 if (_endptr) {
317 *_endptr = _s;
318 }
319 return false;
320 }
321#endif
322
323 if (*_s != 'P') {
324 // invalid string
325 if (_endptr) {
326 *_endptr = _s;
327 }
328 return false;
329 }
330 _s++;
331
332#define __P0 0
333#define __PT 1
334#define __PTDOT 2
335#define __PDONE 3
336
337 bool r = true;
338 int state = __P0; // P3Y6M4DT12H30M5S
339 memset(&_r, 0, sizeof(_r));
340
341 char dotsign = '+'; // '.'에서 부호를 보관해야 SSS 사용할 수 있다.
342 char* endptr = (char*)_s;
343 for (; ; ) {
344 errno = 0;
345 const char* nptr = endptr;
346 long n = strtol(nptr, &endptr, 10);
347 if (errno == ERANGE) {
348 // invalid string
349 r = false;
350 break;
351 }
352 __DCL_TRACE4_N(L"state[%d] [%p][%hc] [%d]\n",
353 state, endptr, (*endptr ? *endptr : '$'), n);
354 switch (*endptr) {
355 case 'Y':
356 _r.years = (int32_t)n;
357 break;
358 case 'M':
359 if (state == __PT) {
360 _r.mins = (int8_t)n;
361 }
362 else {
363 _r.months = (int8_t)n;
364 }
365 break;
366 case 'D':
367 _r.days = (int32_t)n;
368 break;
369 case 'T':
370 state = __PT;
371 break;
372 case 'H':
373 _r.hours = (int8_t)n;
374 break;
375 case '.':
376 state = __PTDOT;
377 dotsign = *nptr;
378 _r.secs = (int8_t)n;
379 break;
380 case 'S': {
381 if (state == __PTDOT) {
382 _r.fracs = __fraction_normalize(n)
383 * (dotsign == '-' ? -1 : 1);
384 }
385 else {
386 _r.secs = (int8_t)n;
387 }
388 state = __PDONE;
389 break;
390 }
391 case '\0': {
392 state = __PDONE;
393 break;
394 }
395 default: {
396 // invalid string
397 r = false;
398 state = __PDONE;
399 }
400 }
401
402 if (state == __PDONE) {
403 break;
404 }
405 else {
406 endptr++;
407 }
408 }
409
410 if (_endptr) {
411 *_endptr = endptr;
412 }
413 return r;
414}
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
Definition PqTypes.cpp:35
#define __PTDOT
#define __P0
#define __PDONE
#define __PT
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()

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

Definition at line 176 of file PqTypes.cpp.

180{
181 __DCL_ASSERT(_s);
182#ifndef __DCL_DEBUG
183 if (!_s) {
184 if (_endptr) {
185 *_endptr = _s;
186 }
187 return false;
188 }
189#endif
190
191#define __START 0
192#define __yyyy 1
193#define __MM 2
194#define __dd 3
195#define __HH 4
196#define __mm 5
197#define __ss 6
198#define __SSS 7
199#define __ZH 8
200#define __Zm 9
201#define __Zs 10
202#define __BC 11
203#define __DONE 12
204
205 int state = __START; // yyyy-MM-dd'T'HH:mm:ss.SSSZ
206 memset(&_r, 0, sizeof(_r));
207 _r.tzoff = INT16_MIN;
208
209 bool r = true;
210 char* endptr = (char*)_s;
211 for (; ; ) {
212 errno = 0;
213 const char* nptr = endptr;
214 long n = strtol(nptr, &endptr, 10);
215 if (errno == ERANGE) {
216 // invalid string
217 r = false;
218 break;
219 }
220 if (state == __START) {
221 if (*endptr == '-') {
222 state = __yyyy;
223 }
224 else if (*endptr == ':') {
225 state = __HH;
226 }
227 else {
228 // invalid string
229 r = false;
230 break;
231 }
232 }
233 else if (*endptr == 'B') {
234 state = __BC;
235 }
236 else {
237 // '\0' == *endptr || strchr("- T:.+", *endptr)
238 state++;
239 }
240
241 __DCL_TRACE4_N(L"state[%2d] n[%10d] [%p][%hc]\n",
242 state, n, endptr, *endptr ? *endptr : '$');
243 switch (state) {
244 case __yyyy:
245 _r.year = (int16_t)n;
246 break;
247 case __MM:
248 _r.month = (uint8_t)n;
249 break;
250 case __dd:
251 _r.day = (uint8_t)n;
252 break;
253 case __HH:
254 _r.hour = (uint8_t)n;
255 break;
256 case __mm:
257 _r.min = (uint8_t)n;
258 break;
259 case __ss:
260 _r.sec = (uint8_t)n;
261 break;
262 case __SSS:
263 _r.frac = __fraction_normalize(n);
264 break;
265 case __ZH:
266 _r.tzoff = (int16_t)(n * 60);
267 break;
268 case __Zm:
269 _r.tzoff += (int16_t)n;
270 break;
271 case __Zs:
272 // +08:27:52 BC PostgreSQL Bug!! ignore
273 break;
274 case __BC: {
275 __DCL_ASSERT(*(endptr + 1) == 'C');
276 _r.year *= -1;
277 state = __DONE;
278 break;
279 }
280 default: {
281 __DCL_ASSERT(false);
282 }
283 }
284
285 if (*endptr == '\0' || state == __DONE) {
286 break;
287 }
288 else {
289 __DCL_TRACE1_N(L"[%hs]\n", (*endptr ? endptr : "(nil)"));
290 if ((state == __ss || state == __SSS)
291 && (*endptr == '+' || *endptr == '-')
292 ) {
293 state = __SSS;
294 // 부호와 함께 strtol 후 __ZH 상태가 된다.
295 }
296 else {
297 endptr++;
298 }
299 }
300 }
301
302 if (_endptr) {
303 *_endptr = endptr;
304 }
305 return r;
306}
#define INT16_MIN
Definition Config.h:284
#define __SSS
#define __DONE
#define __yyyy
#define __Zm
#define __MM
#define __BC
#define __dd
#define __DCL_TRACE1_N(fmt, arg)
Definition PqTypes.cpp:32
#define __mm
#define __START
#define __Zs
#define __ZH
#define __HH
#define __ss
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