FreeTDS API

Classes | Macros | Typedefs | Enumerations | Functions | Variables
Query
LibTDS API

Function to handle query. More...

Collaboration diagram for Query:

## Classes
struct | tds_quoteout_stream

## Macros
#define | TDS_PUT_N_AS_UCS2(tds, s)
| Utility to convert a constant ascii string to ucs2 and send to server. More...

## Typedefs
typedef struct tds_quoteout_stream | TDSQUOTEOUTSTREAM

## Enumerations
enum | { OPT_VERSION = 0x01, OPT_TIMER = 0x02, OPT_NOFOOTER = 0x04, OPT_NOHEADER = 0x08, OPT_QUIET = 0x10, OPT_VERBOSE = 0x20, OPT_INSTANCES = 0x40, POS_ISO1, POS_UTF8, POS_UCS2LE, POS_UCS2BE, MUL_STARTED = 1, ASN1_SEQUENCE = ASN1_TAG_SEQUENCE, CS_USERNAME = 9100, CS_USERNAME = 9100, CS_PASSWORD = 9101, CS_PASSWORD = 9101, CS_APPNAME = 9102, CS_APPNAME = 9102, CS_HOSTNAME = 9103, CS_HOSTNAME = 9103, CS_LOGIN_STATUS = 9104, CS_LOGIN_STATUS = 9104, CS_TDS_VERSION = 9105, CS_TDS_VERSION = 9105, CS_CHARSETCNV = 9106, CS_CHARSETCNV = 9106, CS_PACKETSIZE = 9107, CS_PACKETSIZE = 9107, CS_USERDATA = 9108, CS_USERDATA = 9108, CS_NETIO = 9110, CS_NETIO = 9110, CS_TEXTLIMIT = 9112, CS_TEXTLIMIT = 9112, CS_HIDDEN_KEYS = 9113, CS_HIDDEN_KEYS = 9113, CS_VERSION = 9114, CS_VERSION = 9114, CS_IFILE = 9115, CS_IFILE = 9115, CS_LOGIN_TIMEOUT = 9116, CS_LOGIN_TIMEOUT = 9116, CS_TIMEOUT = 9117, CS_TIMEOUT = 9117, CS_MAX_CONNECT = 9118, CS_MAX_CONNECT = 9118, CS_EXPOSE_FMTS = 9120, CS_EXPOSE_FMTS = 9120, CS_EXTRA_INF = 9121, CS_EXTRA_INF = 9121, CS_ANSI_BINDS = 9123, CS_ANSI_BINDS = 9123, CS_BULK_LOGIN = 9124, CS_BULK_LOGIN = 9124, CS_LOC_PROP = 9125, CS_LOC_PROP = 9125, CS_PARENT_HANDLE = 9130, CS_PARENT_HANDLE = 9130, CS_EED_CMD = 9131, CS_EED_CMD = 9131, CS_DIAG_TIMEOUT = 9132, CS_DIAG_TIMEOUT = 9132, CS_DISABLE_POLL = 9133, CS_DISABLE_POLL = 9133, CS_SEC_ENCRYPTION = 9135, CS_SEC_ENCRYPTION = 9135, CS_SEC_CHALLENGE = 9136, CS_SEC_CHALLENGE = 9136, CS_SEC_NEGOTIATE = 9137, CS_SEC_NEGOTIATE = 9137, CS_CON_STATUS = 9143, CS_CON_STATUS = 9143, CS_VER_STRING = 9144, CS_VER_STRING = 9144, CS_SERVERNAME = 9146, CS_SERVERNAME = 9146, CS_SEC_APPDEFINED = 9149, CS_SEC_APPDEFINED = 9149, CS_STICKY_BINDS = 9151, CS_STICKY_BINDS = 9151, CS_SEC_NETWORKAUTH = 9175, CS_SEC_NETWORKAUTH = 9175, CS_SEC_DELEGATION = 9176, CS_SEC_DELEGATION = 9176, CS_SEC_MUTUALAUTH = 9177, CS_SEC_MUTUALAUTH = 9177, CS_SEC_SERVERPRINCIPAL = 9188, CS_SEC_SERVERPRINCIPAL = 9188, CS_SERVERADDR = 9206, CS_SERVERADDR = 9206, CS_PORT = 9300, CS_PORT = 9300, CS_CLIENTCHARSET = 9301, CS_CLIENTCHARSET = 9301, CS_DATABASE, dblib_msdblib = 0, TDS_CHARSET_ISO_8859_1 = 0, TDS_CHARSET_UTF_8 = 1, TDS_CHARSET_UCS_2LE = 2, TDS_CHARSET_UCS_2BE = 3, TDS_CHARSET_ARMSCII_8 = 4, TDS_CHARSET_BIG_5 = 5, TDS_CHARSET_BIG5_HKSCS = 6, TDS_CHARSET_C99 = 7, TDS_CHARSET_CHINESE = 8, TDS_CHARSET_CN = 9, TDS_CHARSET_CN_GB = 10, TDS_CHARSET_CN_GB_ISOIR165 = 11, TDS_CHARSET_CP1133 = 12, TDS_CHARSET_CP1250 = 13, TDS_CHARSET_CP1251 = 14, TDS_CHARSET_CP1252 = 15, TDS_CHARSET_CP1253 = 16, TDS_CHARSET_CP1254 = 17, TDS_CHARSET_CP1255 = 18, TDS_CHARSET_CP1256 = 19, TDS_CHARSET_CP1257 = 20, TDS_CHARSET_CP1258 = 21, TDS_CHARSET_CP1361 = 22, TDS_CHARSET_CP437 = 23, TDS_CHARSET_CP850 = 24, TDS_CHARSET_CP862 = 25, TDS_CHARSET_CP866 = 26, TDS_CHARSET_CP874 = 27, TDS_CHARSET_CP932 = 28, TDS_CHARSET_CP936 = 29, TDS_CHARSET_CP949 = 30, TDS_CHARSET_CP950 = 31, TDS_CHARSET_EUC_JP = 32, TDS_CHARSET_EUC_KR = 33, TDS_CHARSET_EUC_TW = 34, TDS_CHARSET_GB18030 = 35, TDS_CHARSET_GEORGIAN_ACADEMY = 36, TDS_CHARSET_GEORGIAN_PS = 37, TDS_CHARSET_HZ = 38, TDS_CHARSET_ISO_2022_CN = 39, TDS_CHARSET_ISO_2022_CN_EXT = 40, TDS_CHARSET_ISO_2022_JP = 41, TDS_CHARSET_ISO_2022_JP_1 = 42, TDS_CHARSET_ISO_2022_JP_2 = 43, TDS_CHARSET_ISO_2022_KR = 44, TDS_CHARSET_ISO_8859_10 = 45, TDS_CHARSET_ISO_8859_13 = 46, TDS_CHARSET_ISO_8859_14 = 47, TDS_CHARSET_ISO_8859_15 = 48, TDS_CHARSET_ISO_8859_16 = 49, TDS_CHARSET_ISO_8859_2 = 50, TDS_CHARSET_ISO_8859_3 = 51, TDS_CHARSET_ISO_8859_4 = 52, TDS_CHARSET_ISO_8859_5 = 53, TDS_CHARSET_ISO_8859_6 = 54, TDS_CHARSET_ISO_8859_7 = 55, TDS_CHARSET_ISO_8859_8 = 56, TDS_CHARSET_ISO_8859_9 = 57, TDS_CHARSET_ISO_IR_14 = 58, TDS_CHARSET_ISO_IR_149 = 59, TDS_CHARSET_ISO_IR_159 = 60, TDS_CHARSET_ISO_IR_166 = 61, TDS_CHARSET_ISO_IR_87 = 62, TDS_CHARSET_JAVA = 63, TDS_CHARSET_JISX0201_1976 = 64, TDS_CHARSET_KOI8_R = 65, TDS_CHARSET_KOI8_RU = 66, TDS_CHARSET_KOI8_T = 67, TDS_CHARSET_KOI8_U = 68, TDS_CHARSET_MAC = 69, TDS_CHARSET_MACARABIC = 70, TDS_CHARSET_MACCENTRALEUROPE = 71, TDS_CHARSET_MACCROATIAN = 72, TDS_CHARSET_MACCYRILLIC = 73, TDS_CHARSET_MACGREEK = 74, TDS_CHARSET_MACHEBREW = 75, TDS_CHARSET_MACICELAND = 76, TDS_CHARSET_MACROMANIA = 77, TDS_CHARSET_MACTHAI = 78, TDS_CHARSET_MACTURKISH = 79, TDS_CHARSET_MACUKRAINE = 80, TDS_CHARSET_MULELAO_1 = 81, TDS_CHARSET_NEXTSTEP = 82, TDS_CHARSET_ROMAN8 = 83, TDS_CHARSET_SJIS = 84, TDS_CHARSET_TCVN = 85, TDS_CHARSET_UCS_4BE = 86, TDS_CHARSET_UCS_4LE = 87, TDS_CHARSET_US_ASCII = 88, TDS_CHARSET_UTF_16BE = 89, TDS_CHARSET_UTF_16LE = 90, TDS_CHARSET_UTF_32BE = 91, TDS_CHARSET_UTF_32LE = 92, TDS_CHARSET_UTF_7 = 93, TDS_CHARSET_VISCII = 94, TDS_NUM_CHARSETS = 95, ODBC_PARAM_SIZE, TDS_OPT_ARITHOVERFLOW = 0x01, TDS_OPT_NUMERICTRUNC = 0x02, TDS_CUR_ISTAT_UNUSED = 0x00, TDS_CUR_ISTAT_DECLARED = 0x01, TDS_CUR_ISTAT_OPEN = 0x02, TDS_CUR_ISTAT_CLOSED = 0x04, TDS_CUR_ISTAT_RDONLY = 0x08, TDS_CUR_ISTAT_UPDATABLE = 0x10, TDS_CUR_ISTAT_ROWCNT = 0x20, TDS_CUR_ISTAT_DEALLOC = 0x40, SYBCHAR = 47, SYBCHAR = 47, SYBVARCHAR = 39, SYBVARCHAR = 39, SYBINTN = 38, SYBINTN = 38, SYBINT1 = 48, SYBINT1 = 48, SYBINT2 = 52, SYBINT2 = 52, SYBINT4 = 56, SYBINT4 = 56, SYBINT8 = 127, SYBINT8 = 127, SYBFLT8 = 62, SYBFLT8 = 62, SYBDATETIME = 61, SYBDATETIME = 61, SYBBIT = 50, SYBBIT = 50, SYBBITN = 104, SYBBITN = 104, SYBTEXT = 35, SYBTEXT = 35, SYBNTEXT = 99, SYBNTEXT = 99, SYBIMAGE = 34, SYBIMAGE = 34, SYBMONEY4 = 122, SYBMONEY4 = 122, SYBMONEY = 60, SYBMONEY = 60, SYBDATETIME4 = 58, SYBDATETIME4 = 58, SYBREAL = 59, SYBREAL = 59, SYBBINARY = 45, SYBBINARY = 45, SYBVOID = 31, SYBVOID = 31, SYBVARBINARY = 37, SYBVARBINARY = 37, SYBNUMERIC = 108, SYBNUMERIC = 108, SYBDECIMAL = 106, SYBDECIMAL = 106, SYBFLTN = 109, SYBFLTN = 109, SYBMONEYN = 110, SYBMONEYN = 110, SYBDATETIMN = 111, SYBDATETIMN = 111, SYBNVARCHAR = 103, SYBNVARCHAR = 103, SYBDATE = 49, SYBDATE = 49, SYBTIME = 51, SYBTIME = 51, SYBBIGDATETIME = 187, SYBBIGDATETIME = 187, SYBBIGTIME = 188, SYBBIGTIME = 188, SYBMSDATE = 40, SYBMSDATE = 40, SYBMSTIME = 41, SYBMSTIME = 41, SYBMSDATETIME2 = 42, SYBMSDATETIME2 = 42, SYBMSDATETIMEOFFSET = 43, SYBMSDATETIMEOFFSET = 43 }

