77 bool * p_negative,
size_t *p_digits,
size_t *p_decimals);
79 #define test_alloc(x) {if ((x)==NULL) return TDS_CONVERT_NOMEM;}
81 #define IS_TINYINT(x) ( 0 <= (x) && (x) <= 0xff )
82 #define IS_SMALLINT(x) ( -32768 <= (x) && (x) <= 32767 )
83 #define IS_USMALLINT(x) ( 0 <= (x) && (x) <= 65535 )
88 #define TDS_INT_MIN (-2147483647l-1l)
89 #define TDS_INT_MAX 2147483647l
90 #define IS_INT(x) (TDS_INT_MIN <= (x) && (x) <= TDS_INT_MAX)
92 #define TDS_UINT_MAX 4294967295lu
93 #define IS_UINT(x) (0 <= (x) && (x) <= TDS_UINT_MAX)
95 #define TDS_INT8_MAX ((((TDS_INT8) 0x7fffffffl) << 32) + (TDS_INT8) 0xfffffffflu)
96 #define TDS_INT8_MIN (-TDS_INT8_MAX - (TDS_INT8) 1)
97 #define IS_INT8(x) (TDS_INT8_MIN <= (x) && (x) <= TDS_INT8_MAX)
99 #define TDS_UINT8_MAX ((((TDS_UINT8) 0xfffffffflu) << 32) + 0xfffffffflu)
100 #define IS_UINT8(x) (0 <= (x) && (x) <= TDS_UINT8_MAX)
102 #define TDS_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
104 #define BIGDATETIME_BIAS 693961
146 static bool is_ampm(
const char *);
147 #define is_monthname(s) (store_monthname(s, NULL) >= 0)
163 size_t len = strlen(s);
168 memcpy(cr->
c, s,
len + 1);
170 memcpy(cr->
cc.
c, s, len < cr->cc.len ?
len : cr->
cc.
len);
175 #define string_to_result(s, cr) \
176 string_to_result_(desttype, s, cr)
187 memcpy(cr->
ib, data,
len);
189 memcpy(cr->
cb.
ib, data, len < cr->cb.len ?
len : cr->
cb.
len);
195 #define CASE_ALL_CHAR \
196 SYBCHAR: case SYBVARCHAR: case SYBTEXT: case XSYBCHAR: \
197 case XSYBVARCHAR: case SYBNVARCHAR: case SYBNTEXT: case XSYBNCHAR: \
199 #define CASE_ALL_BINARY \
200 SYBBINARY: case SYBVARBINARY: case SYBIMAGE: case XSYBBINARY: case XSYBVARBINARY: \
201 case SYBLONGBINARY: case TDS_CONVERT_BINARY
227 for (s = 0; cplen >= 2; ++s, cplen -= 2) {
250 for (s = 0; s < srclen; s++) {
273 memcpy(cr, src, srclen);
274 memset(((
char*) cr) + srclen, 0, cplen - srclen);
297 const TDS_CHAR * src,
size_t srclen)
300 unsigned char hex1, c = 0;
309 for (;
i < srclen; ++
i) {
312 if (
'0' <= hex1 && hex1 <=
'9')
316 if (
'A' <= hex1 && hex1 <=
'F') {
320 "error_handler: attempt to convert data stopped by syntax error in source field \n");
326 if ((
i/2u) >= destlen)
330 dest[
i / 2u] = c | hex1;
351 size_t digits, decimals;
355 memcpy(cr->
cc.
c, src, srclen < cr->cc.len ? srclen : cr->
cc.
len);
361 memcpy(cr->
c, src, srclen);
425 cr->
ti = tds_i ? 1 : 0;
440 for (; digits; --digits)
441 mynumber[
i++] = *src++;
443 for (digits = 0; digits < 4 && digits < decimals; ++digits)
444 mynumber[
i++] = *src++;
445 for (; digits < 4; ++digits)
489 if (srclen < (32 + 3))
493 TDS_UINT last = (src[8+1 + 4+1 + 4+1 + 4 + 1] ==
'-') ? 32+4+1 : 32+3+1;
494 if (srclen <=
last || src[
last] !=
'}')
503 for (
i = 0;
i < 32 + 3; ++
i) {
524 case 8+1 + 4+1 + 4+1 + 4:
527 if (--srclen < 32 + 3)
534 if (c >=
'0' && c <=
'9')
538 if (c >=
'A' && c <=
'F')
543 if (
i > (16 + 2) && !(
i & 1)) {
631 sprintf(tmp_str,
"%d", num);
675 cr->
ti = num ? 1 : 0;
687 if (num > 214748 || num < -214748)
689 cr->
m4.
mny4 = num * 10000;
722 memcpy(&
buf, src,
sizeof(
buf));
799 memcpy(&
buf, src,
sizeof(
buf));
904 if (((
i >> 15) ^ cr->
n.
array[0]) & 1)
930 if (((
i >> 31) ^ cr->
n.
array[0]) & 1)
957 if (((bi >> 63) ^ cr->
n.
array[0]) & 1)
994 if (((
i >> 31) ^ cr->
n.
array[0]) & 1)
1010 if (((bi >> 63) ^ cr->
n.
array[0]) & 1)
1026 cr->
f = atof(tmpstr);
1070 dollars = -(mny.
mny4 / 50 - 1 ) / 2;
1072 dollars = (mny.
mny4 / 50 + 1 ) / 2;
1075 sprintf(p,
"%ld.%02lu", dollars / 100, dollars % 100);
1080 dollars = mny.
mny4 / 10000;
1087 dollars = mny.
mny4 / 10000;
1094 dollars = mny.
mny4 / 10000;
1101 cr->
i = mny.
mny4 / 10000;
1105 dollars = mny.
mny4 / 10000;
1112 cr->
bi = mny.
mny4 / 10000;
1116 dollars = mny.
mny4 / 10000;
1124 cr->
ti = mny.
mny4 ? 1 : 0;
1179 if (mymoney <= -10000 || mymoney >= 256 * 10000)
1186 if (mymoney <= -32769 * 10000 || mymoney >= 32768 * 10000)
1192 if (mymoney <= -1 * 10000 || mymoney >= 65536 * 10000)
1198 dollars = mymoney / 10000;
1205 dollars = mymoney / 10000;
1212 cr->
bi = mymoney / 10000;
1216 dollars = mymoney / 10000;
1224 cr->
ti = mymoney ? 1 : 0;
1242 cr->
m.
mny = mymoney;
1265 char whole_date_string[64];
1334 char whole_date_string[64];
1363 memset(&cr->
dta, 0,
sizeof(cr->
dta));
1465 memset(&dta, 0,
sizeof(dta));
1468 dta.
time = *bigtime % ((
TDS_UINT8) 86400u * 1000000u) * 10u;
1485 memset(&dta, 0,
sizeof(dta));
1511 sprintf(tmp_str,
"%.9g", the_value);
1534 if (!
IS_INT((
double)the_value))
1540 if (!
IS_UINT((
double)the_value))
1559 cr->
ti = the_value ? 1 : 0;
1576 mymoney = (
TDS_INT8) (the_value * 10000);
1577 cr->
m.
mny = mymoney;
1584 mymoney4 = (
TDS_INT) (the_value * 10000);
1590 sprintf(tmp_str,
"%.*f", cr->
n.
scale, the_value);
1616 memcpy(&the_value, src, 8);
1620 sprintf(tmp_str,
"%.17g", the_value);
1668 cr->
ti = the_value ? 1 : 0;
1696 sprintf(tmp_str,
"%.16g", the_value);
1723 sprintf(
buf,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
1834 if (srclen >= 2 && src[0] ==
'0' && (src[1] ==
'x' || src[1] ==
'X')) {
1841 while (srclen > 0 && (src[srclen - 1] ==
' ' || src[srclen - 1] ==
'\0'))
1855 ? cr->
cb.
len : 0xffffffffu,
1886 assert(srclen >= 0 && srclen <= 2147483647u);
1982 #if !defined(WORDS_BIGENDIAN)
1983 if (length > 0 && desttype ==
SYBMONEY) {
1995 PUT_NUMERIC_IN_CONTEXT,
1996 DOING_ALPHABETIC_DATE,
2003 char last_token[32];
2010 unsigned int dt_time;
2016 memset(&
t,
'\0',
sizeof(
t));
2024 current_state = GOING_IN_BLIND;
2026 while (tok !=
NULL) {
2029 switch (current_state) {
2030 case GOING_IN_BLIND:
2039 current_state = DOING_ALPHABETIC_DATE;
2041 current_state = STRING_GARBLED;
2050 switch (strlen(tok)) {
2057 current_state = DOING_ALPHABETIC_DATE;
2066 strcpy(last_token, tok);
2067 current_state = PUT_NUMERIC_IN_CONTEXT;
2075 current_state = GOING_IN_BLIND;
2077 current_state = STRING_GARBLED;
2083 current_state = STRING_GARBLED;
2093 current_state = GOING_IN_BLIND;
2097 current_state = GOING_IN_BLIND;
2101 current_state = GOING_IN_BLIND;
2104 current_state = STRING_GARBLED;
2109 case DOING_ALPHABETIC_DATE:
2114 if (monthdone && yeardone && mdaydone)
2115 current_state = GOING_IN_BLIND;
2117 current_state = DOING_ALPHABETIC_DATE;
2119 current_state = STRING_GARBLED;
2122 if (mdaydone && yeardone)
2123 current_state = STRING_GARBLED;
2125 switch (strlen(tok)) {
2129 if (monthdone && yeardone && mdaydone)
2130 current_state = GOING_IN_BLIND;
2132 current_state = DOING_ALPHABETIC_DATE;
2141 if (monthdone && yeardone && mdaydone)
2142 current_state = GOING_IN_BLIND;
2144 current_state = DOING_ALPHABETIC_DATE;
2148 if (monthdone && yeardone && mdaydone)
2149 current_state = GOING_IN_BLIND;
2151 current_state = DOING_ALPHABETIC_DATE;
2156 current_state = STRING_GARBLED;
2159 current_state = STRING_GARBLED;
2164 case PUT_NUMERIC_IN_CONTEXT:
2171 if (monthdone && yeardone && mdaydone)
2172 current_state = GOING_IN_BLIND;
2174 current_state = DOING_ALPHABETIC_DATE;
2177 current_state = GOING_IN_BLIND;
2179 current_state = STRING_GARBLED;
2182 switch (strlen(tok)) {
2190 if (monthdone && yeardone && mdaydone)
2191 current_state = GOING_IN_BLIND;
2193 current_state = DOING_ALPHABETIC_DATE;
2197 current_state = STRING_GARBLED;
2200 current_state = STRING_GARBLED;
2205 case STRING_GARBLED:
2208 "error_handler: Attempt to convert data stopped by syntax error in source field \n");
2216 i = (
t.tm_mon - 13) / 12;
2217 dt_days = 1461 * (
t.tm_year + 1900 +
i) / 4 +
2218 (367 * (
t.tm_mon - 1 - 12 *
i)) / 12 - (3 * ((
t.tm_year + 2000 +
i) / 100)) / 4 +
t.tm_mday - 693932;
2226 dt_time =
t.tm_hour * 60 +
t.tm_min;
2233 dt_time = dt_time * 60 +
t.tm_sec;
2236 cr->
dt.
dttime = dt_time * 300 + (
t.tm_ns / 1000000u * 300 + 150) / 1000;
2240 cr->
time = dt_time * 300 + (
t.tm_ns / 1000000u * 300 + 150) / 1000;
2249 + dt_time * (
TDS_UINT8) 1000000u +
t.tm_ns / 1000u;
2284 size_t digits, decimals;
2311 for (
i = 0;
i < 8; ++
i)
2319 memcpy(ptr, instr, digits);
2321 instr += digits + 1;
2324 if (decimals > cr->
n.
scale)
2326 memcpy(ptr, instr, decimals);
2329 memset(ptr + decimals,
'0', cr->
n.
scale - decimals);
2345 for (
i = 1;
i < 8; ++
i)
2346 n =
n * 10u + *ptr++;
2348 packed_num[++j] =
n - ((
TDS_UINT)
'0' * 11111111lu);
2350 }
while (ptr > mynumber);
2354 while (j > 0 && !packed_num[j])
2358 bool is_zero =
true;
2375 packed_num[
i] = carry * (25u * 25u * 25u * 25u) +
tmp / 256u;
2384 cr->
n.
array[--bytes] = carry;
2398 for (instr =
t; *instr; instr++) {
2399 if (!
isdigit((
unsigned char) *instr) && *instr !=
'/' && *instr !=
'-' && *instr !=
'.')
2404 else if (*instr ==
'-')
2406 else if (*instr ==
'.')
2412 if (hyphens + slashes + periods != 2)
2414 if (hyphens == 1 || slashes == 1 || periods == 1)
2417 if (digits < 4 || digits > 8)
2438 if (!
isdigit((
unsigned char) *instr))
2443 if (!
isdigit((
unsigned char) *instr))
2448 if (*instr ==
'-') {
2462 if (!
isdigit((
unsigned char) *instr))
2466 if (!
isdigit((
unsigned char) *instr))
2472 if (!
isdigit((
unsigned char) *instr))
2476 if (!
isdigit((
unsigned char) *instr))
2489 if (!
isdigit((
unsigned char) *instr))
2493 if (!
isdigit((
unsigned char) *instr))
2498 if (!
isdigit((
unsigned char) *instr))
2502 if (!
isdigit((
unsigned char) *instr))
2528 for (s = datestr; *s; s++) {
2529 if (!
isalpha((
unsigned char) *s))
2540 for (s = datestr; *s; s++) {
2541 if (!
isdigit((
unsigned char) *s))
2552 for (s = datestr; *s; s++) {
2553 if (!
isdigit((
unsigned char) *s) && *s !=
':' && *s !=
'.')
2573 t->tm_year = 100 + year;
2581 t->tm_year = year - 1900;
2592 int mday = atoi(datestr);
2594 if (mday > 0 && mday < 32) {
2611 int month = 0, year = 0, mday = 0;
2615 if (strlen(datestr) == 10 && *(datestr + 4) ==
'-' && *(datestr + 7) ==
'-') {
2630 for (s = datestr; *s; s++) {
2631 if (!
isdigit((
unsigned char) *s) &&
isdigit((
unsigned char) last_char)) {
2634 if (
state == TDS_MONTH)
2635 month = (month * 10) + (*s -
'0');
2636 if (
state == TDS_DAY)
2637 mday = (mday * 10) + (*s -
'0');
2638 if (
state == TDS_YEAR)
2639 year = (year * 10) + (*s -
'0');
2644 if (month > 0 && month < 13)
2645 t->tm_mon = month - 1;
2648 if (mday > 0 && mday < 32)
2670 if (mday > 0 && mday < 32)
2675 if (datestr[2] ==
'-') {
2683 year = atoi(&datestr[7]);
2695 year = atoi(&datestr[5]);
2715 if (strlen(datestr) == 3) {
2745 else if (
strcasecmp(datestr,
"february") == 0)
2757 else if (
strcasecmp(datestr,
"september") == 0)
2759 else if (
strcasecmp(datestr,
"october") == 0)
2761 else if (
strcasecmp(datestr,
"november") == 0)
2763 else if (
strcasecmp(datestr,
"december") == 0)
2776 int month = 0, year = 0, mday = 0;
2780 wholedate = atoi(datestr);
2782 year = wholedate / 10000;
2783 month = (wholedate - (year * 10000)) / 100;
2784 mday = (wholedate - (year * 10000) - (month * 100));
2786 if (month > 0 && month < 13)
2787 t->tm_mon = month - 1;
2790 if (mday > 0 && mday < 32)
2809 int state = TDS_HOURS;
2810 char last_sep =
'\0';
2812 unsigned int hours = 0, minutes = 0, seconds = 0, nanosecs = 0;
2814 unsigned ns_div = 1;
2816 for (s = datestr; *s && strchr(
"apmAPM", (
int) *s) ==
NULL; s++) {
2817 if (*s ==
':' || *s ==
'.') {
2821 if (*s < '0' || *s >
'9')
2825 hours = (hours * 10u) + (*s -
'0');
2828 minutes = (minutes * 10u) + (*s -
'0');
2831 seconds = (seconds * 10u) + (*s -
'0');
2834 if (ns_div < 1000000000u) {
2835 nanosecs = (nanosecs * 10u) + (*s -
'0');
2852 if (hours > 0u && hours < 12u)
2853 t->tm_hour = hours + 12;
2864 t->tm_min = minutes;
2868 t->tm_sec = seconds;
2873 if (nanosecs < ns_div && last_sep ==
'.')
2874 t->tm_ns = nanosecs * (1000000000u / ns_div);
2875 else if (nanosecs < 1000u)
2876 t->tm_ns = nanosecs * 1000000u;
2892 if (hours >= 0 && hours < 24) {
2902 if (hours > 0 && hours < 12)
2903 t->tm_hour = hours + 12;
2983 assert(0 <=
dr->decimicrosecond &&
dr->decimicrosecond < 10000000);
2984 if (prec < 0 || prec > 7)
2987 tm.tm_sec =
dr->second;
2988 tm.tm_min =
dr->minute;
2989 tm.tm_hour =
dr->hour;
2990 tm.tm_mday =
dr->day;
2991 tm.tm_mon =
dr->month;
2992 tm.tm_year =
dr->year - 1900;
2993 tm.tm_wday =
dr->weekday;
2994 tm.tm_yday =
dr->dayofyear;
2996 #ifdef HAVE_STRUCT_TM_TM_ZONE
2998 #elif defined(HAVE_STRUCT_TM___TM_ZONE)
2999 tm.__tm_zone =
NULL;
3007 strcpy(our_format,
format);
3015 for (pz = our_format; (pz = strstr(pz,
"%z")) !=
NULL; pz++) {
3017 if (pz > our_format && *(pz - 1) !=
'%')
3022 if (prec || pz <= our_format || pz[-1] !=
'.') {
3024 sprintf(
buf,
"%07d",
dr->decimicrosecond);
3025 memcpy(pz,
buf, prec);
3026 strcpy(pz + prec,
format + (pz - our_format) + 2);
3028 strcpy(pz - 1,
format + (pz - our_format) + 2);
3032 length = strftime(
buf, maxsize, our_format, &tm);
3068 if (((srctype|desttype) & ~0xff) != 0)
3075 yn = (yn >> cat_to) & 1;
3078 srctype, desttype, yn?
"yes":
"no");
3083 select day(d) as day, datepart(dw, d) as weekday, datepart(week, d) as week, d as
'date' from #
t order by d
3084 day weekday week date
3085 ----------- ----------- ----------- ----------
3086 1 5 1 2009-01-01 Thursday
3087 2 6 1 2009-01-02 Friday
3088 3 7 1 2009-01-03 Saturday
3089 4 1 2 2009-01-04 Sunday
3129 unsigned int dt_time;
3131 int years,
months, days, ydays, wday, hours, mins, secs, dms, tzone = 0;
3134 memset(
dr, 0,
sizeof(*
dr));
3145 dms = dta->
time % 10000000u;
3146 dt_time = (
unsigned int) (dta->
time / 10000000u);
3147 secs = dt_time % 60;
3148 dt_time = dt_time / 60;
3152 dt_time = dt_time + 1440 + dta->
offset;
3153 dt_days += dt_time / 1440;
3160 dms = ((dt_time % 300) * 1000 + 150) / 300 * 10000u;
3161 dt_time = dt_time / 300;
3162 secs = dt_time % 60;
3163 dt_time = dt_time / 60;
3169 dt_days = dt4->
days;
3171 }
else if (datetype ==
SYBDATE) {
3172 dt_days = *((
const TDS_DATE *) di);
3176 }
else if (datetype ==
SYBTIME) {
3177 dt_time = *((
const TDS_TIME *) di);
3178 dms = ((dt_time % 300) * 1000 + 150) / 300 * 10000u;
3179 dt_time = dt_time / 300;
3180 secs = dt_time % 60;
3181 dt_time = dt_time / 60;
3186 dms = bigtime % 1000000u * 10u;
3187 dt_time = (bigtime / 1000000u) % 86400u;
3188 secs = dt_time % 60;
3189 dt_time = dt_time / 60u;
3192 dms = bigdatetime % 1000000u * 10u;
3193 bigdatetime /= 1000000u;
3194 secs = bigdatetime % 60u;
3196 dt_time = bigdatetime % (24u*60u);
3206 l = dt_days + (146038 + 146097*4);
3208 n = (4 * l) / 146097;
3209 l = l - (146097 *
n + 3) / 4;
3210 i = (4000 * (l + 1)) / 1461001;
3211 l = l - (1461 *
i) / 4;
3212 ydays = l >= 306 ? l - 305 : l + 60;
3214 j = (80 * l) / 2447;
3215 days = l - (2447 * j) / 80;
3218 years = 100 * (
n - 1) +
i + l;
3219 if (l == 0 && (years & 3) == 0 && (years % 100 != 0 || years % 400 == 0))
3222 hours = dt_time / 60;
3223 mins = dt_time % 60;
3229 dr->dayofyear = ydays;
3234 dr->decimicrosecond = dms;
3235 dr->timezone = tzone;
3257 size_t digits, decimals;
3264 for (; digits; --digits, ++
buf) {
3267 if (num > 214748364u)
3269 num = num * 10u + (*
buf -
'0');
3274 if (num > 2147483648u)
3278 if (num >= 2147483648u)
3295 size_t digits, decimals;
3302 for (; digits; --digits, ++
buf) {
3305 if (num > (((
TDS_UINT8) 1u) << 63) / 5u)
3307 num = num * 10u + (*
buf -
'0');
3389 parse_numeric(
const char *
buf,
const char *pend,
bool *p_negative,
size_t *p_digits,
size_t *p_decimals)
3391 enum { blank =
' ' };
3392 #define SKIP_IF(cond) while (p != pend && (cond)) ++p;
3393 const char *p, *start;
3402 *p_negative =
false;
3433 *p_digits = p - start;
3436 if (p != pend && *p ==
'.') {
3437 const char *decimals_start = ++p;
3439 *p_decimals = p - decimals_start;
3458 while (srclen > 0 && src[0] ==
' ')
3462 while (srclen > 0 && (src[srclen - 1] ==
' ' || src[srclen - 1] ==
'\0'))
3465 if (srclen >=
sizeof(tmpstr))
3468 memcpy(tmpstr, src, srclen);
3472 res = strtod(tmpstr, &end);
3473 if (errno == ERANGE)
3475 if (end != tmpstr + srclen)
#define TDS_GET_UA4BE(ptr)
#define TDS_GET_UA2BE(ptr)
#define TDS_PUT_UA4BE(ptr, val)
#define TDS_CONVERT_SYNTAX
#define TDS_CONVERT_BINARY
#define TDS_CONVERT_OVERFLOW
#define TDS_CONVERT_NOAVAIL
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static TDS_INT tds_convert_int(TDS_INT num, int desttype, CONV_RESULT *cr)
static TDS_INT string_to_int(const char *buf, const char *pend, TDS_INT *res)
convert a number in string to TDS_INT
static bool is_numeric(const char *)
#define string_to_result(s, cr)
static TDS_INT tds_convert_real(const TDS_REAL *src, int desttype, CONV_RESULT *cr)
static TDS_INT string_to_result_(int desttype, const char *s, CONV_RESULT *cr)
Copy a terminated string to result and return len or TDS_CONVERT_NOMEM.
static TDS_INT tds_convert_bigdatetime(const TDSCONTEXT *tds_ctx, const TDS_BIGDATETIME *bigdatetime, int desttype, CONV_RESULT *cr)
static int store_monthname(const char *, struct tds_time *)
Test if a string is a month name and store correct month number.
static TDS_INT tds_convert_bit(const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_int_numeric(unsigned char scale, unsigned char sign, TDS_UINT num, CONV_RESULT *cr)
static TDS_INT tds_convert_int1(const TDS_TINYINT *src, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_money(const TDS_MONEY *src, int desttype, CONV_RESULT *cr)
static int string_to_numeric(const char *instr, const char *pend, CONV_RESULT *cr)
convert a number in string to a TDSNUMERIC
static int store_time(const char *, struct tds_time *)
static TDS_INT string_to_float(const TDS_CHAR *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_datetimeall(const TDSCONTEXT *tds_ctx, int srctype, const TDS_DATETIMEALL *dta, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_date(const TDSCONTEXT *tds_ctx, const TDS_DATE *date, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_unique(const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static int stringz_to_numeric(const char *instr, CONV_RESULT *cr)
convert a zero terminated string to NUMERIC
static int string_to_datetime(const char *datestr, TDS_UINT len, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_uint8(const TDS_UINT8 *src, int desttype, CONV_RESULT *cr)
static bool is_dd_mon_yyyy(char *t)
static bool is_ampm(const char *)
static const char * parse_numeric(const char *buf, const char *pend, bool *p_negative, size_t *p_digits, size_t *p_decimals)
Parse a string for numbers.
static TDS_INT tds_convert_bigtime(const TDSCONTEXT *tds_ctx, const TDS_BIGTIME *bigtime, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_datetime4(const TDSCONTEXT *tds_ctx, const TDS_DATETIME4 *dt4, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_uint2(const TDS_USMALLINT *src, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_char(const TDS_CHAR *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
TDS_SERVER_TYPE tds_get_null_type(TDS_SERVER_TYPE srctype)
Get same type but nullable.
static bool is_timeformat(const char *)
static int store_year(int, struct tds_time *)
static int store_yymmdd_date(const char *, struct tds_time *)
static TDS_INT tds_convert_int8_numeric(unsigned char scale, unsigned char sign, TDS_UINT8 num, CONV_RESULT *cr)
unsigned char tds_willconvert(int srctype, int desttype)
Test if a conversion is possible.
TDSRET tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC *dr)
Convert from db date format to a structured date format.
static TDS_INT tds_convert_time(const TDSCONTEXT *tds_ctx, const TDS_TIME *time, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_datetime(const TDSCONTEXT *tds_ctx, const TDS_DATETIME *dt, int desttype, unsigned precision, CONV_RESULT *cr)
size_t tds_strftime(char *buf, size_t maxsize, const char *format, const TDSDATEREC *dr, int prec)
format a date string according to an "extended" strftime(3) formatting definition.
ssize_t tds_char2hex(TDS_CHAR *dest, size_t destlen, const TDS_CHAR *src, size_t srclen)
static TDS_INT string_to_int8(const char *buf, const char *pend, TDS_INT8 *res)
convert a number in string to TDS_INT8
static TDS_INT tds_convert_money4(const TDS_MONEY4 *src, int desttype, CONV_RESULT *cr)
TDS_INT tds_convert(const TDSCONTEXT *tds_ctx, int srctype, const TDS_CHAR *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
tds_convert convert a type to another.
static TDS_INT tds_convert_int2(const TDS_SMALLINT *src, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_flt8(const TDS_FLOAT *src, int desttype, CONV_RESULT *cr)
static TDS_INT binary_to_result(int desttype, const void *data, size_t len, CONV_RESULT *cr)
Copy binary data to to result and return len or TDS_CONVERT_NOMEM.
static TDS_INT tds_convert_binary(const TDS_UCHAR *src, TDS_INT srclen, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_numeric(const TDS_NUMERIC *src, int desttype, CONV_RESULT *cr)
static TDS_INT tds_convert_uint4(const TDS_UINT *src, int desttype, CONV_RESULT *cr)
static int store_dd_mon_yyy_date(char *datestr, struct tds_time *t)
static TDS_INT tds_convert_to_binary(int srctype, const TDS_CHAR *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
static int store_hour(const char *, const char *, struct tds_time *)
static TDS_INT parse_int8(const char *buf, const char *pend, TDS_UINT8 *res, bool *p_negative)
convert a number in string to TDS_INT8
static TDS_INT tds_convert_int8(const TDS_INT8 *src, int desttype, CONV_RESULT *cr)
static bool is_numeric_dateformat(const char *)
static bool is_alphabetic(const char *)
static TDS_INT string_to_uint8(const char *buf, const char *pend, TDS_UINT8 *res)
convert a number in string to TDS_UINT8
const char tds_hex_digits[]
static int store_numeric_date(const char *, struct tds_time *)
static int store_mday(const char *, struct tds_time *)
static TDS_INT tds_convert_int4(const TDS_INT *src, int desttype, CONV_RESULT *cr)
unsigned int
A callback function used to compare two keys in a database.
if(yy_accept[yy_current_state])
std::istream & in(std::istream &in_, double &x_)
struct tdsdatetime4 TDS_DATETIME4
struct tdsunique TDS_UNIQUE
TDS_UINT8 TDS_BIGDATETIME
struct tdsnumeric TDS_NUMERIC
struct tdsmoney4 TDS_MONEY4
struct tdsdatetime TDS_DATETIME
#define tds_numeric_to_string
#define tds_get_size_by_type
#define tds_money_to_string
#define tds_numeric_bytes_per_prec
#define tds_numeric_change_prec_scale
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
TDS_INT date
date, 0 = 1900-01-01
TDS_SMALLINT offset
time offset
TDS_UINT8 time
time, 7 digit precision
int tm_ns
nanoseconds (0-999999999)
int tm_mday
month day (1-31)
Store variant informations.
#define SYBMSDATETIMEOFFSET
Main include file for libtds.
tds_sysdep_int32_type TDS_INT
tds_sysdep_real64_type TDS_FLOAT
tds_sysdep_int64_type TDS_INT8
tds_sysdep_real32_type TDS_REAL
unsigned char TDS_TINYINT
tds_sysdep_int16_type TDS_SMALLINT
tds_sysdep_uint64_type TDS_UINT8
tds_sysdep_uint16_type TDS_USMALLINT
tds_sysdep_uint32_type TDS_UINT
static const TDS_UINT category_conversion[]
static const TDS_TINYINT type2category[256]
struct conv_result::cb_t cb
struct conv_result::cc_t cc
TDS_BIGDATETIME bigdatetime
TDS_OLD_MONEY tdsoldmoney