FreeTDS API: Memory allocation

FreeTDS API

Macros | Functions | Variables
Memory allocation
LibTDS API

Allocate or free resources. More...

Collaboration diagram for Memory allocation:

## Macros
#define | REQ(i, n) |(((TDS_REQ_ ## n / 8) == i)?(1<<(TDS_REQ_ ## n & 7)):0)
#define | REQB(i) 0 SUPPORTED_REQ_CAP(i)
#define | RES(i, n) |(((TDS_RES_ ## n / 8) == i)?(1<<(TDS_RES_ ## n & 7)):0)
#define | RESB(i) 0 SUPPORTED_RES_CAP(i)
#define | SQLS_ENTRY(number, state) case number: p = state; break
#define | SUPPORTED_REQ_CAP(i)
#define | SUPPORTED_RES_CAP(i) RES(i,CON_NOOOB) RES(i,PROTO_NOTEXT) RES(i,PROTO_NOBULK) RES(i,NOTDSDEBUG)

## Functions
BCPCOLDATA * | tds_alloc_bcp_column_data (unsigned int column_size)
TDSBCPINFO * | tds_alloc_bcpinfo (void)
char * | tds_alloc_client_sqlstate (int msgno)
static TDSCOLUMN * | tds_alloc_column (void)
static TDSCOMPUTEINFO * | tds_alloc_compute_result (TDS_USMALLINT num_cols, TDS_USMALLINT by_cols)
| Allocate memory for storing compute info return NULL on out of memory.
TDSCOMPUTEINFO ** | tds_alloc_compute_results (TDSSOCKET *tds, TDS_USMALLINT num_cols, TDS_USMALLINT by_cols)
TDSRET | tds_alloc_compute_row (TDSCOMPUTEINFO *res_info)
TDSCONTEXT * | tds_alloc_context (void *parent)
TDSCURSOR * | tds_alloc_cursor (TDSSOCKET *tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen)
TDSDYNAMIC * | tds_alloc_dynamic (TDSCONNECTION *conn, const char *id)
| Allocate a dynamic statement. More...
TDSLOCALE * | tds_alloc_locale (void)
TDSLOGIN * | tds_alloc_login (int use_environment)
char * | tds_alloc_lookup_sqlstate (TDSSOCKET *tds, int msgno)
TDSPACKET * | tds_alloc_packet (void *buf, unsigned len)
void * | tds_alloc_param_data (TDSCOLUMN *curparam)
| Allocate data for a parameter. More...
TDSPARAMINFO * | tds_alloc_param_result (TDSPARAMINFO *old_param)
| Adds a output parameter to TDSPARAMINFO. More...
TDSRESULTINFO * | tds_alloc_results (TDS_USMALLINT num_cols)
TDSRET | tds_alloc_row (TDSRESULTINFO *res_info)
| Allocate space for row store return NULL on out of memory.
TDSSOCKET * | tds_alloc_socket (TDSCONTEXT *context, unsigned int bufsize)
| TDS_COMPILE_CHECK (tds_cap_len, sizeof(defaultcaps)==TDS_MAX_CAPABILITY)
| TDS_COMPILE_CHECK (tds_values_len, sizeof(defaultcaps.types[0].values)==14)
static void | tds_connection_remove_socket (TDSCONNECTION *conn, TDSSOCKET *tds)
void | tds_cursor_deallocated (TDSCONNECTION *conn, TDSCURSOR *cursor)
void | tds_deinit_bcpinfo (TDSBCPINFO *bcpinfo)
static void | tds_deinit_connection (TDSCONNECTION *conn)
void | tds_detach_results (TDSRESULTINFO *info)
| Detach result info from it current socket.
void | tds_dynamic_deallocated (TDSCONNECTION *conn, TDSDYNAMIC *dyn)
void | tds_free_all_results (TDSSOCKET *tds)
void | tds_free_bcp_column_data (BCPCOLDATA *coldata)
void | tds_free_bcpinfo (TDSBCPINFO *bcpinfo)
static void | tds_free_column (TDSCOLUMN *col)
static void | tds_free_compute_result (TDSCOMPUTEINFO *comp_info)
static void | tds_free_compute_results (TDSSOCKET *tds)
void | tds_free_context (TDSCONTEXT *context)
static void | tds_free_env (TDSCONNECTION *conn)
void | tds_free_input_params (TDSDYNAMIC *dyn)
| Frees all allocated input parameters of a dynamic statement. More...
void | tds_free_locale (TDSLOCALE *locale)
void | tds_free_login (TDSLOGIN *login)
void | tds_free_msg (TDSMESSAGE *message)
void | tds_free_packets (TDSPACKET *packet)
void | tds_free_param_result (TDSPARAMINFO *param_info)
| Delete latest parameter.
void | tds_free_param_results (TDSPARAMINFO *param_info)
void | tds_free_results (TDSRESULTINFO *res_info)
void | tds_free_row (TDSRESULTINFO *res_info, unsigned char *row)
void | tds_free_socket (TDSSOCKET *tds)
static char * | tds_get_dynid (TDSCONNECTION *conn, char *id)
| Get an id for dynamic query based on TDS information. More...
static TDSCONNECTION * | tds_init_connection (TDSCONNECTION *conn, TDSCONTEXT *context, unsigned int bufsize)
TDSLOGIN * | tds_init_login (TDSLOGIN *login, TDSLOCALE *locale)
| Initialize login structure with locale information and other stuff for connection. More...
static TDSSOCKET * | tds_init_socket (TDSSOCKET *tds_socket, unsigned int bufsize)
static void | tds_param_free (TDSCOLUMN *col)
void * | tds_realloc (void **pp, size_t new_size)
| Reallocate a pointer and update it if success. More...
TDSPACKET * | tds_realloc_packet (TDSPACKET *packet, unsigned len)
TDSSOCKET * | tds_realloc_socket (TDSSOCKET *tds, size_t bufsize)
void | tds_release_cursor (TDSCURSOR **pcursor)
void | tds_release_dynamic (TDSDYNAMIC **pdyn)
| Frees dynamic statement. More...
static void | tds_row_free (TDSRESULTINFO *res_info, unsigned char *row)
void | tds_set_current_results (TDSSOCKET *tds, TDSRESULTINFO *info)
static int | winsock_initialized (void)