## Functions
static TDSRET | tds4_send_emulated_rpc (TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params)
| Send RPC as string query. More...
static char * | tds5_fix_dot_query (const char *query, size_t *query_len, TDSPARAMINFO *params)
| Substitute ?-style placeholders with named (@param) ones. More...
static TDSRET | tds5_put_params (TDSSOCKET *tds, TDSPARAMINFO *info, int flags)
| Send parameters to server. More...
TDSRET | tds71_submit_prepexec (TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
| Creates a temporary stored procedure in the server and execute it. More...
static void | tds7_put_cursor_fetch (TDSSOCKET *tds, TDS_INT cursor_id, TDS_TINYINT fetch_type, TDS_INT i_row, TDS_INT num_rows)
static void | tds7_put_query_params (TDSSOCKET *tds, const char *query, size_t query_len)
| Output params types and query (required by sp_prepare/sp_executesql/sp_prepexec) More...
static TDSRET | tds7_send_execute (TDSSOCKET *tds, TDSDYNAMIC *dyn)
| Send dynamic request on TDS 7+ to be executed. More...
static TDSRET | tds7_write_param_def_from_params (TDSSOCKET *tds, const char *query, size_t query_len, TDSPARAMINFO *params)
| Write string with parameters definition, useful for TDS7+. More...
static TDSRET | tds7_write_param_def_from_query (TDSSOCKET *tds, const char *converted_query, size_t converted_query_len, TDSPARAMINFO *params)
| Write string with parameters definition, useful for TDS7+. More...
static size_t | tds_ascii_to_ucs2 (char *buffer, const char *buf)
| Accept an ASCII string, convert it to UCS2-LE The input is NUL-terminated, but the output does not contains the NUL. More...
const char * | tds_convert_string (TDSSOCKET *tds, TDSICONV *char_conv, const char *s, int len, size_t *out_len)
| Convert a string in an allocated buffer. More...
int | tds_count_placeholders (const char *query)
| Count the number of placeholders ('?') in a query. More...
static int | tds_count_placeholders_ucs2le (const char *query, const char *query_end)
| Count the number of placeholders ('?') in a query. More...
static bool | tds_cursor_check_allocated (TDSCONNECTION *conn, TDSCURSOR *cursor)
| Check if a cursor is allocated into the server. More...
TDSRET | tds_cursor_close (TDSSOCKET *tds, TDSCURSOR *cursor)
TDSRET | tds_cursor_dealloc (TDSSOCKET *tds, TDSCURSOR *cursor)
| Send a deallocation request to server.
TDSRET | tds_cursor_declare (TDSSOCKET *tds, TDSCURSOR *cursor, TDSPARAMINFO *params, int *something_to_send)
TDSRET | tds_cursor_fetch (TDSSOCKET *tds, TDSCURSOR *cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row)
TDSRET | tds_cursor_get_cursor_info (TDSSOCKET *tds, TDSCURSOR *cursor, TDS_UINT *prow_number, TDS_UINT *prow_count)
TDSRET | tds_cursor_open (TDSSOCKET *tds, TDSCURSOR *cursor, TDSPARAMINFO *params, int *something_to_send)
TDSRET | tds_cursor_setname (TDSSOCKET *tds, TDSCURSOR *cursor)
TDSRET | tds_cursor_setrows (TDSSOCKET *tds, TDSCURSOR *cursor, int *something_to_send)
TDSRET | tds_cursor_update (TDSSOCKET *tds, TDSCURSOR *cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO *params)
TDSRET | tds_deferred_cursor_dealloc (TDSCONNECTION *conn, TDSCURSOR *cursor)
| Deallocate cursor on idle. More...
TDSRET | tds_deferred_unprepare (TDSCONNECTION *conn, TDSDYNAMIC *dyn)
| Unprepare dynamic on idle. More...
TDSRET | tds_disconnect (TDSSOCKET *tds)
size_t | tds_fix_column_size (TDSSOCKET *tds, TDSCOLUMN *curcol)
| Get column size for wire.
TDSRET | tds_get_column_declaration (TDSSOCKET *tds, TDSCOLUMN *curcol, char *out)
| Return declaration for column (like "varchar(20)"). More...
TDSRET | tds_multiple_done (TDSSOCKET *tds, TDSMULTIPLE *multiple)
TDSRET | tds_multiple_execute (TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC *dyn)
TDSRET | tds_multiple_init (TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type, TDSHEADERS *head)
TDSRET | tds_multiple_query (TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO *params)
int | tds_needs_unprepare (TDSCONNECTION *conn, TDSDYNAMIC *dyn)
| Check if dynamic request must be unprepared. More...
const char * | tds_next_placeholder (const char *start)
| Get position of next placeholder. More...
static const char * | tds_next_placeholder_ucs2le (const char *start, const char *end, int named)
| Found the next placeholder (? or @param) in a string. More...
static TDSRET | tds_put_char_param_as_string (TDSSOCKET *tds, const TDSCOLUMN *curcol)
static TDSRET | tds_put_data (TDSSOCKET *tds, TDSCOLUMN *curcol)
| Write data to wire. More...
static TDSRET | tds_put_data_info (TDSSOCKET *tds, TDSCOLUMN *curcol, int flags)
| Put data information to wire. More...
static TDSRET | tds_put_param_as_string (TDSSOCKET *tds, TDSPARAMINFO *params, int n)
| Send a parameter to server. More...
static TDSRET | tds_query_flush_packet (TDSSOCKET *tds)
| Flush query packet. More...
static size_t | tds_quote (TDSSOCKET *tds, char *buffer, char quoting, const char *id, size_t len)
| Quote a string properly. More...
static void | tds_quote_and_put (TDSSOCKET *tds, const char *s, const char *end)
| Send a string to server while quoting it. More...
size_t | tds_quote_id (TDSSOCKET *tds, char *buffer, const char *id, int idlen)
| Quote an id. More...
size_t | tds_quote_id_rpc (TDSSOCKET *tds, char *buffer, const char *id, int idlen)
| Quote an id for a RPC call. More...
size_t | tds_quote_string (TDSSOCKET *tds, char *buffer, const char *str, int len)
| Quote a string. More...
static void | tds_quoteout_stream_init (TDSQUOTEOUTSTREAM *stream, TDSSOCKET *tds)
static int | tds_quoteout_stream_write (TDSOUTSTREAM *stream, size_t len)
TDSRET | tds_send_cancel (TDSSOCKET *tds)
| tds_send_cancel() sends an empty packet (8 byte header only) tds_process_cancel should be called directly after this. More...
static TDSRET | tds_send_emulated_execute (TDSSOCKET *tds, const char *query, TDSPARAMINFO *params)
| Emulate prepared execute traslating to a normal language.
static void | tds_set_cur_cursor (TDSSOCKET *tds, TDSCURSOR *cursor)
| Set current cursor. More...
void | tds_set_cur_dyn (TDSSOCKET *tds, TDSDYNAMIC *dyn)
| Set current dynamic. More...
const char * | tds_skip_comment (const char *s)
| Skip a comment in a query. More...
static const char * | tds_skip_comment_ucs2le (const char *s, const char *end)
| Skip a comment in a query. More...
const char * | tds_skip_quoted (const char *s)
| Skip quoting string (like 'sfsf', "dflkdj" or [dfkjd]) More...
static const char * | tds_skip_quoted_ucs2le (const char *s, const char *end)
| Return pointer to end of a quoted string. More...
void | tds_start_query (TDSSOCKET *tds, unsigned char packet_type)
| Start query packet of a given type. More...
static TDSRET | tds_start_query_head (TDSSOCKET *tds, unsigned char packet_type, TDSHEADERS *head)
| Start query packet of a given type. More...
TDSRET | tds_submit_begin_tran (TDSSOCKET *tds)
| Send a rollback request. More...
TDSRET | tds_submit_commit (TDSSOCKET *tds, int cont)
| Send a commit request. More...
TDSRET | tds_submit_execdirect (TDSSOCKET *tds, const char *query, TDSPARAMINFO *params, TDSHEADERS *head)
| Submit a prepared query with parameters. More...
TDSRET | tds_submit_execute (TDSSOCKET *tds, TDSDYNAMIC *dyn)
| Sends a previously prepared dynamic statement to the server. More...
TDSRET | tds_submit_optioncmd (TDSSOCKET *tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size)
| Send option commands to server. More...
TDSRET | tds_submit_prepare (TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
| Creates a temporary stored procedure in the server. More...
TDSRET | tds_submit_query (TDSSOCKET *tds, const char *query)
| Sends a language string to the database server for processing. More...
TDSRET | tds_submit_query_params (TDSSOCKET *tds, const char *query, TDSPARAMINFO *params, TDSHEADERS *head)
| Sends a language string to the database server for processing. More...
TDSRET | tds_submit_queryf (TDSSOCKET *tds, const char *queryf,...)
| Format and submit a query. More...
TDSRET | tds_submit_rollback (TDSSOCKET *tds, int cont)
| Send a rollback request. More...
TDSRET | tds_submit_rpc (TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params, TDSHEADERS *head)
| Calls a RPC from server. More...
TDSRET | tds_submit_unprepare (TDSSOCKET *tds, TDSDYNAMIC *dyn)
| Send a unprepare request for a prepared query. More...

## Variables
static const TDSCONTEXT | empty_ctx = {0}

## Detailed Description

Function to handle query.

## Macro Definition Documentation

## ◆ TDS_PUT_N_AS_UCS2

#define TDS_PUT_N_AS_UCS2 | ( |  | tds,
|  |  | s
| ) |  |

Value:
do { \
char buffer[sizeof(s)*2-2]; \
tds_put_smallint(tds, sizeof(buffer)/2); \
tds_put_n(tds, buffer, tds_ascii_to_ucs2(buffer, s)); \
} while(0)

Utility to convert a constant ascii string to ucs2 and send to server.

Used to send internal store procedure names to server.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  s | constanst string to send

## Function Documentation

## ◆ tds4_send_emulated_rpc()

static TDSRET tds4_send_emulated_rpc | ( | TDSSOCKET * | tds,
|  | const char * | rpc_name,
|  | TDSPARAMINFO * | params
| ) |  |
| static

Send RPC as string query.

This function is used on old protocol which does not support RPC queries.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  rpc_name | name of RPC to invoke
  params | parameters to send to server

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the call graph for this function:

## ◆ tds5_fix_dot_query()

static char* tds5_fix_dot_query | ( | const char * | query,
|  | size_t * | query_len,
|  | TDSPARAMINFO * | params
| ) |  |
| static

Substitute ?-style placeholders with named (@param) ones.

Sybase does not support ?-style placeholders so convert them. Also the function replace parameter names.

Parameters

  | query | query string
  [in,out] | query_len | pointer to query length. On input length of input query, on output length of output query
  | params | parameters to send to server

Returns
  new query or NULL on error

## ◆ tds5_put_params()

static TDSRET tds5_put_params | ( | TDSSOCKET * | tds,
|  | TDSPARAMINFO * | info,
|  | int | flags
| ) |  |
| static

Send parameters to server.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  info | parameters to send
  flags | 0 or TDS_PUT_DATA_USE_NAME

Here is the call graph for this function:

## ◆ tds71_submit_prepexec()

TDSRET tds71_submit_prepexec | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | const char * | id,
|  | TDSDYNAMIC ** | dyn_out,
|  | TDSPARAMINFO * | params
| ) |  |

