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