## Variables
static const TDS_CAPABILITIES | defaultcaps
static volatile unsigned int | inc_num = 1
const TDSCOLUMNFUNCS | tds_invalid_funcs

## Detailed Description

Allocate or free resources.

Allocation can fail only on out of memory. In such case they return NULL and leave the state as before call. Mainly function names are in the form tds_alloc_XX or tds_free_XXX. tds_alloc_XXX functions allocate structures and return pointer to allocated data while tds_free_XXX take structure pointers and free them. Some functions require additional parameters to initialize structure correctly. The main exception are structures that use reference counting. These structures have tds_alloc_XXX functions but instead of tds_free_XXX use tds_release_XXX.

## Macro Definition Documentation

## ◆ SUPPORTED_REQ_CAP

#define SUPPORTED_REQ_CAP | ( |  | i | ) |

Value:
REQ(i,LANG) REQ(i,RPC) REQ(i,EVT) REQ(i,MSTMT) REQ(i,BCP) REQ(i,CURSOR) REQ(i,DYNF) \
REQ(i,MSG) REQ(i,PARAM) REQ(i,DATA_INT1) REQ(i,DATA_INT2) REQ(i,DATA_INT4) REQ(i,DATA_BIT) \
REQ(i,DATA_CHAR) REQ(i,DATA_VCHAR) REQ(i,DATA_BIN) REQ(i,DATA_VBIN) REQ(i,DATA_MNY8) \
REQ(i,DATA_MNY4) REQ(i,DATA_DATE8) REQ(i,DATA_DATE4) REQ(i,DATA_FLT4) REQ(i,DATA_FLT8) \
REQ(i,DATA_NUM) REQ(i,DATA_TEXT) REQ(i,DATA_IMAGE) REQ(i,DATA_DEC) REQ(i,DATA_LCHAR) \
REQ(i,DATA_LBIN) REQ(i,DATA_INTN) REQ(i,DATA_DATETIMEN) REQ(i,DATA_MONEYN) \
REQ(i,CSR_PREV) REQ(i,CSR_FIRST) REQ(i,CSR_LAST) REQ(i,CSR_ABS) REQ(i,CSR_REL) \
REQ(i,CSR_MULTI) REQ(i,CON_INBAND) REQ(i,PROTO_TEXT) REQ(i,PROTO_BULK) \
REQ(i,DATA_SENSITIVITY) REQ(i,DATA_BOUNDARY) REQ(i,PROTO_DYNPROC) REQ(i,DATA_FLTN) \
REQ(i,DATA_BITN) REQ(i,DATA_INT8) REQ(i,WIDETABLE) \
REQ(i,DATA_UINT2) REQ(i,DATA_UINT4) REQ(i,DATA_UINT8) REQ(i,DATA_UINTN) REQ(i,LARGEIDENT) \
REQ(i,SRVPKTSIZE) REQ(i,DATA_DATE) REQ(i,DATA_TIME) REQ(i,DATA_BIGTIME) REQ(i,DATA_BIGDATETIME)