Creates a temporary stored procedure in the server and execute it.

Parameters

  tds | state information for the socket and the TDS protocol
  query | language query with given placeholders ('?')
  id | string to identify the dynamic query. Pass NULL for automatic generation.
  dyn_out | will receive allocated TDSDYNAMIC*. Any older allocated dynamic won't be freed. Can be NULL.
  params | parameters to use. It can be NULL even if parameters are present.

Returns
  TDS_FAIL or TDS_SUCCESS

## ◆ tds7_put_query_params()

static void tds7_put_query_params | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | size_t | query_len
| ) |  |
| static

Output params types and query (required by sp_prepare/sp_executesql/sp_prepexec)

Parameters

  tds | state information for the socket and the TDS protocol
  query | query (encoded in ucs2le)
  query_len | query length in bytes

## ◆ tds7_send_execute()

static TDSRET tds7_send_execute | ( | TDSSOCKET * | tds,
|  | TDSDYNAMIC * | dyn
| ) |  |
| static

Send dynamic request on TDS 7+ to be executed.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  dyn | dynamic query to execute

## ◆ tds7_write_param_def_from_params()

static TDSRET tds7_write_param_def_from_params | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | size_t | query_len,
|  | TDSPARAMINFO * | params
| ) |  |
| static

Write string with parameters definition, useful for TDS7+.

