Skip to content

Commit

Permalink
Handle big(date)time types coming from the server
Browse files Browse the repository at this point in the history
Add type to misc/types.csv to handle base information on types.
Add data structure and functions to handle type from/to server.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
  • Loading branch information
freddy77 committed Sep 21, 2015
1 parent a74a06e commit 680cb33
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/freetds/data.h
Expand Up @@ -77,6 +77,14 @@ tds_func_put_info tds_clrudt_put_info;
#define tds_clrudt_put tds_generic_put
tds_func_check tds_clrudt_check;

tds_func_get_info tds_sybbigtime_get_info;
tds_func_row_len tds_sybbigtime_row_len;
tds_func_get_data tds_sybbigtime_get;
tds_func_put_info_len tds_sybbigtime_put_info_len;
tds_func_put_info tds_sybbigtime_put_info;
tds_func_put_data tds_sybbigtime_put;
tds_func_check tds_sybbigtime_check;

/**
* If TDS_DONT_DEFINE_DEFAULT_FUNCTIONS is no defined
* define default implementations for these tables
Expand All @@ -90,6 +98,7 @@ TDS_DEFINE_DEFAULT_FUNCS(numeric);
TDS_DEFINE_DEFAULT_FUNCS(variant);
TDS_DEFINE_DEFAULT_FUNCS(msdatetime);
TDS_DEFINE_DEFAULT_FUNCS(clrudt);
TDS_DEFINE_DEFAULT_FUNCS(sybbigtime);
#endif

#include <freetds/popvis.h>
Expand Down
2 changes: 2 additions & 0 deletions misc/types.csv
@@ -1,4 +1,6 @@
Name;vendor;varint;fixed;nullable;variable;blob;numeric;collate;unicode;ascii;datetime;size;nullable type;display size;
SYB5BIGTIME;SYB;1;0;1;0;0;0;0;0;0;1;8;0;15;
SYB5BIGDATETIME;SYB;1;0;1;0;0;0;0;0;0;1;8;0;26;
SYB5INT8;SYB;0;1;0;0;0;0;0;0;0;0;8;SYBINTN;20;
SYBBINARY;ALL;1;0;0;1;0;0;0;0;0;0;-1;0;2*S;
SYBBIT;ALL;0;1;0;0;0;0;0;0;0;0;1;SYBBITN;1;
Expand Down
86 changes: 86 additions & 0 deletions src/tds/data.c
Expand Up @@ -1253,13 +1253,93 @@ tds_clrudt_put_info(TDSSOCKET * tds, TDSCOLUMN * col)
return TDS_SUCCESS;
}

TDSRET
tds_sybbigtime_get_info(TDSSOCKET * tds, TDSCOLUMN * col)
{
col->column_scale = col->column_prec = 6;
tds_get_byte(tds); /* 8, size */
tds_get_byte(tds); /* 6, precision ?? */
col->on_server.column_size = col->column_size = sizeof(TDS_UINT8);
return TDS_SUCCESS;
}

TDS_INT
tds_sybbigtime_row_len(TDSCOLUMN *col)
{
return sizeof(TDS_UINT8);
}

TDSRET
tds_sybbigtime_get(TDSSOCKET * tds, TDSCOLUMN * col)
{
TDS_UINT8 *dt = (TDS_UINT8 *) col->column_data;
int size = tds_get_byte(tds);

if (size == 0) {
col->column_cur_size = -1;
return TDS_SUCCESS;
}

col->column_cur_size = sizeof(TDS_UINT8);
*dt = tds_get_int8(tds);

return TDS_SUCCESS;
}

TDSRET
tds_sybbigtime_put_info(TDSSOCKET * tds, TDSCOLUMN * col)
{
tds_put_byte(tds, 8);
tds_put_byte(tds, 6);
return TDS_SUCCESS;
}

unsigned
tds_sybbigtime_put_info_len(TDSSOCKET * tds, TDSCOLUMN * col)
{
return 2;
}

TDSRET
tds_sybbigtime_put(TDSSOCKET *tds, TDSCOLUMN *col, int bcp7)
{
const TDS_UINT8 *dt = (const TDS_UINT8 *) col->column_data;

if (col->column_cur_size < 0) {
tds_put_byte(tds, 0);
return TDS_SUCCESS;
}

tds_put_byte(tds, 8);
tds_put_int8(tds, *dt);

return TDS_SUCCESS;
}

#if ENABLE_EXTRA_CHECKS
int
tds_generic_check(const TDSCOLUMN *col)
{
return 0;
}

int
tds_sybbigtime_check(const TDSCOLUMN *col)
{
assert(col->column_type == col->on_server.column_type);
assert(col->on_server.column_size == col->column_size);
assert(!is_numeric_type(col->column_type));
assert(!is_fixed_type(col->column_type));
assert(!is_blob_type(col->column_type));
assert(!is_variable_type(col->column_type));
assert(is_nullable_type(col->column_type));
assert(col->column_varint_size == 1);
assert(col->column_prec == 6);
assert(col->column_scale == col->column_prec);

return 1;
}

int
tds_clrudt_check(const TDSCOLUMN *col)
{
Expand Down Expand Up @@ -1320,6 +1400,7 @@ TDS_DECLARE_FUNCS(numeric);
TDS_DECLARE_FUNCS(variant);
TDS_DECLARE_FUNCS(msdatetime);
TDS_DECLARE_FUNCS(clrudt);
TDS_DECLARE_FUNCS(sybbigtime);
#include <freetds/popvis.h>

static const TDSCOLUMNFUNCS *
Expand All @@ -1340,6 +1421,9 @@ tds_get_column_funcs(TDSCONNECTION *conn, int type)
case SYBMSDATETIME2:
case SYBMSDATETIMEOFFSET:
return &tds_msdatetime_funcs;
case SYB5BIGTIME:
case SYB5BIGDATETIME:
return &tds_sybbigtime_funcs;
}
return &tds_generic_funcs;
}
Expand Down Expand Up @@ -1369,6 +1453,8 @@ tds_swap_datatype(int coltype, void *b)
break;
case SYBINT8:
case SYBFLT8:
case SYB5BIGTIME:
case SYB5BIGDATETIME:
tds_swap_bytes(buf, 8);
break;
case SYBUNIQUE:
Expand Down

0 comments on commit 680cb33

Please sign in to comment.