FreeTDS API

odbc.h
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) 2004-2010 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 #ifndef _sql_h_
22 #define _sql_h_
23
24 #define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS
25 #include <freetds/tds.h>
26 #include <freetds/thread.h>
27 #include <freetds/data.h>
28
29 #if defined(UNIXODBC) || defined(_WIN32) || defined(TDS_NO_DM)
30 #include <sql.h>
31 #include <sqlext.h>
32 #if defined(UNIXODBC) || defined(_WIN32)
33 #include <odbcinst.h>
34 #endif
35 #else /* IODBC */
36 #include <isql.h>
37 #include <isqlext.h>
38 #ifdef HAVE_IODBCINST_H
39 #include <iodbcinst.h>
40 #endif /* HAVE_IODBCINST_H */
41 #endif
42
43 #ifndef HAVE_SQLLEN
44 #ifndef SQLULEN
45 #define SQLULEN SQLUINTEGER
46 #endif
47 #ifndef SQLLEN
48 #define SQLLEN SQLINTEGER
49 #endif
50 #endif
51
52 #ifndef HAVE_SQLSETPOSIROW
53 #define SQLSETPOSIROW SQLUSMALLINT
54 #endif
55
56 #ifndef HAVE_SQLROWOFFSET
57 #define SQLROWOFFSET SQLLEN
58 #endif
59
60 #ifndef HAVE_SQLROWSETSIZE
61 #define SQLROWSETSIZE SQLULEN
62 #endif
63
64 #ifdef __cplusplus
65 extern "C"
66 {
67 #if 0
68 }
69 #endif
70 #endif
71
72 #include <freetds/pushvis.h>
73 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
74 #define ODBC_API SQL_API __attribute__((externally_visible))
75 #else
76 #define ODBC_API SQL_API
77 #endif
78
79 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(__GNUC__)
80 # define ODBC_PUBLIC __attribute__((dllexport))
81 #else
82 # define ODBC_PUBLIC
83 #endif
84
85 #define ODBC_MAX(a,b) ( (a) > (b) ? (a) : (b) )
86 #define ODBC_MIN(a,b) ( (a) < (b) ? (a) : (b) )
87
88 struct _sql_error
89 {
90 const char *msg;
91 char state2[6];
92 char state3[6];
93 TDS_UINT native;
94 char *server;
95 int linenum;
96 int msgstate;
97 int row;
98 };
99
100 struct _sql_errors
101 {
102 struct _sql_error *errs;
103 int num_errors;
104 SQLRETURN lastrc;
105 char ranked;
106 };
107
108 typedef struct _sql_errors TDS_ERRS;
109
110 #if ENABLE_EXTRA_CHECKS
111 void odbc_check_struct_extra(void *p);
112 #else
113 static inline void odbc_check_struct_extra(void *p) {}
114 #endif
115
116 #define ODBC_RETURN(handle, rc) \
117 do { odbc_check_struct_extra(handle); \
118 return handle->errs.lastrc = (rc); } while(0)
119 #define ODBC_RETURN_(handle) \
120 do { odbc_check_struct_extra(handle); \
121 return handle->errs.lastrc; } while(0)
122
123 #define ODBC_EXIT(handle, rc) \
124 do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
125 odbc_check_struct_extra(handle); \
126 tds_mutex_unlock(&handle->mtx); \
127 return _odbc_rc; } while(0)
128 #define ODBC_EXIT_(handle) \
129 do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
130 odbc_check_struct_extra(handle); \
131 tds_mutex_unlock(&handle->mtx); \
132 return _odbc_rc; } while(0)
133
134
136 void odbc_errs_reset(struct _sql_errors *errs);
137
139 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
140
142 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
143 int msgstate, const char *server, int row);
144
145 struct _dheader
146 {
147 SQLSMALLINT sql_desc_alloc_type;
148 SQLINTEGER sql_desc_bind_type;
149 SQLULEN sql_desc_array_size;
150 /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
151 SQLSMALLINT sql_desc_count;
152 SQLUSMALLINT *sql_desc_array_status_ptr;
153 SQLULEN *sql_desc_rows_processed_ptr;
154 SQLLEN *sql_desc_bind_offset_ptr;
155 };
156
157 struct _drecord
158 {
159 SQLUINTEGER sql_desc_auto_unique_value;
160 DSTR sql_desc_base_column_name;
161 DSTR sql_desc_base_table_name;
162 SQLINTEGER sql_desc_case_sensitive;
163 DSTR sql_desc_catalog_name;
164 SQLSMALLINT sql_desc_concise_type;
165 SQLPOINTER sql_desc_data_ptr;
166 SQLSMALLINT sql_desc_datetime_interval_code;
167 SQLINTEGER sql_desc_datetime_interval_precision;
168 SQLLEN sql_desc_display_size;
169 SQLSMALLINT sql_desc_fixed_prec_scale;
170 SQLLEN *sql_desc_indicator_ptr;
171 DSTR sql_desc_label;
172 SQLULEN sql_desc_length;
173 /* this point to a constant buffer, do not free or modify */
174 const char *sql_desc_literal_prefix;
175 /* this point to a constant buffer, do not free or modify */
176 const char *sql_desc_literal_suffix;
177 DSTR sql_desc_local_type_name;
178 DSTR sql_desc_name;
179 SQLSMALLINT sql_desc_nullable;
180 SQLINTEGER sql_desc_num_prec_radix;
181 SQLLEN sql_desc_octet_length;
182 SQLLEN *sql_desc_octet_length_ptr;
183 SQLSMALLINT sql_desc_parameter_type;
184 SQLSMALLINT sql_desc_precision;
185 SQLSMALLINT sql_desc_rowver;
186 SQLSMALLINT sql_desc_scale;
187 DSTR sql_desc_schema_name;
188 SQLSMALLINT sql_desc_searchable;
189 DSTR sql_desc_table_name;
190 SQLSMALLINT sql_desc_type;
191 /* this point to a constant buffer, do not free or modify */
192 const char *sql_desc_type_name;
193 SQLSMALLINT sql_desc_unnamed;
194 SQLSMALLINT sql_desc_unsigned;
195 SQLSMALLINT sql_desc_updatable;
196 };
197
198 struct _hdesc
199 {
200 SQLSMALLINT htype; /* do not reorder this field */
201 struct _sql_errors errs; /* do not reorder this field */
202 tds_mutex mtx;
203 int type;
204 SQLHANDLE parent;
205 struct _dheader header;
206 struct _drecord *records;
207 };
208
209 typedef struct _hdesc TDS_DESC;
210
211 #define DESC_IRD 1
212 #define DESC_IPD 2
213 #define DESC_ARD 3
214 #define DESC_APD 4
215
216 struct _heattr
217 {
218 SQLUINTEGER connection_pooling;
219 SQLUINTEGER cp_match;
220 SQLINTEGER odbc_version;
221 SQLINTEGER output_nts;
222 };
223
224 struct _hchk
225 {
226 SQLSMALLINT htype; /* do not reorder this field */
227 struct _sql_errors errs; /* do not reorder this field */
228 tds_mutex mtx;
229 };
230
231 struct _henv
232 {
233 SQLSMALLINT htype; /* do not reorder this field */
234 struct _sql_errors errs; /* do not reorder this field */
235 tds_mutex mtx;
236 TDSCONTEXT *tds_ctx;
237 struct _heattr attr;
238 };
239
240 struct _hcattr
241 {
242 SQLUINTEGER access_mode;
243 SQLUINTEGER async_enable;
244 SQLUINTEGER auto_ipd;
245 SQLUINTEGER autocommit;
246 SQLUINTEGER connection_dead;
247 SQLUINTEGER connection_timeout;
248 DSTR current_catalog;
249 SQLUINTEGER login_timeout;
250 SQLUINTEGER metadata_id;
251 SQLUINTEGER odbc_cursors;
252 SQLUINTEGER packet_size;
253 SQLHWND quite_mode;
254 DSTR translate_lib;
255 SQLUINTEGER translate_option;
256 SQLUINTEGER txn_isolation;
257 SQLUINTEGER mars_enabled;
258 SQLUINTEGER cursor_type;
259 SQLUINTEGER bulk_enabled;
260 #ifdef TDS_NO_DM
261 SQLUINTEGER trace;
262 DSTR tracefile;
263 #endif
264 };
265
266 #define TDS_MAX_APP_DESC 100
267
268 struct _hstmt;
269 struct _hdbc
270 {
271 SQLSMALLINT htype; /* do not reorder this field */
272 struct _sql_errors errs; /* do not reorder this field */
273 tds_mutex mtx;
274 struct _henv *env;
275 TDSSOCKET *tds_socket;
276 DSTR dsn;
277 DSTR oldpwd;
278 #ifdef ENABLE_ODBC_WIDE
279 DSTR original_charset;
280 TDSICONV *mb_conv;
281 #endif
282
288 struct _hstmt *current_statement;
290 struct _hstmt *stmt_list;
291 struct _hcattr attr;
293 TDS_DESC *uad[TDS_MAX_APP_DESC];
295 unsigned int cursor_support:1;
296 unsigned int use_oldpwd:1;
297 TDS_INT default_query_timeout;
298
299 TDSBCPINFO *bcpinfo;
300 char *bcphint;
301 };
302
303 struct _hsattr
304 {
305 /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
306 /* TDS_DESC *app_row_desc; */
307 /* TDS_DESC *app_param_desc; */
308 SQLUINTEGER async_enable;
309 SQLUINTEGER concurrency;
310 SQLUINTEGER cursor_scrollable;
311 SQLUINTEGER cursor_sensitivity;
312 SQLUINTEGER cursor_type;
313 SQLUINTEGER enable_auto_ipd;
314 SQLPOINTER fetch_bookmark_ptr;
315 SQLULEN keyset_size;
316 SQLULEN max_length;
317 SQLULEN max_rows;
318 SQLUINTEGER metadata_id;
319 SQLUINTEGER noscan;
320 /* apd->sql_desc_bind_offset_ptr */
321 /* SQLUINTEGER *param_bind_offset_ptr; */
322 /* apd->sql_desc_bind_type */
323 /* SQLUINTEGER param_bind_type; */
324 /* apd->sql_desc_array_status_ptr */
325 /* SQLUSMALLINT *param_operation_ptr; */
326 /* ipd->sql_desc_array_status_ptr */
327 /* SQLUSMALLINT *param_status_ptr; */
328 /* ipd->sql_desc_rows_processed_ptr */
329 /* SQLUSMALLINT *params_processed_ptr; */
330 /* apd->sql_desc_array_size */
331 /* SQLUINTEGER paramset_size; */
332 SQLUINTEGER query_timeout;
333 SQLUINTEGER retrieve_data;
334 /* ard->sql_desc_bind_offset_ptr */
335 /* SQLUINTEGER *row_bind_offset_ptr; */
336 /* ard->sql_desc_array_size */
337 /* SQLUINTEGER row_array_size; */
338 /* ard->sql_desc_bind_type */
339 /* SQLUINTEGER row_bind_type; */
340 SQLULEN row_number;
341 /* ard->sql_desc_array_status_ptr */
342 /* SQLUINTEGER *row_operation_ptr; */
343 /* ird->sql_desc_array_status_ptr */
344 /* SQLUINTEGER *row_status_ptr; */
345 /* ird->sql_desc_rows_processed_ptr */
346 /* SQLUINTEGER *rows_fetched_ptr; */
347 SQLUINTEGER simulate_cursor;
348 SQLUINTEGER use_bookmarks;
349 /* SQLGetStmtAttr only */
350 /* TDS_DESC *imp_row_desc; */
351 /* TDS_DESC *imp_param_desc; */
352 DSTR qn_msgtext;
353 DSTR qn_options;
354 SQLUINTEGER qn_timeout;
355 };
356
357 typedef enum
358 {
359 NOT_IN_ROW,
360 IN_NORMAL_ROW,
361 IN_COMPUTE_ROW,
362 AFTER_COMPUTE_ROW,
363 PRE_NORMAL_ROW
364 } TDS_ODBC_ROW_STATUS;
365
366 typedef enum
367 {
368 ODBC_SPECIAL_NONE = 0,
369 ODBC_SPECIAL_GETTYPEINFO = 1,
370 ODBC_SPECIAL_COLUMNS = 2,
371 ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
372 ODBC_SPECIAL_SPECIALCOLUMNS = 4
373 } TDS_ODBC_SPECIAL_ROWS;
374
375 struct _hstmt
376 {
377 SQLSMALLINT htype; /* do not reorder this field */
378 struct _sql_errors errs; /* do not reorder this field */
379 tds_mutex mtx;
380 struct _hdbc *dbc;
382 DSTR query;
384 TDSSOCKET *tds;
385
387 struct _hstmt *next;
389 struct _hstmt *prev;
390
391 /* begin prepared query stuff */
392 unsigned is_prepared_query:1;
393 unsigned prepared_query_is_func:1;
394 unsigned prepared_query_is_rpc:1;
395 unsigned need_reprepare:1;
396 unsigned param_data_called:1;
397 /* end prepared query stuff */
398
400 TDSPARAMINFO *params;
402 int param_num;
404 char *prepared_pos;
405
406 unsigned int curr_param_row, num_param_rows;
407
409 unsigned int param_count;
410 int row;
412 TDS_INT8 row_count;
414 TDS_ODBC_ROW_STATUS row_status;
415 /* do NOT free dynamic, free from socket or attach to connection */
416 TDSDYNAMIC *dyn;
417 TDS_DESC *ard, *ird, *apd, *ipd;
418 TDS_DESC *orig_ard, *orig_apd;
419 SQLULEN sql_rowset_size;
420 struct _hsattr attr;
421 DSTR cursor_name; /* auto generated cursor name */
422 TDS_ODBC_SPECIAL_ROWS special_row;
423 /* do NOT free cursor, free from socket or attach to connection */
424 TDSCURSOR *cursor;
425 };
426
427 typedef struct _henv TDS_ENV;
428 typedef struct _hdbc TDS_DBC;
429 typedef struct _hstmt TDS_STMT;
430 typedef struct _hchk TDS_CHK;
431
432 typedef struct {
433 /* this must be the first member */
434 TDSCOLUMNFUNCS common;
435 void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
436 } TDS_FUNCS;
437
438 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
439 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
440 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
441 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
442
443 /* fix a bug in MingW headers */
444 #ifdef __MINGW32__
445 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
446
447 #undef SQL_INTERVAL_YEAR
448 #undef SQL_INTERVAL_MONTH
449 #undef SQL_INTERVAL_DAY
450 #undef SQL_INTERVAL_HOUR
451 #undef SQL_INTERVAL_MINUTE
452 #undef SQL_INTERVAL_SECOND
453 #undef SQL_INTERVAL_YEAR_TO_MONTH
454 #undef SQL_INTERVAL_DAY_TO_HOUR
455 #undef SQL_INTERVAL_DAY_TO_MINUTE
456 #undef SQL_INTERVAL_DAY_TO_SECOND
457 #undef SQL_INTERVAL_HOUR_TO_MINUTE
458 #undef SQL_INTERVAL_HOUR_TO_SECOND
459 #undef SQL_INTERVAL_MINUTE_TO_SECOND
460
461 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
462 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
463 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
464 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
465 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
466 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
467 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
468 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
469 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
470 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
471 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
472 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
473 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
474
475 #endif
476 #endif
477
478 #ifdef _WIN32
479 BOOL get_login_info(HWND hwndParent, TDSLOGIN * login);
480 #endif
481
482 #define ODBC_PARAM_LIST \
483 ODBC_PARAM(Servername) \
484 ODBC_PARAM(Server) \
485 ODBC_PARAM(DSN) \
486 ODBC_PARAM(UID) \
487 ODBC_PARAM(PWD) \
488 ODBC_PARAM(Address) \
489 ODBC_PARAM(Port) \
490 ODBC_PARAM(TDS_Version) \
491 ODBC_PARAM(Language) \
492 ODBC_PARAM(Database) \
493 ODBC_PARAM(TextSize) \
494 ODBC_PARAM(PacketSize) \
495 ODBC_PARAM(ClientCharset) \
496 ODBC_PARAM(DumpFile) \
497 ODBC_PARAM(DumpFileAppend) \
498 ODBC_PARAM(DebugFlags) \
499 ODBC_PARAM(Encryption) \
500 ODBC_PARAM(Trusted_Connection) \
501 ODBC_PARAM(APP) \
502 ODBC_PARAM(WSID) \
503 ODBC_PARAM(UseNTLMv2) \
504 ODBC_PARAM(MARS_Connection) \
505 ODBC_PARAM(REALM) \
506 ODBC_PARAM(ServerSPN) \
507 ODBC_PARAM(AttachDbFilename) \
508 ODBC_PARAM(ApplicationIntent)
509
510 #define ODBC_PARAM(p) ODBC_PARAM_##p,
511 enum {
512 ODBC_PARAM_LIST
513 ODBC_PARAM_SIZE
514 };
515 #undef ODBC_PARAM
516
517
518 /*
519 * connectparams.h
520 */
521
522 typedef struct {
523 const char *p;
524 size_t len;
525 } TDS_PARSED_PARAM;
526
534 int odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
535 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
536 #ifdef _WIN32
537 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
538 #endif
539
540 /*
541 * convert_tds2sql.c
542 */
543 SQLLEN odbc_tds2sql(TDS_STMT * stmt, TDSCOLUMN *curcol, int srctype, TDS_CHAR * src, TDS_UINT srclen, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
544
545 /*
546 * descriptor.c
547 */
548 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
549 SQLRETURN desc_free(TDS_DESC * desc);
550 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
551 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
552 SQLRETURN desc_free_records(TDS_DESC * desc);
553 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
554
555 /*
556 * odbc.c
557 */
558 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
559
560 /*
561 * odbc_checks.h
562 */
563 #if ENABLE_EXTRA_CHECKS
564 /* macro */
565 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
566 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
567 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
568 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
569 /* declarations*/
570 void odbc_check_env_extra(TDS_ENV * env);
571 void odbc_check_dbc_extra(TDS_DBC * dbc);
572 void odbc_check_stmt_extra(TDS_STMT * stmt);
573 void odbc_check_desc_extra(TDS_DESC * desc);
574 #else
575 /* macro */
576 #define CHECK_ENV_EXTRA(env)
577 #define CHECK_DBC_EXTRA(dbc)
578 #define CHECK_STMT_EXTRA(stmt)
579 #define CHECK_DESC_EXTRA(desc)
580 #endif
581
582 /*
583 * odbc_util.h
584 */
585
586 /* helpers for ODBC wide string support */
587 #undef _wide
588 #undef _WIDE
589 #ifdef ENABLE_ODBC_WIDE
590 typedef union {
591 char mb[1];
592 SQLWCHAR wide[1];
593 } ODBC_CHAR;
594 # define _wide ,wide
595 # define _wide0 ,0
596 # define _WIDE ,int wide
597 #else
598 # define _wide
599 # define _wide0
600 # define _WIDE
601 # define ODBC_CHAR SQLCHAR
602 #endif
603 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
604 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
605 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
606
607 void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
608
609 int odbc_sql_to_c_type_default(int sql_type);
610 TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
611 TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
612
613 unsigned int odbc_get_string_size(int size, const ODBC_CHAR * str _WIDE);
614 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
615 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
616
617 #ifdef ENABLE_ODBC_WIDE
618 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
619 #define odbc_dstr_copy(dbc, s, len, out) \
620 odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
621 #define odbc_dstr_copy_oct(dbc, s, len, out) \
622 odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
623 #else
624 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
625 #define odbc_dstr_copy_oct odbc_dstr_copy
626 #endif
627
628
629 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
630 #ifdef ENABLE_ODBC_WIDE
631 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
632 odbc_set_string_flag(dbc, sizeof((buf)->mb) ? (buf) : (buf), buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
633 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
634 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
635 #else
636 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
637 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
638 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
639 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
640 #endif
641
642 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
643 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
644 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
645 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
646
647 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
648 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
649
650 /*
651 * prepare_query.c
652 */
653 SQLRETURN prepare_call(struct _hstmt *stmt);
654 SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
655 int parse_prepared_query(struct _hstmt *stmt, int compute_row);
656 int start_parse_prepared_query(struct _hstmt *stmt, int compute_row);
657 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
658 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
659 const char *odbc_skip_rpc_name(const char *s);
660
661 /*
662 * sql2tds.c
663 */
664 SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol, int compute_row, const TDS_DESC* axd, unsigned int n_row);
665 TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
666
667 /*
668 * bcp.c
669 */
670 void odbc_bcp_free_storage(TDS_DBC *dbc);
671 void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
672 void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
673 void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
674 void odbc_bcp_sendrow(TDS_DBC *dbc);
675 int odbc_bcp_batch(TDS_DBC *dbc);
676 int odbc_bcp_done(TDS_DBC *dbc);
677 void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
678
679 /*
680 * sqlwchar.c
681 */
682 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
683 size_t sqlwcslen(const SQLWCHAR * s);
684
685 typedef struct sqlwstr_buf {
686 struct sqlwstr_buf *next;
687 wchar_t buf[256];
688 } SQLWSTRBUF;
689 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
690 void sqlwstr_free(SQLWSTRBUF *bufs);
691 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
692 #define SQLWSTR(s) sqlwstr(s, &bufs)
693 #define SQLWSTR_FREE() sqlwstr_free(bufs)
694 #else
695 #define sqlwcslen(s) wcslen(s)
696
697 #define SQLWSTR_BUFS(n) do {} while(0)
698 #define SQLWSTR(s) ((const wchar_t*)(s))
699 #define SQLWSTR_FREE() do {} while(0)
700 #endif
701
702 #if SIZEOF_SQLWCHAR == 2
703 # if WORDS_BIGENDIAN
704 # define ODBC_WIDE_NAME "UCS-2BE"
705 # define ODBC_WIDE_NAME_UTF "UTF-16BE"
706 # else
707 # define ODBC_WIDE_NAME "UCS-2LE"
708 # define ODBC_WIDE_NAME_UTF "UTF-16LE"
709 # endif
710 const char *odbc_get_wide_name(TDSCONNECTION *conn);
711 #elif SIZEOF_SQLWCHAR == 4
712 # if WORDS_BIGENDIAN
713 # define ODBC_WIDE_NAME "UCS-4BE"
714 # else
715 # define ODBC_WIDE_NAME "UCS-4LE"
716 # endif
717 static inline const char *
718 odbc_get_wide_name(TDSCONNECTION *conn)
719 {
720 return ODBC_WIDE_NAME;
721 }
722 #else
723 #error SIZEOF_SQLWCHAR not supported !!
724 #endif
725
726 #include <freetds/popvis.h>
727
728 #ifdef __cplusplus
729 #if 0
730 {
731 #endif
732 }
733 #endif
734
735 #endif
tds_bcpinfo
Definition: tds.h:1605
_hstmt
Definition: odbc.h:375
_hstmt::row_status
TDS_ODBC_ROW_STATUS row_status
status of row, it can happen that this flag mark that we are still parsing row, this it&#39;s normal ...
Definition: odbc.h:414
tds_dstr
Structure to hold a string.
Definition: tds.h:94
tds_context
Definition: tds.h:1063
tds_socket
Information for a server connection.
Definition: tds.h:1174
_hstmt::tds
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:384
TDS_PARSED_PARAM
Definition: odbc.h:522
tds_login
Definition: tds.h:549
_hdbc::stmt_list
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:290
_hstmt::query
DSTR query
query to execute
Definition: odbc.h:382
_hstmt::params
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:400
odbc_set_concise_sql_type
SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only)
Set concise type and all cascading field.
Definition: odbc_util.c:971
_hstmt::prev
struct _hstmt * prev
previous in list
Definition: odbc.h:389
odbc_get_param_len
SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC *axd, unsigned int n_row)
Return length of parameter from parameter information.
Definition: odbc_util.c:857
_drecord
Definition: odbc.h:157
odbc_c_to_server_type
TDS_SERVER_TYPE odbc_c_to_server_type(int c_type)
Pass this an SQL_C_* type and get a SYB* type which most closely corresponds to the SQL_C_* type...
Definition: odbc_util.c:600
tds_result_info
Hold information for any results.
Definition: tds.h:803
_hstmt::param_num
int param_num
last valid parameter in params, it&#39;s a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:402
_hcattr
Definition: odbc.h:240
tds.h
Main include file for libtds.
_hstmt::param_count
unsigned int param_count
number of parameter in current query
Definition: odbc.h:409
_sql_error
Definition: odbc.h:88
tds_column_funcs
Definition: tds.h:674
_heattr
Definition: odbc.h:216
_dheader
Definition: odbc.h:145
odbc_rdbms_version
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition: odbc_util.c:848
tdsiconvinfo
Definition: iconv.h:91
_hsattr
Definition: odbc.h:303
_hstmt::prepared_pos
char * prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:404
_henv
Definition: odbc.h:231
tds_cursor
Holds informations about a cursor.
Definition: tds.h:971
_hdesc
Definition: odbc.h:198
_hstmt::row_count
TDS_INT8 row_count
row count to return
Definition: odbc.h:412
_sql_errors
Definition: odbc.h:100
odbc_set_string_flag
SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR *pcbBuffer, const char *s, int len, int flag)
Copy a string to client setting size according to ODBC convenction.
Definition: odbc_util.c:279
tds_column
Metadata about columns in regular and compute rows.
Definition: tds.h:726
_hdbc::current_statement
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:288
odbc_set_concise_c_type
SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only)
Set concise type and all cascading field.
Definition: odbc_util.c:1093
tds_connection
Definition: tds.h:1102
TDS_FUNCS
Definition: odbc.h:432
TDS_DATETIMEALL
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information...
Definition: tds.h:144
_hdbc
Definition: odbc.h:269
tds_dynamic
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:1011
_hchk
Definition: odbc.h:224
_hstmt::next
struct _hstmt * next
next in list
Definition: odbc.h:387