Looks like "@P1 INT, @P2 VARCHAR(100)"

Parameters

  tds | state information for the socket and the TDS protocol
  query | query to send to server encoded in ucs2le
  query_len | query length in bytes
  params | parameters to build declaration

Returns
  result of the operation

## ◆ tds7_write_param_def_from_query()

static TDSRET tds7_write_param_def_from_query | ( | TDSSOCKET * | tds,
|  | const char * | converted_query,
|  | size_t | converted_query_len,
|  | TDSPARAMINFO * | params
| ) |  |
| static

Write string with parameters definition, useful for TDS7+.

Looks like "@P1 INT, @P2 VARCHAR(100)"

Parameters

  tds | state information for the socket and the TDS protocol
  converted_query | query to send to server in ucs2le encoding
  converted_query_len | query length in bytes
  params | parameters to build declaration

Returns
  result of write

## ◆ tds_ascii_to_ucs2()

static size_t tds_ascii_to_ucs2 | ( | char * | buffer,
|  | const char * | buf
| ) |  |
| static

Accept an ASCII string, convert it to UCS2-LE The input is NUL-terminated, but the output does not contains the NUL.

Parameters

  buffer | buffer where to store output
  buf | string to write

Returns
  bytes written

## ◆ tds_convert_string()

const char* tds_convert_string | ( | TDSSOCKET * | tds,
|  | TDSICONV * | char_conv,
|  | const char * | s,
|  | int | len,
|  | size_t * | out_len
| ) |  |

