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  int param_focus;
435 };
436 
437 typedef struct _henv TDS_ENV;
438 typedef struct _hdbc TDS_DBC;
439 typedef struct _hstmt TDS_STMT;
440 typedef struct _hchk TDS_CHK;
441 
442 typedef struct {
443  /* this must be the first member */
444  TDSCOLUMNFUNCS common;
445  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
446 } TDS_FUNCS;
447 
448 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
449 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
450 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
451 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
452 
453 /* fix a bug in MingW headers */
454 #ifdef __MINGW32__
455 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
456 
457 #undef SQL_INTERVAL_YEAR
458 #undef SQL_INTERVAL_MONTH
459 #undef SQL_INTERVAL_DAY
460 #undef SQL_INTERVAL_HOUR
461 #undef SQL_INTERVAL_MINUTE
462 #undef SQL_INTERVAL_SECOND
463 #undef SQL_INTERVAL_YEAR_TO_MONTH
464 #undef SQL_INTERVAL_DAY_TO_HOUR
465 #undef SQL_INTERVAL_DAY_TO_MINUTE
466 #undef SQL_INTERVAL_DAY_TO_SECOND
467 #undef SQL_INTERVAL_HOUR_TO_MINUTE
468 #undef SQL_INTERVAL_HOUR_TO_SECOND
469 #undef SQL_INTERVAL_MINUTE_TO_SECOND
470 
471 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
472 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
473 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
474 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
475 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
476 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
477 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
478 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
479 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
480 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
481 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
482 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
483 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
484 
485 #endif
486 #endif
487 
488 #ifdef _WIN32
489 bool get_login_info(HWND hwndParent, TDSLOGIN * login);
490 #endif
491 
492 #define ODBC_PARAM_LIST \
493  ODBC_PARAM(Servername) \
494  ODBC_PARAM(Server) \
495  ODBC_PARAM(DSN) \
496  ODBC_PARAM(UID) \
497  ODBC_PARAM(PWD) \
498  ODBC_PARAM(Address) \
499  ODBC_PARAM(Port) \
500  ODBC_PARAM(TDS_Version) \
501  ODBC_PARAM(Language) \
502  ODBC_PARAM(Database) \
503  ODBC_PARAM(TextSize) \
504  ODBC_PARAM(PacketSize) \
505  ODBC_PARAM(ClientCharset) \
506  ODBC_PARAM(DumpFile) \
507  ODBC_PARAM(DumpFileAppend) \
508  ODBC_PARAM(DebugFlags) \
509  ODBC_PARAM(Encryption) \
510  ODBC_PARAM(Trusted_Connection) \
511  ODBC_PARAM(APP) \
512  ODBC_PARAM(WSID) \
513  ODBC_PARAM(UseNTLMv2) \
514  ODBC_PARAM(MARS_Connection) \
515  ODBC_PARAM(REALM) \
516  ODBC_PARAM(ServerSPN) \
517  ODBC_PARAM(AttachDbFilename) \
518  ODBC_PARAM(ApplicationIntent) \
519  ODBC_PARAM(Timeout)
520 
521 #define ODBC_PARAM(p) ODBC_PARAM_##p,
522 enum {
523  ODBC_PARAM_LIST
524  ODBC_PARAM_SIZE
525 };
526 #undef ODBC_PARAM
527 
528 
529 /*
530  * connectparams.h
531  */
532 
533 typedef struct {
534  const char *p;
535  size_t len;
537 
545 bool odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
546 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
547 #ifdef _WIN32
548 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
549 #endif
550 
551 /*
552  * convert_tds2sql.c
553  */
554 SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
555 SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
556 
557 
558 
559 /*
560  * descriptor.c
561  */
562 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
563 SQLRETURN desc_free(TDS_DESC * desc);
564 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
565 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
566 SQLRETURN desc_free_records(TDS_DESC * desc);
567 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
568 
569 /*
570  * odbc.c
571  */
572 /* Temporarily store the bound TVP columns */
573 /* Follow the naming in _SQLBindParameter for convenience */
574 typedef struct {
575  SQLSMALLINT fParamType; /* InputOutputParam */
576  SQLSMALLINT fCType; /* C data type */
577  SQLSMALLINT fSqlType; /* SQL data type */
578  SQLULEN cbColDef; /* columnsize */
579  SQLSMALLINT ibScale; /* precision */
580  SQLPOINTER rgbValue; /* content buffer */
581  SQLLEN cbValueMax; /* buffer length */
582  SQLLEN *pcbValue; /* content length buffer */
583 } SQLTVPCOLUMN;
584 
585 typedef struct sql_tvp_column_list {
586  SQLTVPCOLUMN *column;
587  SQLUSMALLINT ipar;
588  struct sql_tvp_column_list *next;
590 
591 typedef struct {
592  char *type_name;
593  SQLLEN type_name_len;
594  int num_cols;
595  SQLTVPCOLUMNLIST *col_list;
596 } SQLTVP;
597 
598 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
599 
600 /*
601  * odbc_checks.h
602  */
603 #if ENABLE_EXTRA_CHECKS
604 /* macro */
605 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
606 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
607 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
608 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
609 /* declarations*/
610 void odbc_check_env_extra(TDS_ENV * env);
611 void odbc_check_dbc_extra(TDS_DBC * dbc);
612 void odbc_check_stmt_extra(TDS_STMT * stmt);
613 void odbc_check_desc_extra(TDS_DESC * desc);
614 #else
615 /* macro */
616 #define CHECK_ENV_EXTRA(env)
617 #define CHECK_DBC_EXTRA(dbc)
618 #define CHECK_STMT_EXTRA(stmt)
619 #define CHECK_DESC_EXTRA(desc)
620 #endif
621 
622 /*
623  * odbc_util.h
624  */
625 
626 /* helpers for ODBC wide string support */
627 #undef _wide
628 #undef _WIDE
629 #ifdef ENABLE_ODBC_WIDE
630 typedef union {
631  char mb[1];
632  SQLWCHAR wide[1];
633 } ODBC_CHAR;
634 # define _wide ,wide
635 # define _wide0 ,0
636 # define _WIDE ,int wide
637 #else
638 # define _wide
639 # define _wide0
640 # define _WIDE
641 # define ODBC_CHAR SQLCHAR
642 #endif
643 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
644 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
645 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
646 
647 void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
648 
649 int odbc_sql_to_c_type_default(int sql_type);
650 TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
651 TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
652 
653 unsigned int odbc_get_string_size(int size, const ODBC_CHAR * str _WIDE);
654 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
655 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
656 
657 #ifdef ENABLE_ODBC_WIDE
658 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
659 #define odbc_dstr_copy(dbc, s, len, out) \
660  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
661 #define odbc_dstr_copy_oct(dbc, s, len, out) \
662  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
663 #else
664 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
665 #define odbc_dstr_copy_oct odbc_dstr_copy
666 #endif
667 
668 
669 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
670 #ifdef ENABLE_ODBC_WIDE
671 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
672  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))
673 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
674  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
675 #else
676 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
677  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
678 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
679  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
680 #endif
681 
682 #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))
683 #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))
684 
685 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
686 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
687 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
688 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
689 
690 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
691 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
692 
693 /*
694  * prepare_query.c
695  */
696 SQLRETURN prepare_call(struct _hstmt *stmt);
697 SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
698 int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
699 int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
700 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
701 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
702 const char *odbc_skip_rpc_name(const char *s);
703 
704 /*
705  * sql2tds.c
706  */
707 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);
708 TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
709 
710 /*
711  * bcp.c
712  */
713 void odbc_bcp_free_storage(TDS_DBC *dbc);
714 void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
715 void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
716 void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
717 void odbc_bcp_sendrow(TDS_DBC *dbc);
718 int odbc_bcp_batch(TDS_DBC *dbc);
719 int odbc_bcp_done(TDS_DBC *dbc);
720 void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
721 
722 /*
723  * sqlwchar.c
724  */
725 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
726 size_t sqlwcslen(const SQLWCHAR * s);
727 
728 typedef struct sqlwstr_buf {
729  struct sqlwstr_buf *next;
730  wchar_t buf[256];
731 } SQLWSTRBUF;
732 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
733 void sqlwstr_free(SQLWSTRBUF *bufs);
734 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
735 #define SQLWSTR(s) sqlwstr(s, &bufs)
736 #define SQLWSTR_FREE() sqlwstr_free(bufs)
737 #else
738 #define sqlwcslen(s) wcslen(s)
739 
740 #define SQLWSTR_BUFS(n) do {} while(0)
741 #define SQLWSTR(s) ((const wchar_t*)(s))
742 #define SQLWSTR_FREE() do {} while(0)
743 #endif
744 
745 int odbc_get_wide_canonic(TDSCONNECTION *conn);
746 
747 #include <freetds/popvis.h>
748 
749 #ifdef __cplusplus
750 #if 0
751 {
752 #endif
753 }
754 #endif
755 
756 #endif
tdsiconvinfo
Definition: iconv.h:92
_hdbc::cursor_support
unsigned int cursor_support
<>0 if server handle cursors
Definition: odbc.h:300
TDS_PARSED_PARAM
Definition: odbc.h:533
_hstmt::prev
struct _hstmt * prev
previous in list
Definition: odbc.h:394
_hsattr
Definition: odbc.h:309
tds_context
Definition: tds.h:1028
_hcattr
Definition: odbc.h:246
tds_column_funcs
Definition: tds.h:642
tds_dynamic
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:976
_hstmt::params
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:409
_heattr
Definition: odbc.h:222
TDS_FUNCS
Definition: odbc.h:442
_hstmt::tds
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:389
_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
_hdbc::uad
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition: odbc.h:298
_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:858
_hstmt::next
struct _hstmt * next
next in list
Definition: odbc.h:392
_henv
Definition: odbc.h:237
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:867
_hstmt::param_count
unsigned int param_count
number of parameter in current query
Definition: odbc.h:418
SQLTVPCOLUMN
Definition: odbc.h:574
tds_connection
Definition: tds.h:1090
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_bcpinfo
Definition: tds.h:1695
_dheader
Definition: odbc.h:151
tds_result_info
Hold information for any results.
Definition: tds.h:768
_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
tds.h
Main include file for libtds.
_hstmt::prepared_pos
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:413
_hstmt::need_reprepare
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition: odbc.h:404
_sql_error
Definition: odbc.h:94
SQLTVP
Definition: odbc.h:591
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
_hstmt::row_count
TDS_INT8 row_count
row count to return
Definition: odbc.h:421
tds_column
Metadata about columns in regular and compute rows.
Definition: tds.h:688
_hstmt::query
DSTR query
query to execute
Definition: odbc.h:387
_hdbc::current_statement
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:293
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:984
_hdbc
Definition: odbc.h:275
_hdbc::stmt_list
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:295
sql_tvp_column_list
Definition: odbc.h:585
tds_socket
Information for a server connection.
Definition: tds.h:1175
_hdesc
Definition: odbc.h:204
_hstmt
Definition: odbc.h:381
TDS_DATETIMEALL
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
Definition: tds.h:145
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:1108
tds_login
Definition: tds.h:516
_hchk
Definition: odbc.h:230
tds_dstr
Structure to hold a string.
Definition: string.h:36
tds_cursor
Holds informations about a cursor.
Definition: tds.h:936
_sql_errors
Definition: odbc.h:106