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);
245void SQLField::getValue(String&
_r)
254 size_t n = dataSize();
257 ByteBuffer*
buf = ByteBuffer::create(
n);
261 _r = UTF8Decoder::decode(
buf->data(),
buf->__dataLength);
270void SQLField::getValue(
285 size_t n = dataSize();
288 ByteBuffer*
buf = ByteBuffer::create(
n);
290 getData(
buf->data(), &
n, _dataType);
291 buf->__dataLength =
n;
301void SQLField::getValue(
318 static const char_t* _cast =
__T(
"asBoolean");
337 const wchar_t* p = (
const wchar_t*)
_r;
340 if (*p !=
__T(
'0')) {
346 if (*p !=
__T(
'.')) {
358 const wchar_t* p = (
const wchar_t*)
_r;
359 if (
_r.length() == 1) {
360 if (!(*p ==
__T(
' ') || *p ==
__T(
'0')
361 || *p ==
__T(
'f') || *p ==
__T(
'F')))
366 if (!(*p ==
__T(
' ') || *p ==
__T(
'0'))) {
377 throw new SQLException(
380 SQLException::eInvalidCast
390 static const char_t* _cast =
__T(
"asInt32");
394 if (dataSizeMax() <=
sizeof(int32_t))
400 throw new SQLException(
403 SQLException::eOutOfRange
411 if (dataSizeMax() <=
sizeof(uint32_t))
412 getValue((uint32_t&)
result);
417 throw new SQLException(
420 SQLException::eOutOfRange
433 throw new SQLException(
436 SQLException::eOutOfRange
450 size_t index =
_r.indexOf(
__T(
'e'));
451 if (index == (
size_t)-1)
452 index =
_r.indexOf(
__T(
'E'));
453 if (index != (
size_t)-1) {
459 catch (NumericConvertException* e) {
460 throw new SQLException(
this, _cast, e);
465 throw new SQLException(
468 SQLException::eOutOfRange
475 index =
_r.indexOf(
__T(
'.'));
476 if (index != (
size_t)-1)
483 catch (NumericConvertException* e) {
485 throw new SQLException(
this, _cast, e);
492 throw new SQLException(
495 SQLException::eInvalidCast
505 static const char_t* _cast =
__T(
"asInt64");
524 throw new SQLException(
527 SQLException::eOutOfRange
540 size_t index =
_r.indexOf(
__T(
'e'));
541 if (index == (
size_t)-1)
542 index =
_r.indexOf(
__T(
'E'));
543 if (index != (
size_t)-1) {
549 catch (NumericConvertException* e) {
550 throw new SQLException(
this, _cast, e);
555 throw new SQLException(
558 SQLException::eOutOfRange
565 index =
_r.indexOf(
'.');
566 if (index != (
size_t)-1)
573 catch (NumericConvertException* e) {
575 throw new SQLException(
this, _cast, e);
582 throw new SQLException(
585 SQLException::eInvalidCast
595 static const char_t* _cast =
__T(
"asSingle");
599 if (dataSizeMax() <=
sizeof(
float))
604 if (
_r < FLT_MIN || FLT_MAX <
_r) {
605 throw new SQLException(
608 SQLException::eOutOfRange
616 if (dataSizeMax() <=
sizeof(int32_t)) {
628 if (dataSizeMax() <=
sizeof(uint32_t)) {
651 catch (NumericConvertException* e) {
653 throw new SQLException(
this, _cast, e);
659 throw new SQLException(
662 SQLException::eInvalidCast
672 static const char_t* _cast =
__T(
"asDouble");
680 if (dataSizeMax() <=
sizeof(int32_t)) {
693 if (dataSizeMax() <=
sizeof(uint32_t)) {
716 catch (NumericConvertException* e) {
718 throw new SQLException(
this, _cast, e);
724 throw new SQLException(
727 SQLException::eInvalidCast
737 static const char_t* _cast =
__T(
"asDate");
756 throw new SQLException(
759 SQLException::eInvalidCast
769 static const char_t* _cast =
__T(
"asTime");
799 throw new SQLException(
802 SQLException::eInvalidCast
812 static const char_t* _cast =
__T(
"asDateTime");
855 throw new SQLException(
858 SQLException::eInvalidCast
868 return n < 0 ? -
n :
n;
873 static const char_t* _cast =
__T(
"asInterval");
880 if (
__ABS(
_r.years) > 5965231) {
882 throw new SQLException(
885 SQLException::eOutOfRange
889 _r.years * 360 +
_r.months * 30,
909 if (
__ABS(
_r.years) > 5965231) {
911 throw new SQLException(
914 SQLException::eOutOfRange
918 _r.days +
_r.years * 360 +
_r.months * 30,
928 throw new SQLException(
931 SQLException::eInvalidCast
938String SQLField::asString()
991 __T(
"%04d-%02d-%02d"),
1002 __T(
"%02d:%02d:%02d.%03d"),
1014 __T(
"%02d:%02d:%02d.%03d %+03d%02d"),
1028 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%03d"),
1043 __T(
"%04d-%02d-%02d %02d:%02d:%02d.%03d %+03d%02d"),
1059 if (
_r.years < 0 ||
_r.months < 0) {
1067 else if (
_r.years > 0 ||
_r.months > 0) {
1075 else if (
_r.days < 0
1076 ||
_r.hours < 0 ||
_r.mins < 0
1077 ||
_r.secs < 0 ||
_r.fracs < 0
1081 __T(
"-%d %02d:%02d:%02d.%03d"),
1086 -(
_r.fracs / 1000000)
1092 __T(
"+%d %02d:%02d:%02d.%03d"),
1097 (
_r.fracs / 1000000)
1105 if (
_r.years < 0 ||
_r.months < 0) {
1127 ||
_r.hours < 0 ||
_r.mins < 0
1128 ||
_r.secs < 0 ||
_r.fracs < 0
1132 __T(
"-%d %02d:%02d:%02d.%03d"),
1137 -(
_r.fracs / 1000000)
1143 __T(
"+%d %02d:%02d:%02d.%03d"),
1148 (
_r.fracs / 1000000)
1164 result = String::tryString(
_r, 20);
1175String SQLField::asStringF(
const char_t* _format )
1180 switch(dataType()) {
1232 memset(&t, 0,
sizeof(
struct tm));
1233 t.tm_year =
_r.year - 1900;
1234 t.tm_mon =
_r.month - 1;
1241 buf->__dataLength =
n;
1256 memset(&t, 0,
sizeof(
struct tm));
1257 t.tm_hour =
_r.hour;
1265 buf->__dataLength =
n;
1280 t.tm_year =
_r.year - 1900;
1281 t.tm_mon =
_r.month - 1;
1283 t.tm_hour =
_r.hour;
1294 buf->__dataLength =
n;
1317 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