Convert a string in an allocated buffer.

Parameters

  tds | state information for the socket and the TDS protocol
  char_conv | information about the encodings involved
  s | input string
  len | input string length (in bytes), -1 for NUL-terminated
  out_len | returned output length (in bytes)

Returns
  string allocated (or input pointer if no conversion required) or NULL if error

## ◆ tds_count_placeholders()

int tds_count_placeholders | ( | const char * | query | ) |

Count the number of placeholders ('?') in a query.

Parameters

  query | query string

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ tds_count_placeholders_ucs2le()

static int tds_count_placeholders_ucs2le | ( | const char * | query,
|  | const char * | query_end
| ) |  |
| static

Count the number of placeholders ('?') in a query.

Parameters

  query | query encoded in ucs2le
  query_end | end of query

Returns
  number of placeholders found

Here is the call graph for this function:

## ◆ tds_cursor_check_allocated()

static bool tds_cursor_check_allocated | ( | TDSCONNECTION * | conn,
|  | TDSCURSOR * | cursor
| ) |  |
| static

Check if a cursor is allocated into the server.

If is not allocated it assures is removed from the connection list

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.

Returns
  true if allocated false otherwise

Here is the caller graph for this function:

## ◆ tds_deferred_cursor_dealloc()

TDSRET tds_deferred_cursor_dealloc | ( | TDSCONNECTION * | conn,
|  | TDSCURSOR * | cursor
| ) |  |

