17#if __DCL_HAVE_ALLOC_DEBUG
18#undef __DCL_ALLOC_LEVEL
19#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
53const String& SQLField::name()
const
69const wchar_t* SQLField::serverDataTypeName()
const
74 return __handle->serverDataTypeName();
77short SQLField::precision()
const
85short SQLField::scale()
const
93bool SQLField::isNull()
const
107 if (!__handle->getDataSize(&nSize, _maxSize)) {
113void SQLField::getData(
124 if (!__handle->getData(_pv, _pn, _dataType)) {
136 size_t n =
sizeof(int32_t);
147 size_t n =
sizeof(uint32_t);
158 size_t n =
sizeof(int64_t);
169 size_t n =
sizeof(uint64_t);
180 size_t n =
sizeof(float);
191 size_t n =
sizeof(double);
226 getData(&
_r, &
n, dataType());
239 getData(&
_r, &
n, dataType());
244void SQLField::getValue(String&
_r)
253 size_t n = dataSize();
256 ByteBuffer*
buf = ByteBuffer::create(
n);
260 _r = UTF8Decoder::decode(
buf->data(),
buf->__dataLength);
269void SQLField::getValue(
284 size_t n = dataSize();
287 ByteBuffer*
buf = ByteBuffer::create(
n);
289 getData(
buf->data(), &
n, _dataType);
290 buf->__dataLength =
n;
314 static const char_t* _cast =
__T(
"asBoolean");
333 const wchar_t* p = (
const wchar_t*)
_r;
336 if (*p !=
__T(
'0')) {
342 if (*p !=
__T(
'.')) {
354 const wchar_t* p = (
const wchar_t*)
_r;
355 if (
_r.length() == 1) {
356 if (!(*p ==
__T(
' ') || *p ==
__T(
'0')
357 || *p ==
__T(
'f') || *p ==
__T(
'F')))
362 if (!(*p ==
__T(
' ') || *p ==
__T(
'0'))) {
373 throw new SQLException(
376 SQLException::eInvalidCast
386 static const char_t* _cast =
__T(
"asInt32");
390 if (dataSizeMax() <=
sizeof(int32_t))
396 throw new SQLException(
399 SQLException::eOutOfRange
407 if (dataSizeMax() <=
sizeof(uint32_t))
408 getValue((uint32_t&)
result);
413 throw new SQLException(
416 SQLException::eOutOfRange
429 throw new SQLException(
432 SQLException::eOutOfRange
446 size_t index =
_r.indexOf(
__T(
'e'));
447 if (index == (
size_t)-1)
448 index =
_r.indexOf(
__T(
'E'));
449 if (index != (
size_t)-1) {
455 catch (NumericConvertException* e) {
456 throw new SQLException(
this, _cast, e);
461 throw new SQLException(
464 SQLException::eOutOfRange
471 index =
_r.indexOf(
__T(
'.'));
472 if (index != (
size_t)-1)
479 catch (NumericConvertException* e) {
481 throw new SQLException(
this, _cast, e);
488 throw new SQLException(
491 SQLException::eInvalidCast
501 static const char_t* _cast =
__T(
"asInt64");
521 throw new SQLException(
524 SQLException::eOutOfRange
537 size_t index =
_r.indexOf(
__T(
'e'));
538 if (index == (
size_t)-1)
539 index =
_r.indexOf(
__T(
'E'));
540 if (index != (
size_t)-1) {
546 catch (NumericConvertException* e) {
547 throw new SQLException(
this, _cast, e);
552 throw new SQLException(
555 SQLException::eOutOfRange
562 index =
_r.indexOf(
'.');
563 if (index != (
size_t)-1)
570 catch (NumericConvertException* e) {
572 throw new SQLException(
this, _cast, e);
579 throw new SQLException(
582 SQLException::eInvalidCast
592 static const char_t* _cast =
__T(
"asSingle");
596 if (dataSizeMax() <=
sizeof(
float))
601 if (
_r < FLT_MIN || FLT_MAX <
_r) {
602 throw new SQLException(
605 SQLException::eOutOfRange
613 if (dataSizeMax() <=
sizeof(int32_t)) {
625 if (dataSizeMax() <=
sizeof(uint32_t)) {
648 catch (NumericConvertException* e) {
650 throw new SQLException(
this, _cast, e);
656 throw new SQLException(
659 SQLException::eInvalidCast
669 static const char_t* _cast =
__T(
"asDouble");
677 if (dataSizeMax() <=
sizeof(int32_t)) {
690 if (dataSizeMax() <=
sizeof(uint32_t)) {
713 catch (NumericConvertException* e) {
715 throw new SQLException(
this, _cast, e);
721 throw new SQLException(
724 SQLException::eInvalidCast
734 static const char_t* _cast =
__T(
"asDate");
753 throw new SQLException(
756 SQLException::eInvalidCast
766 static const char_t* _cast =
__T(
"asTime");
795 throw new SQLException(
798 SQLException::eInvalidCast
808 static const char_t* _cast =
__T(
"asDateTime");
850 throw new SQLException(
853 SQLException::eInvalidCast
863 return n < 0 ? -
n :
n;
868 static const char_t* _cast =
__T(
"asInterval");
875 if (
__ABS(
_r.nYears) > 5965231) {
877 throw new SQLException(
880 SQLException::eOutOfRange
884 _r.nYears * 360 +
_r.nMonths * 30,
904 if (
__ABS(
_r.nYears) > 5965231) {
906 throw new SQLException(
909 SQLException::eOutOfRange
913 _r.nDays +
_r.nYears * 360 +
_r.nMonths * 30,
923 throw new SQLException(
926 SQLException::eInvalidCast
933String SQLField::asString()
986 __T(
"%04d-%02d-%02d"),
997 __T(
"%02d:%02d:%02d.%03d"),
1009 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%03d"),
1024 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%03d %+03d%02d"),
1040 if (
_r.nYears < 0 ||
_r.nMonths < 0) {
1062 ||
_r.nHours < 0 ||
_r.nMins < 0
1063 ||
_r.nSecs < 0 ||
_r.nFracs < 0
1067 __T(
"-%d %02d:%02d:%02d.%03d"),
1072 -(
_r.nFracs / 1000000)
1078 __T(
"+%d %02d:%02d:%02d.%03d"),
1083 (
_r.nFracs / 1000000)
1091 if (
_r.nYears < 0 ||
_r.nMonths < 0) {
1099 else if (
_r.nYears > 0 ||
_r.nMonths > 0) {
1107 else if (
_r.nDays < 0
1108 ||
_r.nHours < 0 ||
_r.nMins < 0
1109 ||
_r.nSecs < 0 ||
_r.nFracs < 0
1113 __T(
"-%d %02d:%02d:%02d.%03d"),
1118 -(
_r.nFracs / 1000000)
1124 __T(
"+%d %02d:%02d:%02d.%03d"),
1129 (
_r.nFracs / 1000000)
1145 result = String::tryString(
_r, 20);
1156String SQLField::asStringF(
const char_t* _format )
1161 switch(dataType()) {
1213 memset(&t, 0,
sizeof(
struct tm));
1214 t.tm_year =
_r.nYear - 1900;
1215 t.tm_mon =
_r.nMonth - 1;
1216 t.tm_mday =
_r.nDay;
1222 buf->__dataLength =
n;
1236 memset(&t, 0,
sizeof(
struct tm));
1237 t.tm_hour =
_r.nHour;
1245 buf->__dataLength =
n;
1260 t.tm_year =
_r.nYear - 1900;
1261 t.tm_mon =
_r.nMonth - 1;
1262 t.tm_mday =
_r.nDay;
1263 t.tm_hour =
_r.nHour;
1274 buf->__dataLength =
n;
1297 result = String::tryString(
_r, 20);
#define __DCL_THROWS2(e1, e2)
#define DATETIME_FORMAT_BUFFER_SIZE
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
void CharsetConvertException *size_t n
String CharsetConvertException *size_t nDataSize
static const wchar_t * FORMAT_STRING
static const wchar_t * FORMAT_STRING
static double parse(const wchar_t *_number) __DCL_THROWS1(NumericConvertException *)
String toString(unsigned _base=10) const
static int32_t parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
String toString(unsigned _base=10) const
static int64_t parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
static float parse(const wchar_t *_number) __DCL_THROWS1(NumericConvertException *)
static const wchar_t * FORMAT_STRING
String toString(unsigned _base=10) const
String toString(unsigned _base=10) const