39 #include <freetds/enum_cap.h>
40 #include <freetds/data.h>
41 #include <freetds/replacements.h>
91 return "user api layer";
99 return "unrecognized layer";
109 return "external error";
112 return "internal CT-Library error";
115 return "common library error";
118 return "intl library error";
124 return "internal BLK-Library error";
129 return "unrecognized origin";
139 return "Failed in conversion routine - condition overflow."
140 " col = %1! row = %2!.";
142 return "Failed in conversion routine - syntax error."
143 " col = %1! row = %2!.";
145 return "Data truncated while doing local character set"
146 " conversion. col = %1! row = %2!.";
148 return "A bind count of %1! is not consistent with the count supplied for existing binds. "
149 "The current bind count is %2!.";
152 return "Use direction CS_BLK_IN or CS_BLK_OUT for a bulk copy operation.";
155 return "The parameter tblname cannot be NULL.";
158 return "Failed when processing results from server.";
161 return "Parameter %1! has an illegal value of %2!";
164 return "No value or default value available and NULL not allowed. col = %1! row = %2! .";
167 return "parameter name(s) must be supplied for LANGUAGE command.";
170 return "This routine cannot be called when the command structure is idle.";
175 return "unrecognized error";
183 tdsdump_log(
TDS_DBG_FUNC,
"_ct_get_msgstr(%s, %d, %d, %d, %d)\n", funcname, layer,
origin, severity,
number);
201 tdsdump_log(
TDS_DBG_FUNC,
"_ctclient_msg(%p, %s, %d, %d, %d, %d, %s)\n", con, funcname, layer,
origin, severity,
number, fmt);
207 cm.
msgnumber = (((layer << 24) & 0xFF000000)
208 | ((
origin << 16) & 0x00FF0000)
209 | ((severity << 8) & 0x0000FF00)
210 | ((
number) & 0x000000FF));
301 (*con)->tds_login =
login;
302 (*con)->server_addr =
NULL;
314 int (*funcptr) (
void *,
void *,
void *) = (
int (*)(
void *,
void *,
void *)) func;
316 tdsdump_log(
TDS_DBG_FUNC,
"ct_callback(%p, %p, %d, %d, %p)\n",
ctx, con, action,
type, func);
334 *(
void **) func =
NULL;
363 tdsdump_log(
TDS_DBG_FUNC,
"ct_con_props(%p, %d, %d, %p, %d, %p)\n", con, action, property,
buffer, buflen, out_len);
371 char *set_buffer =
NULL;
372 bool copy_ret =
true;
427 char *host, *port, *lasts =
NULL;
429 host=
strtok_r(set_buffer,
" ", &lasts);
431 if (!host || !port) {
436 portno = (
int)strtol(port,
NULL, 10);
437 if (portno < 1 || portno >= 65536) {
469 memcpy(&intval,
buffer,
sizeof(intval));
473 memcpy(&intval,
buffer,
sizeof(intval));
543 }
else if (action ==
CS_GET) {
594 memcpy(
buffer, &intval,
sizeof(intval));
601 memcpy(
buffer, &intval,
sizeof(intval));
608 memcpy(
buffer, &intval,
sizeof(intval));
610 *out_len =
sizeof(intval);
682 }
else if (!servername || snamelen == 0 || snamelen ==
CS_UNUSED) {
685 server = (
char *) servername;
738 if (!
locale->datetime_fmt)
792 for (pcommand = con->
cmds; pcommand->
next !=
NULL; pcommand = pcommand->
next)
803 ssize_t query_len, current_query_len;
805 tdsdump_log(
TDS_DBG_FUNC,
"ct_command(%p, %d, %p, %d, %d)\n",
cmd,
type,
buffer, buflen,
option);
826 query_len = strlen((
const char *)
buffer);
845 current_query_len = strlen(
cmd->
query);
849 cmd->
query[current_query_len + query_len] =
'\0';
874 }
else if (buflen > 0) {
1006 tdsdyn->
params = pparam_info;
1106 int something_to_send = 0;
1116 if (!cursor->
query) {
1132 if (something_to_send == 0) {
1146 if (something_to_send == 0) {
1163 if (something_to_send) {
1167 something_to_send = 0;
1218 unsigned process_flags;
1309 *result_type = res_type;
1372 *result_type = res_type;
1505 *result_type = res_type;
1512 *result_type = res_type;
1520 *result_type = res_type;
1525 *result_type = res_type;
1577 tdsdump_log(
TDS_DBG_FUNC,
"ct_bind(%p, %d, %p, %p, %p, %p)\n",
cmd, item, datafmt_arg,
buffer, copied, indicator);
1584 bind_count = datafmt->
count;
1592 if (!resinfo || item <= 0 || item > resinfo->
num_cols)
1600 bind_count = (datafmt->
count == 0) ? 1 : datafmt->
count;
1616 colinfo = resinfo->
columns[item - 1];
1640 tdsdump_log(
TDS_DBG_FUNC,
"ct_fetch(%p, %d, %d, %d, %p)\n",
cmd,
type,
offset,
option, prows_read);
1656 prows_read = &rows_read_dummy;
1700 for (temp_count = 0; temp_count <
cmd->
bind_count; temp_count++) {
1756 tdsdump_log(
TDS_DBG_FUNC,
"_ct_fetch_cursor(%p, %d, %d, %d, %p)\n",
cmd,
type,
offset,
option, rows_read);
1798 for (temp_count = 0; temp_count <
cmd->
bind_count; temp_count++) {
1813 *rows_read = *rows_read + 1;
1827 if (rows_this_fetch)
1839 unsigned char *src, *dest;
1842 TDS_INT datalen_dummy, *pdatalen;
1870 nullind = &nullind_dummy;
1876 pdatalen = &datalen_dummy;
1898 src = (
unsigned char *) ((
TDSBLOB *) src)->textvalue;
1922 *pdatalen, srctype);
1955 for (pvictim = &con->
cmds; *pvictim !=
cmd; ) {
1960 pvictim = &(*pvictim)->
next;
1999 con->
cmds = next_cmd;
2464 if (item < 1 || item > resinfo->
num_cols)
2467 curcol = resinfo->
columns[item - 1];
2508 datafmt->
status = status;
2526 tdsdump_log(
TDS_DBG_FUNC,
"ct_res_info(%p, %d, %p, %d, %p)\n",
cmd,
type,
buffer, buflen, out_len);
2572 tdsdump_log(
TDS_DBG_FUNC,
"ct_config(%p, %d, %d, %p, %d, %p)\n",
ctx, action, property,
buffer, buflen, outlen);
2606 if (
buffer && buflen > 0 && outlen) {
2608 *outlen= snprintf((
char*)
buffer, buflen,
"%s (%s, default tds version=%s)",
2610 (settings->
threadsafe ?
"threadsafe" :
"non-threadsafe"),
2613 ((
char*)
buffer)[buflen - 1]= 0;
2631 if (
buffer && buflen > 0 && outlen) {
2634 ((
char*)
buffer)[buflen - 1]= 0;
2693 tdsdump_log(
TDS_DBG_FUNC,
"ct_cmd_props(%p, %d, %d, %p, %d, %p)\n",
cmd, action, property,
buffer, buflen, outlen);
2732 if (outlen) *outlen =
sizeof(
CS_INT);
2741 if (outlen) *outlen =
sizeof(
CS_INT);
2745 if (outlen) *outlen =
sizeof(
CS_INT);
2756 if (outlen) *outlen =
sizeof(
CS_INT);
2763 if (outlen) *outlen = maxcp;
2786 tdsdump_log(
TDS_DBG_FUNC,
"ct_compute_info(%p, %d, %d, %p, %d, %p)\n",
cmd,
type, colnum,
buffer, buflen, outlen);
2805 *outlen =
sizeof(
CS_INT);
2814 *dest_by_col_ptr = *src_by_col_ptr;
2826 curcol = resinfo->
columns[colnum - 1];
2831 *outlen =
sizeof(
CS_INT);
2841 *outlen =
sizeof(
CS_INT);
2847 curcol = resinfo->
columns[colnum - 1];
2852 *outlen =
sizeof(
CS_INT);
2871 tdsdump_log(
TDS_DBG_FUNC,
"ct_get_data(%p, %d, %p, %d, %p)\n",
cmd, item,
buffer, buflen, outlen);
2878 if (item < 1 || item > resinfo->
num_cols)
2894 size_t table_namelen, column_namelen;
2907 curcol = resinfo->
columns[item - 1];
2912 src = (
unsigned char *) blob->
textvalue;
2931 if (table_namelen + column_namelen + 2 >
sizeof(
cmd->
iodesc->
name))
2932 column_namelen =
sizeof(
cmd->
iodesc->
name) - 2 - table_namelen;
2941 if (table_namelen) {
2953 if (column_namelen) {
2971 curcol = resinfo->
columns[item - 1];
2974 src = (
unsigned char *) ((
TDSBLOB *) src)->textvalue;
2988 if (item < resinfo->num_cols)
2998 if (buflen >= srclen) {
2999 memcpy(
buffer, src, srclen);
3003 if (item < resinfo->num_cols)
3008 memcpy(
buffer, src, buflen);
3020 char textptr_string[35];
3021 char timestamp_string[19];
3056 c = timestamp_string;
3125 if (colnum < 1 || colnum > resinfo->
num_cols)
3161 unsigned char bitmask = 0;
3164 tdsdump_log(
TDS_DBG_FUNC,
"ct_capability(%p, %d, %d, %d, %p)\n", con, action,
type, capability,
value);
3171 switch (capability) {
3221 "ct_capability -- attempt to set a read-only capability (type %d, action %d)\n",
3227 switch (capability) {
3299 bitmask = 1 << (idx&7);
3300 idx =
sizeof(cap->
values) - 1 - (idx>>3);
3308 cap->
values[idx] |= bitmask;
3311 cap->
values[idx] &= ~bitmask;
3336 tdsdump_log(
TDS_DBG_FUNC,
"ct_dynamic(%p, %d, %p, %d, %p, %d)\n",
cmd,
type,
id, idlen,
buffer, buflen);
3353 query_len = strlen(
buffer);
3405 tdsdump_log(
TDS_DBG_FUNC,
"ct_param(%p, %p, %p, %d, %hd)\n",
cmd, datafmt_arg,
data, datalen, indicator);
3417 for (
i = 0;
i < datalen; ++
i) {
3418 if (((
const char*)
data)[
i] & 0x80) {
3440 "RPC is NULL in ct_param\n");
3458 pparam = &(*pparam)->
next;
3484 pparam = &(*pparam)->
next;
3510 pparam = &(*pparam)->
next;
3530 tdsdump_log(
TDS_DBG_FUNC,
"ct_setparam(%p, %p, %p, %p, %p)\n",
cmd, datafmt_arg,
data, datalen, indicator);
3548 "RPC is NULL in ct_param\n");
3566 if (*pparam !=
NULL) {
3567 while ((*pparam)->next !=
NULL) {
3568 pparam = &(*pparam)->
next;
3571 pparam = &(*pparam)->
next;
3583 "cmd->dyn is NULL in ct_param\n");
3599 if (*pparam !=
NULL) {
3600 while ((*pparam)->next !=
NULL) {
3601 pparam = &(*pparam)->
next;
3604 pparam = &(*pparam)->
next;
3634 while ((*pparam)->next)
3635 pparam = &(*pparam)->
next;
3636 (*pparam)->
next = param;
3654 const char *action_string =
NULL;
3658 static const struct TDS_BOOL_OPTION_MAP
3662 } tds_bool_option_map[] = {
3682 tdsdump_log(
TDS_DBG_FUNC,
"ct_options(%p, %d, %d, %p, %d, %p)\n", con, action,
option, param, paramlen, outlen);
3696 action_string =
"CS_GET";
3701 action_string =
"CS_SET";
3705 action_string =
"CS_CLEAR";
3713 assert(tds_command && action_string);
3736 tds_option = tds_bool_option_map[
i].tds_option;
3740 tds_argument.
ti = 1;
3743 tds_argument.
ti = 0;
3775 tds_argsize = (action ==
CS_SET) ? paramlen : 0;
3780 tds_argsize = (action ==
CS_SET) ? paramlen : 0;
3785 switch (*(
CS_INT *) param) {
3811 tds_argsize = (action ==
CS_SET) ? 1 : 0;
3815 switch (*(
CS_INT *) param) {
3838 tds_argsize = (action ==
CS_SET) ? 1 : 0;
3842 switch (*(
char *) param) {
3859 tds_argsize = (action ==
CS_SET) ? 1 : 0;
3863 tds_argument.
i = *(
CS_INT *) param;
3864 tds_argsize = (action ==
CS_SET) ?
sizeof(tds_argument.
i) : 0;
3877 tds_argsize = (action ==
CS_SET) ? 1 : 0;
3886 action_string, tds_option,
3887 tds_argsize == 1 ? tds_argument.
ti : (tds_argsize == 4 ? tds_argument.
i : 0), tds_argsize);
3943 ctx, connection, milliseconds, compconn, compcmd, compid, compstatus);
3955 size_t str_len = strlen(
str);
3961 }
else if (pos != str_len) {
3977 tdsdump_log(
TDS_DBG_FUNC,
"ct_cursor(%p, %d, %p, %d, %p, %d, %d)\n",
cmd,
type, name, namelen,
text, tlen,
option);
4011 }
state = eBaseline;
4012 char* savept =
NULL;
4016 while (tok !=
NULL) {
4021 }
else if (
state == eFor
4033 if (
state == eForUpdate) {
4175 enum { num_cols = 1 };
4192 curcol =
info->columns[0];
4213 static const unsigned char *
4247 return (
const unsigned char*)
row;
4270 for (
i = 0, p = first_param; p !=
NULL; p = p->
next,
i++) {