Deallocate cursor on idle.

This let libTDS close the cursor when possible.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  cursor | cursor to close

Here is the call graph for this function:

## ◆ tds_deferred_unprepare()

TDSRET tds_deferred_unprepare | ( | TDSCONNECTION * | conn,
|  | TDSDYNAMIC * | dyn
| ) |  |

Unprepare dynamic on idle.

This let libTDS close the prepared statement when possible.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  dyn | dynamic request to close

Here is the call graph for this function:

## ◆ tds_get_column_declaration()

TDSRET tds_get_column_declaration | ( | TDSSOCKET * | tds,
|  | TDSCOLUMN * | curcol,
|  | char * | out
| ) |  |

Return declaration for column (like "varchar(20)").

This depends on:

- on_server.column_type
- varint_size (for varchar(max) distinction)
- column_size
- precision/scale (numeric)

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  curcol | column
  out | buffer to hold declaration

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the caller graph for this function:

## ◆ tds_needs_unprepare()

int tds_needs_unprepare | ( | TDSCONNECTION * | conn,
|  | TDSDYNAMIC * | dyn
| ) |  |

Check if dynamic request must be unprepared.

Depending on status and protocol version request should be unprepared or not.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  dyn | dynamic request to check

Here is the caller graph for this function:

## ◆ tds_next_placeholder()

const char* tds_next_placeholder | ( | const char * | start | ) |

Get position of next placeholder.

Parameters

  start | pointer to part of query to search

Returns
  next placeholder or NULL if not found

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ tds_next_placeholder_ucs2le()

static const char* tds_next_placeholder_ucs2le | ( | const char * | start,
|  | const char * | end,
|  | int | named
| ) |  |
| static

Found the next placeholder (? or @param) in a string.

String must be encoded in ucs2le.

Parameters

  start | start of the string (or part of it)
  end | end of string
  named | true if named parameters should be returned

Returns
  either start of next placeholder or end if not found

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ tds_put_data()

static TDSRET tds_put_data | ( | TDSSOCKET * | tds,
|  | TDSCOLUMN * | curcol
| ) |  |
| inline static

Write data to wire.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  curcol | column where store column information

Returns
  TDS_FAIL on error or TDS_SUCCESS

## ◆ tds_put_data_info()

static TDSRET tds_put_data_info | ( | TDSSOCKET * | tds,
|  | TDSCOLUMN * | curcol,
|  | int | flags
| ) |  |
| static

Put data information to wire.

Parameters

  tds | state information for the socket and the TDS protocol
  curcol | column where to store information
  flags | bit flags on how to send data (use TDS_PUT_DATA_USE_NAME for use name information)

Returns
  TDS_SUCCESS or TDS_FAIL

## ◆ tds_put_param_as_string()

static TDSRET tds_put_param_as_string | ( | TDSSOCKET * | tds,
|  | TDSPARAMINFO * | params,
|  | int | n
| ) |  |
| static

Send a parameter to server.

Parameters are converted to string and sent to server.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  params | parameters structure
  n | number of parameter to send

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the caller graph for this function:

## ◆ tds_query_flush_packet()

static TDSRET tds_query_flush_packet | ( | TDSSOCKET * | tds | ) |
| static

Flush query packet.

Used at the end of packet write to really send packet to server. This also changes the state to TDS_PENDING.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ tds_quote()

static size_t tds_quote | ( | TDSSOCKET * | tds,
|  | char * | buffer,
|  | char | quoting,
|  | const char * | id,
|  | size_t | len
| ) |  |
| static

Quote a string properly.

Output string is always NUL-terminated

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  buffer | output buffer. If NULL function will just return required bytes
  quoting | quote character (should be one of '\'', '"', ']')
  id | string to quote
  len | length of string to quote

Returns
  size of output string

## ◆ tds_quote_and_put()

static void tds_quote_and_put | ( | TDSSOCKET * | tds,
|  | const char * | s,
|  | const char * | end
| ) |  |
| static