## Function Documentation

## ◆ tds_alloc_dynamic()

TDSDYNAMIC * tds_alloc_dynamic | ( | TDSCONNECTION * | conn,
|  | const char * | id
| ) |  |

Allocate a dynamic statement.

Parameters

  conn | the connection within which to allocate the statement.
  id | a character label identifying the statement.

Returns
  a pointer to the allocated structure (NULL on failure).

tds_alloc_dynamic is used to implement placeholder code under TDS 5.0

Here is the call graph for this function:

## ◆ tds_alloc_param_data()

void* tds_alloc_param_data | ( | TDSCOLUMN * | curparam | ) |

Allocate data for a parameter.

Parameters

  curparam | parameter to retrieve size information

Returns
  NULL on failure or new data

## ◆ tds_alloc_param_result()

TDSPARAMINFO * tds_alloc_param_result | ( | TDSPARAMINFO * | old_param | ) |

Adds a output parameter to TDSPARAMINFO.

Parameters

  old_param | a pointer to the TDSPARAMINFO structure containing the current set of output parameter, or NULL if none exists.

Returns
  a pointer to the new TDSPARAMINFO structure.

tds_alloc_param_result() works a bit differently than the other alloc result functions. Output parameters come in individually with no total number given in advance, so we simply call this func every time with get a TDS_PARAM_TOKEN and let it realloc the columns struct one bigger. tds_free_all_results() usually cleans up after us.

## ◆ tds_free_input_params()

void tds_free_input_params | ( | TDSDYNAMIC * | dyn | ) |

Frees all allocated input parameters of a dynamic statement.

Parameters

  dyn | the dynamic statement whose input parameter are to be freed

tds_free_input_params frees all parameters for the give dynamic statement

## ◆ tds_get_dynid()

static char* tds_get_dynid | ( | TDSCONNECTION * | conn,
|  | char * | id
| ) |  |
| static

Get an id for dynamic query based on TDS information.

Parameters

  conn | state information for the connection and the TDS protocol

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the caller graph for this function:

## ◆ tds_init_login()

TDSLOGIN* tds_init_login | ( | TDSLOGIN * | login,
|  | TDSLOCALE * | locale
| ) |  |

Initialize login structure with locale information and other stuff for connection.

Parameters

  locale | locale information (copied to configuration information)

Returns
  login structure or NULL if initialization error

## ◆ tds_realloc()

void* tds_realloc | ( | void ** | pp,
|  | size_t | new_size
| ) |  |

Reallocate a pointer and update it if success.

Parameters

  pp | pointer to pointer to be reallocated
  new_size | new size to be allocated

Returns
  new pointer allocated, NULL on failure

## ◆ tds_release_dynamic()

void tds_release_dynamic | ( | TDSDYNAMIC ** | pdyn | ) |

Frees dynamic statement.

Parameters

  pdyn | pointer to dynamic statement to be freed.

Here is the call graph for this function:

## Variable Documentation

## ◆ defaultcaps

const TDS_CAPABILITIES defaultcaps
| static

Initial value:
= { {
{ 1, 14, { REQB(13), REQB(12), REQB(11), REQB(10), REQB(9), REQB(8), REQB(7),
REQB(6), REQB(5), REQB(4), REQB(3), REQB(2), REQB(1), REQB(0) } },
{ 2, 14, { RESB(13), RESB(12), RESB(11), RESB(10), RESB(9), RESB(8), RESB(7),
RESB(6), RESB(5), RESB(4), RESB(3), RESB(2), RESB(1), RESB(0) } }
} }