17#if __DCL_HAVE_ALLOC_DEBUG
18#undef __DCL_ALLOC_LEVEL
19#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
25#if __DCL_HAVE_THIS_FILE__
46const String& SQLField::name()
const
58const wchar_t* SQLField::serverDataTypeName()
const
61 return __handle->serverDataTypeName();
64short SQLField::precision()
const
70short SQLField::scale()
const
79 size_t size = (size_t)-1;
81 throw new SQLException(
this,
NULL);
83 return size == (size_t)-1;
89 size_t size = (size_t)-1;
90 if (!__handle->getDataSize(&size, _maxsize)) {
96void SQLField::getData(
105 if (!__handle->getData(_buf, _size, _bufType)) {
117 size_t size =
sizeof(int8_t);
126 size_t size =
sizeof(uint8_t);
135 size_t size =
sizeof(int16_t);
144 size_t size =
sizeof(uint16_t);
153 size_t size =
sizeof(int32_t);
162 size_t size =
sizeof(uint32_t);
171 size_t size =
sizeof(int64_t);
180 size_t size =
sizeof(uint64_t);
189 size_t size =
sizeof(float);
198 size_t size =
sizeof(double);
238void SQLField::getValue(String& _val)
250 _val = UTF8Decoder::decode(val);
257void SQLField::getValue(
272 size_t size = dataSize();
275 ByteBuffer* buf = ByteBuffer::create(size);
277 getData(buf->data(), &size, _bufType);
278 buf->__dataLength = size;
288void SQLField::getValue(
305 static const char_t* _cast =
__T(
"asBoolean");
312 result = _val != (int64_t)0;
324 const wchar_t* p = (
const wchar_t*)_val;
327 if (*p !=
__T(
'0')) {
333 if (*p !=
__T(
'.')) {
345 const wchar_t* p = (
const wchar_t*)_val;
346 if (_val.length() == 1) {
347 if (!(*p ==
__T(
' ') || *p ==
__T(
'0')
348 || *p ==
__T(
'f') || *p ==
__T(
'F')))
353 if (!(*p ==
__T(
' ') || *p ==
__T(
'0'))) {
364 throw new SQLException(
367 SQLException::eInvalidCast
377 static const char_t* _cast =
__T(
"asInt32");
381 if (dataSizeMax() <=
sizeof(int32_t))
387 throw new SQLException(
390 SQLException::eOutOfRange
393 result = (int32_t)_val;
398 if (dataSizeMax() <=
sizeof(uint32_t))
399 getValue((uint32_t&)result);
404 throw new SQLException(
407 SQLException::eOutOfRange
410 result = (int32_t)_val;
420 throw new SQLException(
423 SQLException::eOutOfRange
437 size_t index = _val.indexOf(
__T(
'e'));
438 if (index == (
size_t)-1)
439 index = _val.indexOf(
__T(
'E'));
440 if (index != (
size_t)-1) {
446 catch (NumericConvertException* e) {
447 throw new SQLException(
this, _cast, e);
452 throw new SQLException(
455 SQLException::eOutOfRange
462 index = _val.indexOf(
__T(
'.'));
463 if (index != (
size_t)-1)
464 _val = _val.left(index);
470 catch (NumericConvertException* e) {
472 throw new SQLException(
this, _cast, e);
479 throw new SQLException(
482 SQLException::eInvalidCast
492 static const char_t* _cast =
__T(
"asInt64");
502 result = (int64_t)_val;
511 throw new SQLException(
514 SQLException::eOutOfRange
517 result = (int64_t)_val;
527 size_t index = _val.indexOf(
__T(
'e'));
528 if (index == (
size_t)-1)
529 index = _val.indexOf(
__T(
'E'));
530 if (index != (
size_t)-1) {
536 catch (NumericConvertException* e) {
537 throw new SQLException(
this, _cast, e);
542 throw new SQLException(
545 SQLException::eOutOfRange
552 index = _val.indexOf(
'.');
553 if (index != (
size_t)-1)
554 _val = _val.left(index);
560 catch (NumericConvertException* e) {
562 throw new SQLException(
this, _cast, e);
569 throw new SQLException(
572 SQLException::eInvalidCast
582 static const char_t* _cast =
__T(
"asSingle");
586 if (dataSizeMax() <=
sizeof(
float))
591 if (_val < -FLT_MAX || FLT_MAX < _val) {
592 throw new SQLException(
595 SQLException::eOutOfRange
598 result = (float)_val;
603 if (dataSizeMax() <=
sizeof(int32_t)) {
606 result = (float)_val;
611 result = (float)_val;
615 if (dataSizeMax() <=
sizeof(uint32_t)) {
618 result = (float)_val;
623 result = (float)_val;
638 catch (NumericConvertException* e) {
640 throw new SQLException(
this, _cast, e);
646 throw new SQLException(
649 SQLException::eInvalidCast
659 static const char_t* _cast =
__T(
"asDouble");
667 if (dataSizeMax() <=
sizeof(int32_t)) {
670 result = (double)_val;
675 result = (double)_val;
680 if (dataSizeMax() <=
sizeof(uint32_t)) {
683 result = (double)_val;
688 result = (double)_val;
703 catch (NumericConvertException* e) {
705 throw new SQLException(
this, _cast, e);
711 throw new SQLException(
714 SQLException::eInvalidCast
724 static const char_t* _cast =
__T(
"asDate");
743 throw new SQLException(
746 SQLException::eInvalidCast
756 static const char_t* _cast =
__T(
"asTime");
786 throw new SQLException(
789 SQLException::eInvalidCast
799 static const char_t* _cast =
__T(
"asDateTime");
842 throw new SQLException(
845 SQLException::eInvalidCast
853static inline int __ABS(
int _n)
855 return _n < 0 ? -_n : _n;
860 static const char_t* _cast =
__T(
"asInterval");
869 throw new SQLException(
872 SQLException::eOutOfRange
898 throw new SQLException(
901 SQLException::eOutOfRange
915 throw new SQLException(
918 SQLException::eInvalidCast
925String SQLField::asString()
929 size_t nDataSize = dataSize();
932 if (nDataSize <=
sizeof(int32_t)) {
945 if (nDataSize <=
sizeof(int32_t)) {
958 if (nDataSize ==
sizeof(
float)) {
977 result = String::format(
978 __T(
"%04d-%02d-%02d"),
984 result = result + L
" BC";
991 result = String::format(
992 __T(
"%02d:%02d:%02d.%06d"),
1003 result = String::format(
1004 __T(
"%02d:%02d:%02d.%06d %+03d:%02d"),
1015 SQL::TimeStamp _val;
1017 result = String::format(
1018 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%06d"),
1027 if (_val.
year < 0) {
1028 result = result + L
" BC";
1033 SQL::TimeStamp _val;
1035 result = String::format(
1036 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%06d %+03d:%02d"),
1047 if (_val.
year < 0) {
1048 result = result + L
" BC";
1056 result = String::format(
1064 result = String::format(
1071 else if (_val.
days < 0
1075 result = String::format(
1077 __T(
"-%d %02d:%02d:%02d.%06d"),
1082 -(_val.
fracs / 1000)
1086 result = String::format(
1088 __T(
"+%d %02d:%02d:%02d.%06d"),
1102 result = String::format(
1110 result = String::format(
1126 result = String::format(
1128 __T(
"-%d %02d:%02d:%02d.%06d"),
1133 -(_val.
fracs / 1000)
1137 result = String::format(
1139 __T(
"+%d %02d:%02d:%02d.%06d"),
1160 result = String::tryString(_val, 20);
1171String SQLField::asStringF(
const char_t* _format )
1175 size_t nDataSize = dataSize();
1176 switch(dataType()) {
1178 if (nDataSize <=
sizeof(int32_t)) {
1191 if (nDataSize <=
sizeof(uint32_t)) {
1204 if (nDataSize ==
sizeof(
float)) {
1228 memset(&t, 0,
sizeof(
struct tm));
1229 t.tm_year = _val.
year - 1900;
1230 t.tm_mon = _val.
month - 1;
1231 t.tm_mday = _val.
day;
1237 buf->__dataLength = count;
1252 memset(&t, 0,
sizeof(
struct tm));
1253 t.tm_hour = _val.
hour;
1254 t.tm_min = _val.
min;
1255 t.tm_sec = _val.
sec;
1261 buf->__dataLength = count;
1276 t.tm_year = _val.
year - 1900;
1277 t.tm_mon = _val.
month - 1;
1278 t.tm_mday = _val.
day;
1279 t.tm_hour = _val.
hour;
1280 t.tm_min = _val.
min;
1281 t.tm_sec = _val.
sec;
1290 buf->__dataLength = count;
1299 result = asString();
1313 result = String::tryString(_val, 20);
#define DATETIME_FORMAT_BUFFER_SIZE
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
void assign(int _year, int _month, int _day)
static const wchar_t * FORMAT_STRING
void assign(time_t _timer)
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 *)
void assign(int _days, int _milliseconds)
static float parse(const wchar_t *_number) __DCL_THROWS1(NumericConvertException *)
static const wchar_t * FORMAT_STRING
void assign(int _hour, int _min, int _sec, int _millisecond=0)
String toString(unsigned _base=10) const
String toString(unsigned _base=10) const