Send a string to server while quoting it.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  s | string start
  end | string end

Here is the call graph for this function:

## ◆ tds_quote_id()

size_t tds_quote_id | ( | TDSSOCKET * | tds,
|  | char * | buffer,
|  | const char * | id,
|  | int | idlen
| ) |  |

Quote an id.

Parameters

  tds | state information for the socket and the TDS protocol
  buffer | buffer to store quoted id. If NULL do not write anything (useful to compute quote length)
  id | id to quote
  idlen | id length (< 0 for NUL terminated)

Returns
  written chars (not including needed terminator)

See also
  tds_quote_id_rpc

## ◆ tds_quote_id_rpc()

size_t tds_quote_id_rpc | ( | TDSSOCKET * | tds,
|  | char * | buffer,
|  | const char * | id,
|  | int | idlen
| ) |  |

Quote an id for a RPC call.

Parameters

  tds | state information for the socket and the TDS protocol
  buffer | buffer to store quoted id. If NULL do not write anything (useful to compute quote length)
  id | id to quote
  idlen | id length (< 0 for NUL terminated)

Returns
  written chars (not including needed terminator)

See also
  tds_quote_id

## ◆ tds_quote_string()

size_t tds_quote_string | ( | TDSSOCKET * | tds,
|  | char * | buffer,
|  | const char * | str,
|  | int | len
| ) |  |

Quote a string.

Parameters

  tds | state information for the socket and the TDS protocol
  buffer | buffer to store quoted id. If NULL do not write anything (useful to compute quote length)
  str | string to quote (not necessary NUL-terminated)
  len | length of string (-1 for NUL-terminated)

Returns
  written chars (not including needed terminator)

## ◆ tds_send_cancel()

TDSRET tds_send_cancel | ( | TDSSOCKET * | tds | ) |

tds_send_cancel() sends an empty packet (8 byte header only) tds_process_cancel should be called directly after this.

Parameters

  tds | state information for the socket and the TDS protocol

Remarks
  tcp will either deliver the packet or time out. (TIME_WAIT determines how long it waits between retries.)

On sending the cancel, we may get EAGAIN. We then select(2) until we know either 1) it succeeded or 2) it didn't. On failure, close the socket, tell the app, and fail the function.

On success, we read(2) and wait for a reply with select(2). If we get one, great. If the client's timeout expires, we tell him, but all we can do is wait some more or give up and close the connection. If he tells us to cancel again, we wait some more.

Here is the call graph for this function:

## ◆ tds_set_cur_cursor()

static void tds_set_cur_cursor | ( | TDSSOCKET * | tds,
|  | TDSCURSOR * | cursor
| ) |  |
| inline static

Set current cursor.

Current cursor is the one will receive output from server.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  cursor | cursor to set as current

## ◆ tds_set_cur_dyn()

void tds_set_cur_dyn | ( | TDSSOCKET * | tds,
|  | TDSDYNAMIC * | dyn
| ) |  |

Set current dynamic.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  dyn | dynamic to set

## ◆ tds_skip_comment()

const char* tds_skip_comment | ( | const char * | s | ) |

Skip a comment in a query.

Parameters

  s | start of the string (or part of it)

Returns
  pointer to end of comment

Here is the caller graph for this function:

## ◆ tds_skip_comment_ucs2le()

static const char* tds_skip_comment_ucs2le | ( | const char * | s,
|  | const char * | end
| ) |  |
| static

Skip a comment in a query.

Parameters

  s | start of the string (or part of it). Encoded in ucs2le
  end | end of string

Returns
  pointer to end of comment

Here is the caller graph for this function:

## ◆ tds_skip_quoted()

const char* tds_skip_quoted | ( | const char * | s | ) |

Skip quoting string (like 'sfsf', "dflkdj" or [dfkjd])

Parameters

  s | pointer to first quoting character.
      Should be ', " or [.

Returns
  character after quoting

Here is the caller graph for this function:

## ◆ tds_skip_quoted_ucs2le()

static const char* tds_skip_quoted_ucs2le | ( | const char * | s,
|  | const char * | end
| ) |  |
| static

Return pointer to end of a quoted string.

At the beginning pointer should point to delimiter.

Parameters

  s | start of string to skip encoded in ucs2le
  end | pointer to end of string

Here is the caller graph for this function:

## ◆ tds_start_query()

void tds_start_query | ( | TDSSOCKET * | tds,
|  | unsigned char | packet_type
| ) |  |

Start query packet of a given type.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  packet_type | packet type

Here is the call graph for this function:

## ◆ tds_start_query_head()

static TDSRET tds_start_query_head | ( | TDSSOCKET * | tds,
|  | unsigned char | packet_type,
|  | TDSHEADERS * | head
| ) |  |
| static

Start query packet of a given type.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  packet_type | packet type
  head | extra information to put in a TDS7 header

Here is the caller graph for this function:

## ◆ tds_submit_begin_tran()

TDSRET tds_submit_begin_tran | ( | TDSSOCKET * | tds | ) |

Send a rollback request.

TDS 7.2+ need this in order to handle transactions correctly if MARS is used.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.

See also
  tds_submit_commit, tds_submit_rollback

## ◆ tds_submit_commit()

TDSRET tds_submit_commit | ( | TDSSOCKET * | tds,
|  | int | cont
| ) |  |

