Defines | Functions | Variables

# Conversion
[LibTDS API]

Conversions between datatypes. More...

## Defines
#define | binary_to_result(data, len, cr) binary_to_result(desttype, data, len, cr)
#define | CASE_ALL_BINARY SYBBINARY: case SYBVARBINARY: case SYBIMAGE: case XSYBBINARY: case XSYBVARBINARY: case TDS_CONVERT_BINARY
#define | CASE_ALL_CHAR SYBCHAR: case SYBVARCHAR: case SYBTEXT: case XSYBCHAR: case XSYBVARCHAR
#define | is_monthname(s) (store_monthname(s, NULL) >= 0)
#define | string_to_result(s, cr) string_to_result(desttype, s, cr)
## Functions
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 int | is_alphabetic (const char *)
static int | is_ampm (const char *)
static int | is_dd_mon_yyyy (char *t)
static int | is_numeric (const char *)
static int | is_numeric_dateformat (const char *)
static int | is_timeformat (const char *)
static int | store_dd_mon_yyy_date (char *datestr, struct tds_time *t)
static int | store_hour (const char *, const char *, struct tds_time *)
static int | store_mday (const char *, struct tds_time *)
static int | store_monthname (const char *datestr, struct tds_time *t)
| Test if a string is a month name and store correct month number.
static int | store_numeric_date (const char *, struct tds_time *)
static int | store_time (const char *, struct tds_time *)
static int | store_year (int, struct tds_time *)
static int | store_yymmdd_date (const char *, struct tds_time *)
static int | string_to_datetime (const char *datestr, 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 TDS_INT | string_to_int8 (const char *buf, const char *pend, TDS_INT8 *res)
| convert a number in string to TDS_INT8
static int | string_to_numeric (const char *instr, const char *pend, CONV_RESULT *cr)
| convert a number in string to a TDSNUMERIC
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 int | stringz_to_numeric (const char *instr, CONV_RESULT *cr)
| convert a zero terminated string to NUMERIC
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_binary (int srctype, const TDS_UCHAR *src, TDS_INT srclen, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_bit (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_char (int srctype, const TDS_CHAR *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_datetime (const TDSCONTEXT *tds_ctx, int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_datetime4 (const TDSCONTEXT *tds_ctx, int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_flt8 (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_int1 (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_int2 (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_int4 (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_int8 (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_money (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_money4 (int srctype, const TDS_CHAR *src, int srclen, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_numeric (int srctype, const TDS_NUMERIC *src, TDS_INT srclen, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_real (int srctype, const TDS_CHAR *src, int desttype, CONV_RESULT *cr)
static TDS_INT | tds_convert_unique (int srctype, const TDS_CHAR *src, TDS_INT srclen, int desttype, CONV_RESULT *cr)
TDS_INT | tds_datecrack (TDS_INT datetype, const void *di, TDSDATEREC *dr)
| Convert from db date format to a structured date format.
int | tds_get_conversion_type (int srctype, int colsize)
| Return type suitable for conversions (convert all nullable types to fixed type)
TDS_INT | tds_get_null_type (int srctype)
| Get same type but nullable.
size_t | tds_strftime (char *buf, size_t maxsize, const char *format, const TDSDATEREC *dr)
| format a date string according to an "extended" strftime(3) formatting definition.
unsigned char | tds_willconvert (int srctype, int desttype)
| Test if a conversion is possible.
## Variables
const char | tds_hex_digits [16] = "0123456789abcdef"

## Detailed Description

Conversions between datatypes.

Supports, for example, dbconvert().

## Function Documentation

static int store_monthname | ( | const char * | datestr,
|  | struct tds_time * | t
| ) |  | `[static]`

Test if a string is a month name and store correct month number.

Returns:
  month number (0-11) or -1 if not match

Parameters:

  datestr | string to check
  t | where to store month (if NULL no store is done)

static TDS_INT string_to_int | ( | const char * | buf,
|  | const char * | pend,
|  | TDS_INT * | res
| ) |  | `[static]`

convert a number in string to TDS_INT

Returns:
  TDS_CONVERT_* or failure code on error

Remarks:
  Sybase's char->int conversion tolerates embedded blanks, such that "convert( int, ' - 13 ' )" works. If we find blanks, we copy the string to a temporary buffer, skipping the blanks. We return the results of atoi() with a clean string.

n.b. it is possible to embed all sorts of non-printable characters, but we only check for spaces. at this time, no one on the project has tested anything else.

static TDS_INT string_to_int8 | ( | const char * | buf,
|  | const char * | pend,
|  | TDS_INT8 * | res
| ) |  | `[static]`

convert a number in string to TDS_INT8

Returns:
  TDS_CONVERT_* or failure code on error

static int string_to_numeric | ( | const char * | instr,
|  | const char * | pend,
|  | CONV_RESULT * | cr
| ) |  | `[static]`

convert a number in string to a TDSNUMERIC

Returns:
  sizeof(TDS_NUMERIC) on success, TDS_CONVERT_* failure code on failure

static int stringz_to_numeric | ( | const char * | instr,
|  | CONV_RESULT * | cr
| ) |  | `[static]`

convert a zero terminated string to NUMERIC

Returns:
  sizeof(TDS_NUMERIC) on success, TDS_CONVERT_* failure code on failure

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.

If you convert to SYBDECIMAL/SYBNUMERIC you MUST initialize precision and scale of cr. Do not expect strings to be zero terminated. Databases support zero inside string. Using strlen may result on data loss or even a segmentation fault. Instead, use memcpy to copy destination using length returned. This function does not handle NULL, srclen should be >0. Client libraries handle NULLs each in their own way.

Parameters:

  tds_ctx | context (used in conversion to data and to return messages)
  srctype | type of source
  src | pointer to source data to convert
  srclen | length in bytes of source (not counting terminator or strings)
  desttype | type of destination
  cr | structure to hold result

Returns:
  length of result or TDS_CONVERT_* failure code on failure. All TDS_CONVERT_* constants are <0.

TDS_INT tds_datecrack | ( | TDS_INT | datetype,
|  | const void * | di,
|  | TDSDATEREC * | dr
| ) |  |

Convert from db date format to a structured date format.

Parameters:

  datetype | source date type. SYBDATETIME or SYBDATETIME4
  di | source date
  dr | destination date

Returns:
  TDS_FAIL or TDS_SUCCEED

int tds_get_conversion_type | ( | int | srctype,
|  | int | colsize
| ) |  |

Return type suitable for conversions (convert all nullable types to fixed type)

Parameters:

  srctype | type to convert
  colsize | size of type

Returns:
  type for conversion

TDS_INT tds_get_null_type | ( | int | srctype ) |

Get same type but nullable.

Parameters:

  srctype | type requires

Returns:
  nullable type

size_t tds_strftime | ( | char * | buf,
|  | size_t | maxsize,
|  | const char * | format,
|  | const TDSDATEREC * | dr
| ) |  |

format a date string according to an "extended" strftime(3) formatting definition.

Parameters:

  buf | output buffer
  maxsize | size of buffer in bytes (space include terminator)
  format | format string passed to strftime(3), except that z represents milliseconds
  dr | date to convert

Returns:
  length of string returned, 0 for error

unsigned char tds_willconvert | ( | int | srctype,
|  | int | desttype
| ) |  |

Test if a conversion is possible.

Parameters:

  srctype | source type
  desttype | destination type

Returns:
  0 if not convertible

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines