Line data Source code
1 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 : * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns
3 : * Copyright (C) 2005-2015 Frediano Ziglio
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Library General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2 of the License, or (at your option) any later version.
9 : *
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Library General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Library General Public
16 : * License along with this library; if not, write to the
17 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 : * Boston, MA 02111-1307, USA.
19 : */
20 :
21 : #include <config.h>
22 :
23 : #include <assert.h>
24 :
25 : #if HAVE_STDLIB_H
26 : #include <stdlib.h>
27 : #endif /* HAVE_STDLIB_H */
28 :
29 : #if HAVE_STRING_H
30 : #include <string.h>
31 : #endif /* HAVE_STRING_H */
32 :
33 : #include <freetds/time.h>
34 : #include <freetds/odbc.h>
35 : #include <freetds/convert.h>
36 : #include <freetds/iconv.h>
37 : #include <freetds/utils/string.h>
38 : #include <freetds/utils.h>
39 :
40 : TDS_INT
41 538 : convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta)
42 : {
43 : struct tm src_tm;
44 : int tm_dms;
45 : unsigned int dt_time;
46 : int i;
47 : time_t curr_time;
48 :
49 538 : const DATE_STRUCT *src_date = (const DATE_STRUCT *) src;
50 538 : const TIME_STRUCT *src_time = (const TIME_STRUCT *) src;
51 538 : const TIMESTAMP_STRUCT *src_timestamp = (const TIMESTAMP_STRUCT *) src;
52 :
53 538 : memset(dta, 0, sizeof(*dta));
54 :
55 538 : switch (bindtype) {
56 78 : case SQL_C_DATE:
57 : case SQL_C_TYPE_DATE:
58 78 : src_tm.tm_year = src_date->year - 1900;
59 78 : src_tm.tm_mon = src_date->month - 1;
60 78 : src_tm.tm_mday = src_date->day;
61 78 : src_tm.tm_hour = 0;
62 78 : src_tm.tm_min = 0;
63 78 : src_tm.tm_sec = 0;
64 78 : tm_dms = 0;
65 : dta->has_date = 1;
66 78 : break;
67 78 : case SQL_C_TIME:
68 : case SQL_C_TYPE_TIME:
69 : #if HAVE_GETTIMEOFDAY
70 : {
71 : struct timeval tv;
72 78 : gettimeofday(&tv, NULL);
73 78 : curr_time = tv.tv_sec;
74 : }
75 : #else
76 : curr_time = time(NULL);
77 : #endif
78 78 : tds_localtime_r(&curr_time, &src_tm);
79 78 : src_tm.tm_hour = src_time->hour;
80 78 : src_tm.tm_min = src_time->minute;
81 78 : src_tm.tm_sec = src_time->second;
82 78 : tm_dms = 0;
83 : dta->has_time = 1;
84 78 : break;
85 382 : case SQL_C_TIMESTAMP:
86 : case SQL_C_TYPE_TIMESTAMP:
87 382 : src_tm.tm_year = src_timestamp->year - 1900;
88 382 : src_tm.tm_mon = src_timestamp->month - 1;
89 382 : src_tm.tm_mday = src_timestamp->day;
90 382 : src_tm.tm_hour = src_timestamp->hour;
91 382 : src_tm.tm_min = src_timestamp->minute;
92 382 : src_tm.tm_sec = src_timestamp->second;
93 382 : tm_dms = src_timestamp->fraction / 100lu;
94 : dta->has_date = 1;
95 : dta->has_time = 1;
96 382 : break;
97 : default:
98 : return TDS_CONVERT_FAIL;
99 : }
100 :
101 : /* TODO code copied from convert.c, function */
102 538 : i = (src_tm.tm_mon - 13) / 12;
103 538 : dta->has_date = 1;
104 1614 : dta->date = 1461 * (src_tm.tm_year + 300 + i) / 4 +
105 1614 : (367 * (src_tm.tm_mon - 1 - 12 * i)) / 12 - (3 * ((src_tm.tm_year + 400 + i) / 100)) / 4 +
106 1076 : src_tm.tm_mday - 109544;
107 :
108 538 : dta->has_time = 1;
109 538 : dt_time = (src_tm.tm_hour * 60 + src_tm.tm_min) * 60 + src_tm.tm_sec;
110 538 : dta->time = dt_time * UINT64_C(10000000) + tm_dms;
111 538 : return sizeof(TDS_DATETIMEALL);
112 : }
113 :
114 : static char*
115 48 : odbc_wstr2str(TDS_STMT * stmt, const char *src, int* len)
116 : {
117 48 : int srclen = (*len) / sizeof(SQLWCHAR);
118 48 : char *out = tds_new(char, srclen + 1), *p;
119 48 : const SQLWCHAR *wp = (const SQLWCHAR *) src;
120 :
121 48 : if (!out) {
122 0 : odbc_errs_add(&stmt->errs, "HY001", NULL);
123 0 : return NULL;
124 : }
125 :
126 : /* convert */
127 : p = out;
128 432 : for (; srclen && *wp < 256; --srclen)
129 432 : *p++ = (char) *wp++;
130 :
131 : /* still characters, wrong format */
132 48 : if (srclen) {
133 0 : free(out);
134 : /* TODO correct error ?? */
135 0 : odbc_errs_add(&stmt->errs, "07006", NULL);
136 0 : return NULL;
137 : }
138 :
139 48 : *len = p - out;
140 48 : return out;
141 : }
142 :
143 : static void
144 562 : _odbc_blob_free(TDSCOLUMN *col)
145 : {
146 562 : if (!col->column_data)
147 : return;
148 :
149 562 : TDS_ZERO_FREE(col->column_data);
150 : }
151 :
152 : static SQLRETURN
153 8 : odbc_convert_table(TDS_STMT *stmt, SQLTVP *src, TDS_TVP *dest, SQLLEN num_rows)
154 : {
155 : SQLLEN i;
156 : int j;
157 : TDS_TVP_ROW *row;
158 : TDS_TVP_ROW **prow;
159 : TDSPARAMINFO *params, *new_params;
160 8 : TDS_DESC *apd = src->apd, *ipd = src->ipd;
161 : SQLRETURN ret;
162 : char *type_name, *pch;
163 :
164 : /* probably data at execution attempt, currently not supported for TVP */
165 8 : if (num_rows < 0) {
166 0 : odbc_errs_add(&stmt->errs, "HYC00", "Data at execution are not supported for TVP columns");
167 0 : return SQL_ERROR;
168 : }
169 :
170 8 : tds_deinit_tvp(dest);
171 :
172 16 : type_name = strdup(tds_dstr_cstr(&src->type_name));
173 8 : if (!type_name)
174 : goto Memory_Error;
175 :
176 : /* Tokenize and extract the schema & TVP typename from the TVP's full name */
177 8 : pch = strchr(type_name, '.');
178 8 : if (pch == NULL) {
179 8 : dest->schema = tds_strndup("", 0);
180 8 : dest->name = type_name;
181 : } else {
182 0 : *pch = 0;
183 0 : dest->schema = type_name;
184 0 : dest->name = strdup(++pch);
185 : }
186 16 : if (!dest->schema || !dest->name)
187 : goto Memory_Error;
188 :
189 : /* Ensure that the TVP typename does not contain any more '.' */
190 : /* Otherwise, report it as an invalid data type error */
191 8 : pch = strchr(dest->name, '.');
192 8 : if (pch != NULL) {
193 0 : odbc_errs_add(&stmt->errs, "HY004", NULL);
194 0 : return SQL_ERROR;
195 : }
196 :
197 : params = NULL;
198 16 : for (j = 0; j < ipd->header.sql_desc_count; j++) {
199 16 : if (!(new_params = tds_alloc_param_result(params))) {
200 0 : tds_free_param_results(params);
201 0 : goto Memory_Error;
202 : }
203 16 : params = new_params;
204 :
205 16 : ret = odbc_sql2tds(stmt, &ipd->records[j], &apd->records[j], new_params->columns[j], false, apd, 0);
206 16 : if (!SQL_SUCCEEDED(ret)) {
207 0 : tds_free_param_results(params);
208 0 : return ret;
209 : }
210 : }
211 8 : dest->metadata = params;
212 :
213 44 : for (i = 0, prow = &dest->row; i < num_rows; prow = &(*prow)->next, i++) {
214 36 : if ((row = tds_new0(TDS_TVP_ROW, 1)) == NULL)
215 : goto Memory_Error;
216 :
217 36 : *prow = row;
218 :
219 36 : params = NULL;
220 108 : for (j = 0; j < ipd->header.sql_desc_count; j++) {
221 72 : if (!(new_params = tds_alloc_param_result(params))) {
222 0 : tds_free_param_results(params);
223 0 : goto Memory_Error;
224 : }
225 72 : params = new_params;
226 :
227 72 : ret = odbc_sql2tds(stmt, &ipd->records[j], &apd->records[j], new_params->columns[j], true, apd, i);
228 72 : if (!SQL_SUCCEEDED(ret)) {
229 0 : tds_free_param_results(params);
230 0 : return ret;
231 : }
232 : }
233 36 : row->params = params;
234 : }
235 :
236 : return SQL_SUCCESS;
237 :
238 0 : Memory_Error:
239 0 : odbc_errs_add(&stmt->errs, "HY001", NULL);
240 0 : return SQL_ERROR;
241 : }
242 :
243 : /**
244 : * Convert parameters to libtds format
245 : * @param stmt ODBC statement
246 : * @param drec_ixd IRD or IPD record of destination
247 : * @param drec_ard ARD or APD record of source
248 : * @param curcol destination column
249 : * @param compute_row true if data needs to be written to column
250 : * @param axd ARD or APD of source
251 : * @param n_row number of the row to write
252 : * @return SQL_SUCCESS, SQL_ERROR or SQL_NEED_DATA
253 : */
254 : SQLRETURN
255 24676 : odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol,
256 : bool compute_row, const TDS_DESC* axd, unsigned int n_row)
257 : {
258 24676 : TDS_DBC * dbc = stmt->dbc;
259 24676 : TDSCONNECTION * conn = dbc->tds_socket->conn;
260 : TDS_SERVER_TYPE dest_type, src_type;
261 : int sql_src_type, res;
262 : CONV_RESULT ores;
263 : TDSBLOB *blob;
264 : char *src, *converted_src;
265 : unsigned char *dest;
266 : int len;
267 : TDS_DATETIMEALL dta;
268 : TDS_NUMERIC num;
269 : SQL_NUMERIC_STRUCT *sql_num;
270 : SQLINTEGER sql_len;
271 24676 : bool need_data = false;
272 : int i;
273 :
274 : /* TODO handle bindings of char like "{d '2002-11-12'}" */
275 24676 : tdsdump_log(TDS_DBG_INFO2, "type=%d\n", drec_ixd->sql_desc_concise_type);
276 :
277 : /* what type to convert ? */
278 24676 : dest_type = odbc_sql_to_server_type(conn, drec_ixd->sql_desc_concise_type, drec_ixd->sql_desc_unsigned);
279 24676 : if (dest_type == TDS_INVALID_TYPE) {
280 4400 : odbc_errs_add(&stmt->errs, "07006", NULL); /* Restricted data type attribute violation */
281 4400 : return SQL_ERROR;
282 : }
283 20276 : tdsdump_log(TDS_DBG_INFO2, "trace\n");
284 :
285 : /* get C type */
286 20276 : sql_src_type = drec_axd->sql_desc_concise_type;
287 20276 : if (sql_src_type == SQL_C_DEFAULT)
288 0 : sql_src_type = odbc_sql_to_c_type_default(drec_ixd->sql_desc_concise_type);
289 :
290 20276 : tds_set_param_type(conn, curcol, dest_type);
291 :
292 : /* TODO what happen for unicode types ?? */
293 20276 : if (is_char_type(dest_type)) {
294 7014 : TDSICONV *conv = conn->char_convs[is_unicode_type(dest_type) ? client2ucs2 : client2server_chardata];
295 :
296 : /* use binary format for binary to char */
297 7014 : if (sql_src_type == SQL_C_BINARY) {
298 334 : curcol->char_conv = NULL;
299 6680 : } else if (sql_src_type == SQL_C_WCHAR) {
300 516 : curcol->char_conv = tds_iconv_get_info(conn, odbc_get_wide_canonic(conn), conv->to.charset.canonic);
301 516 : memcpy(curcol->column_collation, conn->collation, sizeof(conn->collation));
302 : } else {
303 : #ifdef ENABLE_ODBC_WIDE
304 6164 : curcol->char_conv = tds_iconv_get_info(conn, dbc->original_charset_num, conv->to.charset.canonic);
305 : #else
306 : curcol->char_conv = NULL;
307 : #endif
308 : }
309 : }
310 20276 : if (is_numeric_type(curcol->column_type)) {
311 970 : curcol->column_prec = drec_ixd->sql_desc_precision;
312 970 : curcol->column_scale = drec_ixd->sql_desc_scale;
313 : }
314 :
315 20276 : if (drec_ixd->sql_desc_parameter_type != SQL_PARAM_INPUT)
316 11510 : curcol->column_output = 1;
317 :
318 : /* compute destination length */
319 20276 : if (curcol->column_varint_size != 0) {
320 : /* curcol->column_size = drec_axd->sql_desc_octet_length; */
321 : /*
322 : * TODO destination length should come from sql_desc_length,
323 : * however there is the encoding problem to take into account
324 : * we should fill destination length after conversion keeping
325 : * attention to fill correctly blob/fixed type/variable type
326 : */
327 : /* TODO location of this test is correct here ?? */
328 20122 : if (dest_type != SYBUNIQUE && !is_fixed_type(dest_type)) {
329 10512 : curcol->column_cur_size = 0;
330 10512 : curcol->column_size = drec_ixd->sql_desc_length;
331 : /* Ensure that the column_cur_size and column_size are consistent, */
332 : /* since drec_ixd->sql_desc_length contains the number of rows for a TVP */
333 10512 : if (dest_type == SYBMSTABLE)
334 8 : curcol->column_size = sizeof(TDS_TVP);
335 10512 : if (curcol->column_size < 0) {
336 10 : curcol->on_server.column_size = curcol->column_size = 0x7FFFFFFFl;
337 : } else {
338 10502 : if (is_unicode_type(dest_type))
339 2094 : curcol->on_server.column_size = curcol->column_size * 2;
340 : else
341 8408 : curcol->on_server.column_size = curcol->column_size;
342 : }
343 : }
344 154 : } else if (dest_type != SYBBIT) {
345 : /* TODO only a trick... */
346 12 : tds_set_param_type(conn, curcol, tds_get_null_type(dest_type));
347 : }
348 :
349 : /* test source type */
350 : /* TODO test intervals */
351 20276 : src_type = odbc_c_to_server_type(sql_src_type);
352 20276 : if (!src_type) {
353 6220 : odbc_errs_add(&stmt->errs, "07006", NULL); /* Restricted data type attribute violation */
354 6220 : return SQL_ERROR;
355 : }
356 :
357 : /* we have no data to convert, just return */
358 14056 : if (!compute_row)
359 : return SQL_SUCCESS;
360 :
361 14040 : src = (char *) drec_axd->sql_desc_data_ptr;
362 14040 : if (src && n_row) {
363 : SQLLEN len;
364 2282 : if (axd->header.sql_desc_bind_type != SQL_BIND_BY_COLUMN) {
365 0 : len = axd->header.sql_desc_bind_type;
366 0 : if (axd->header.sql_desc_bind_offset_ptr)
367 0 : src += *axd->header.sql_desc_bind_offset_ptr;
368 : } else {
369 2282 : len = odbc_get_octet_len(sql_src_type, drec_axd);
370 2282 : if (len < 0)
371 : /* TODO sure ? what happen to upper layer ?? */
372 : /* TODO fill error */
373 : return SQL_ERROR;
374 : }
375 2282 : src += len * n_row;
376 : }
377 :
378 : /* if only output assume input is NULL */
379 14040 : if (drec_ixd->sql_desc_parameter_type == SQL_PARAM_OUTPUT) {
380 : sql_len = SQL_NULL_DATA;
381 : } else {
382 13098 : sql_len = odbc_get_param_len(drec_axd, drec_ixd, axd, n_row);
383 :
384 : /* special case, MS ODBC handle conversion from "\0" to any to NULL, DBD::ODBC require it */
385 13098 : if (src_type == SYBVARCHAR && sql_len == 1 && drec_ixd->sql_desc_parameter_type == SQL_PARAM_INPUT_OUTPUT
386 0 : && src && *src == 0) {
387 : sql_len = SQL_NULL_DATA;
388 : }
389 : }
390 :
391 : /* compute source length */
392 13098 : switch (sql_len) {
393 1440 : case SQL_NULL_DATA:
394 1440 : len = 0;
395 : break;
396 3100 : case SQL_NTS:
397 : /* check that SQLBindParameter::ParameterValuePtr is not zero for input parameters */
398 3100 : if (!src) {
399 490 : odbc_errs_add(&stmt->errs, "HY090", NULL);
400 490 : return SQL_ERROR;
401 : }
402 2610 : if (sql_src_type == SQL_C_WCHAR)
403 96 : len = sqlwcslen((const SQLWCHAR *) src) * sizeof(SQLWCHAR);
404 : else
405 2514 : len = strlen(src);
406 : break;
407 0 : case SQL_DEFAULT_PARAM:
408 0 : odbc_errs_add(&stmt->errs, "07S01", NULL); /* Invalid use of default parameter */
409 0 : return SQL_ERROR;
410 : break;
411 9500 : case SQL_DATA_AT_EXEC:
412 : default:
413 9500 : len = sql_len;
414 9500 : if (sql_len < 0) {
415 : /* test for SQL_C_CHAR/SQL_C_BINARY */
416 : switch (sql_src_type) {
417 : case SQL_C_CHAR:
418 : case SQL_C_WCHAR:
419 : case SQL_C_BINARY:
420 : break;
421 0 : default:
422 0 : odbc_errs_add(&stmt->errs, "HY090", NULL);
423 0 : return SQL_ERROR;
424 : }
425 342 : len = SQL_LEN_DATA_AT_EXEC(sql_len);
426 342 : need_data = true;
427 :
428 : /* dynamic length allowed only for variable fields */
429 342 : switch (drec_ixd->sql_desc_concise_type) {
430 : case SQL_CHAR:
431 : case SQL_VARCHAR:
432 : case SQL_LONGVARCHAR:
433 : case SQL_WCHAR:
434 : case SQL_WVARCHAR:
435 : case SQL_WLONGVARCHAR:
436 : case SQL_BINARY:
437 : case SQL_VARBINARY:
438 : case SQL_LONGVARBINARY:
439 : break;
440 0 : default:
441 0 : odbc_errs_add(&stmt->errs, "HY090", NULL);
442 0 : return SQL_ERROR;
443 : }
444 9158 : }
445 : }
446 :
447 : /* set NULL. For NULLs we don't need to allocate row buffer so avoid it */
448 : if (!need_data) {
449 13208 : assert(drec_ixd->sql_desc_parameter_type != SQL_PARAM_OUTPUT || sql_len == SQL_NULL_DATA);
450 13208 : if (sql_len == SQL_NULL_DATA) {
451 1440 : curcol->column_cur_size = -1;
452 1440 : return SQL_SUCCESS;
453 : }
454 : }
455 :
456 12110 : if (is_char_type(dest_type) && !need_data
457 4678 : && (sql_src_type == SQL_C_CHAR || sql_src_type == SQL_C_WCHAR || sql_src_type == SQL_C_BINARY)) {
458 3528 : if (curcol->column_data && curcol->column_data_free)
459 0 : curcol->column_data_free(curcol);
460 3528 : curcol->column_data_free = NULL;
461 3528 : if (is_blob_col(curcol)) {
462 : /* trick to set blob without freeing it, _odbc_blob_free does not free TDSBLOB->textvalue */
463 562 : TDSBLOB *blob = tds_new0(TDSBLOB, 1);
464 562 : if (!blob) {
465 0 : odbc_errs_add(&stmt->errs, "HY001", NULL);
466 0 : return SQL_ERROR;
467 : }
468 562 : blob->textvalue = src;
469 562 : curcol->column_data = (TDS_UCHAR*) blob;
470 562 : curcol->column_data_free = _odbc_blob_free;
471 : } else {
472 2966 : curcol->column_data = (TDS_UCHAR*) src;
473 : }
474 3528 : curcol->column_size = len;
475 3528 : curcol->column_cur_size = len;
476 3528 : return SQL_SUCCESS;
477 : }
478 :
479 : /* allocate given space */
480 8582 : if (!tds_alloc_param_data(curcol)) {
481 0 : odbc_errs_add(&stmt->errs, "HY001", NULL);
482 0 : return SQL_ERROR;
483 : }
484 :
485 : /* fill data with SQLPutData */
486 8582 : if (need_data) {
487 342 : curcol->column_cur_size = 0;
488 342 : return SQL_NEED_DATA;
489 : }
490 :
491 8240 : if (!src) {
492 3830 : odbc_errs_add(&stmt->errs, "HY090", NULL);
493 3830 : return SQL_ERROR;
494 : }
495 :
496 : /* convert special parameters (not libTDS compatible) */
497 4410 : switch (src_type) {
498 534 : case SYBMSDATETIME2:
499 534 : convert_datetime2server(sql_src_type, src, &dta);
500 534 : src = (char *) &dta;
501 534 : break;
502 182 : case SYBDECIMAL:
503 : case SYBNUMERIC:
504 182 : sql_num = (SQL_NUMERIC_STRUCT *) src;
505 182 : num.precision = sql_num->precision;
506 182 : num.scale = sql_num->scale;
507 182 : num.array[0] = sql_num->sign ^ 1;
508 : /* test precision so client do not crash our library */
509 182 : if (num.precision <= 0 || num.precision > 38 || num.scale > num.precision)
510 : /* TODO add proper error */
511 : return SQL_ERROR;
512 182 : i = tds_numeric_bytes_per_prec[num.precision];
513 182 : memcpy(num.array + 1, sql_num->val, i - 1);
514 182 : tds_swap_bytes(num.array + 1, i - 1);
515 182 : if (i < sizeof(num.array))
516 182 : memset(num.array + i, 0, sizeof(num.array) - i);
517 : src = (char *) #
518 : break;
519 : /* TODO intervals */
520 : default:
521 : /* prevents some compiler warnings about missing cases */
522 : break;
523 : }
524 :
525 4410 : converted_src = NULL;
526 4410 : if (sql_src_type == SQL_C_WCHAR) {
527 48 : converted_src = src = odbc_wstr2str(stmt, src, &len);
528 48 : if (!src)
529 : /* TODO add proper error */
530 : return SQL_ERROR;
531 : src_type = SYBVARCHAR;
532 : }
533 :
534 4410 : dest = curcol->column_data;
535 4410 : switch ((TDS_SERVER_TYPE) dest_type) {
536 164 : case SYBCHAR:
537 : case SYBVARCHAR:
538 : case XSYBCHAR:
539 : case XSYBVARCHAR:
540 : case XSYBNVARCHAR:
541 : case XSYBNCHAR:
542 : case SYBNVARCHAR:
543 164 : ores.cc.c = (TDS_CHAR*) dest;
544 164 : ores.cc.len = curcol->column_size;
545 164 : res = tds_convert(dbc->env->tds_ctx, src_type, src, len, TDS_CONVERT_CHAR, &ores);
546 164 : if (res > curcol->column_size)
547 0 : res = curcol->column_size;
548 : break;
549 234 : case SYBBINARY:
550 : case SYBVARBINARY:
551 : case XSYBBINARY:
552 : case XSYBVARBINARY:
553 234 : ores.cb.ib = (TDS_CHAR*) dest;
554 234 : ores.cb.len = curcol->column_size;
555 234 : res = tds_convert(dbc->env->tds_ctx, src_type, src, len, TDS_CONVERT_BINARY, &ores);
556 234 : if (res > curcol->column_size)
557 0 : res = curcol->column_size;
558 : break;
559 48 : case SYBNTEXT:
560 48 : dest_type = SYBTEXT;
561 256 : case SYBTEXT:
562 : case SYBLONGBINARY:
563 : case SYBIMAGE:
564 256 : res = tds_convert(dbc->env->tds_ctx, src_type, src, len, dest_type, &ores);
565 256 : if (res >= 0) {
566 256 : blob = (TDSBLOB *) dest;
567 256 : free(blob->textvalue);
568 256 : blob->textvalue = ores.ib;
569 : }
570 : break;
571 74 : case SYBNUMERIC:
572 : case SYBDECIMAL:
573 74 : ((TDS_NUMERIC *) dest)->precision = drec_ixd->sql_desc_precision;
574 74 : ((TDS_NUMERIC *) dest)->scale = drec_ixd->sql_desc_scale;
575 3748 : case SYBINTN:
576 : case SYBINT1:
577 : case SYBINT2:
578 : case SYBINT4:
579 : case SYBINT8:
580 : case SYBFLT8:
581 : case SYBDATETIME:
582 : case SYBBIT:
583 : case SYBMONEY4:
584 : case SYBMONEY:
585 : case SYBDATETIME4:
586 : case SYBREAL:
587 : case SYBBITN:
588 : case SYBFLTN:
589 : case SYBMONEYN:
590 : case SYBDATETIMN:
591 : case SYBSINT1:
592 : case SYBUINT2:
593 : case SYBUINT4:
594 : case SYBUINT8:
595 : case SYBUNIQUE:
596 : case SYBMSTIME:
597 : case SYBMSDATE:
598 : case SYBMSDATETIME2:
599 : case SYBMSDATETIMEOFFSET:
600 : case SYB5BIGTIME:
601 : case SYB5BIGDATETIME:
602 3748 : res = tds_convert(dbc->env->tds_ctx, src_type, src, len, dest_type, (CONV_RESULT*) dest);
603 3748 : break;
604 8 : case SYBMSTABLE:
605 8 : free(converted_src);
606 8 : src = drec_ixd->sql_desc_data_ptr;
607 8 : curcol->column_cur_size = sizeof(TDS_TVP);
608 8 : return odbc_convert_table(stmt, (SQLTVP *) src, (TDS_TVP *) dest,
609 8 : drec_axd->sql_desc_octet_length_ptr == NULL ? 1 : *drec_axd->sql_desc_octet_length_ptr);
610 : default:
611 : case SYBVOID:
612 : case SYBVARIANT:
613 : /* TODO ODBC 3.5 */
614 0 : assert(0);
615 : res = -1;
616 : break;
617 : }
618 :
619 4402 : free(converted_src);
620 4402 : if (res < 0) {
621 0 : odbc_convert_err_set(&stmt->errs, res);
622 0 : return SQL_ERROR;
623 : }
624 :
625 4402 : curcol->column_cur_size = res;
626 :
627 4402 : return SQL_SUCCESS;
628 : }
|