Send a commit request.

TDS 7.2+ need this in order to handle transactions correctly if MARS is used.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  cont | true to start a new transaction

See also
  tds_submit_rollback, tds_submit_begin_tran

## ◆ tds_submit_execdirect()

TDSRET tds_submit_execdirect | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | TDSPARAMINFO * | params,
|  | TDSHEADERS * | head
| ) |  |

Submit a prepared query with parameters.

Parameters

  tds | state information for the socket and the TDS protocol
  query | language query with given placeholders (?)
  params | parameters to send

Returns
  TDS_FAIL or TDS_SUCCESS

## ◆ tds_submit_execute()

TDSRET tds_submit_execute | ( | TDSSOCKET * | tds,
|  | TDSDYNAMIC * | dyn
| ) |  |

Sends a previously prepared dynamic statement to the server.

Parameters

  tds | state information for the socket and the TDS protocol
  dyn | dynamic proc to execute. Must build from same tds.

Here is the call graph for this function:

## ◆ tds_submit_optioncmd()

TDSRET tds_submit_optioncmd | ( | TDSSOCKET * | tds,
|  | TDS_OPTION_CMD | command,
|  | TDS_OPTION | option,
|  | TDS_OPTION_ARG * | param,
|  | TDS_INT | param_size
| ) |  |

Send option commands to server.

Option commands are used to change server options.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  command | command type.
  option | option to set/get.
  param | parameter value
  param_size | length of parameter value in bytes

Here is the call graph for this function:

## ◆ tds_submit_prepare()

TDSRET tds_submit_prepare | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | const char * | id,
|  | TDSDYNAMIC ** | dyn_out,
|  | TDSPARAMINFO * | params
| ) |  |

Creates a temporary stored procedure in the server.

Under TDS 4.2 dynamic statements are emulated building sql command. TDS 5 does not uses parameters type. TDS 7+ uses parameter types to prepare the query. You should prepare again the query if parameters changes.

Parameters

  tds | state information for the socket and the TDS protocol
  query | language query with given placeholders (?)
  id | string to identify the dynamic query. Pass NULL for automatic generation.
  dyn_out | will receive allocated TDSDYNAMIC*. Any older allocated dynamic won't be freed, Can be NULL.
  params | parameters to use. It can be NULL even if parameters are present. Used only for TDS7+

Returns
  TDS_FAIL or TDS_SUCCESS

## ◆ tds_submit_query()

TDSRET tds_submit_query | ( | TDSSOCKET * | tds,
|  | const char * | query
| ) |  |

Sends a language string to the database server for processing.

TDS 4.2 is a plain text message with a packet type of 0x01, TDS 7.0 is a unicode string with packet type 0x01, and TDS 5.0 uses a TDS_LANGUAGE_TOKEN to encapsulate the query and a packet type of 0x0f.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  query | language query to submit

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the call graph for this function:

## ◆ tds_submit_query_params()

TDSRET tds_submit_query_params | ( | TDSSOCKET * | tds,
|  | const char * | query,
|  | TDSPARAMINFO * | params,
|  | TDSHEADERS * | head
| ) |  |

Sends a language string to the database server for processing.

TDS 4.2 is a plain text message with a packet type of 0x01, TDS 7.0 is a unicode string with packet type 0x01, and TDS 5.0 uses a TDS_LANGUAGE_TOKEN to encapsulate the query and a packet type of 0x0f.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  query | language query to submit
  params | parameters of query

Returns
  TDS_FAIL or TDS_SUCCESS

Here is the caller graph for this function:

## ◆ tds_submit_queryf()

TDSRET tds_submit_queryf | ( | TDSSOCKET * | tds,
|  | const char * | queryf,
|  |  | ...
| ) |  |

Format and submit a query.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  queryf | query format. printf like expansion is performed on this query.

Here is the caller graph for this function:

## ◆ tds_submit_rollback()

TDSRET tds_submit_rollback | ( | TDSSOCKET * | tds,
|  | int | cont
| ) |  |

Send a rollback request.

TDS 7.2+ need this in order to handle transactions correctly if MARS is used.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.
  cont | true to start a new transaction

See also
  tds_submit_begin_tran, tds_submit_commit

## ◆ tds_submit_rpc()

TDSRET tds_submit_rpc | ( | TDSSOCKET * | tds,
|  | const char * | rpc_name,
|  | TDSPARAMINFO * | params,
|  | TDSHEADERS * | head
| ) |  |

Calls a RPC from server.

Output parameters will be stored in tds->param_info.

Parameters

  tds | state information for the socket and the TDS protocol
  rpc_name | name of RPC
  params | parameters informations. NULL for no parameters

Here is the call graph for this function:

## ◆ tds_submit_unprepare()

TDSRET tds_submit_unprepare | ( | TDSSOCKET * | tds,
|  | TDSDYNAMIC * | dyn
| ) |  |

Send a unprepare request for a prepared query.

Parameters

  tds | state information for the socket and the TDS protocol
  dyn | dynamic query

Returns
  TDS_SUCCESS or TDS_FAIL

tds_ascii_to_ucs2
static size_t tds_ascii_to_ucs2(char *buffer, const char *buf)
Accept an ASCII string, convert it to UCS2-LE The input is NUL-terminated, but the output does not co...
Definition: query.c:91