FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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(TDS_NO_DM)
30 #include <sql.h>
31 #include <sqlext.h>
32 #ifdef UNIXODBC
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 #ifndef SQL_COPT_SS_BASE
65 #define SQL_COPT_SS_BASE 1200
66 #endif
67 
68 #ifndef SQL_COPT_SS_MARS_ENABLED
69 #define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24)
70 #endif
71 
72 #define SQL_INFO_FREETDS_TDS_VERSION 1300
73 
74 #ifndef SQL_MARS_ENABLED_NO
75 #define SQL_MARS_ENABLED_NO 0
76 #endif
77 
78 #ifndef SQL_MARS_ENABLED_YES
79 #define SQL_MARS_ENABLED_YES 1
80 #endif
81 
82 #ifndef SQL_SS_TIME2
83 #define SQL_SS_TIME2 (-154)
84 #endif
85 
86 #ifndef SQL_SS_TIMESTAMPOFFSET
87 #define SQL_SS_TIMESTAMPOFFSET (-155)
88 #endif
89 
90 /*
91  * these types are used from conversion from client to server
92  */
93 #ifndef SQL_C_SS_TIME2
94 #define SQL_C_SS_TIME2 (0x4000)
95 #endif
96 
97 #ifndef SQL_C_SS_TIMESTAMPOFFSET
98 #define SQL_C_SS_TIMESTAMPOFFSET (0x4001)
99 #endif
100 
101 #ifndef SQL_CA_SS_BASE
102 #define SQL_CA_SS_BASE 1200
103 #endif
104 
105 #ifndef SQL_CA_SS_UDT_CATALOG_NAME
106 #define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18)
107 #endif
108 
109 #ifndef SQL_CA_SS_UDT_SCHEMA_NAME
110 #define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19)
111 #endif
112 
113 #ifndef SQL_CA_SS_UDT_TYPE_NAME
114 #define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20)
115 #endif
116 
117 #ifndef SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME
118 #define SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME (SQL_CA_SS_BASE+21)
119 #endif
120 
121 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME
122 #define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22)
123 #endif
124 
125 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME
126 #define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23)
127 #endif
128 
129 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_NAME
130 #define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24)
131 #endif
132 
133 #ifdef __cplusplus
134 extern "C"
135 {
136 #if 0
137 }
138 #endif
139 #endif
140 
141 /* $Id: tdsodbc.h,v 1.134 2012-03-09 21:51:21 freddy77 Exp $ */
142 
143 #include <freetds/pushvis.h>
144 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
145 #define ODBC_API SQL_API __attribute__((externally_visible))
146 #else
147 #define ODBC_API SQL_API
148 #endif
149 
150 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(__GNUC__)
151 # define ODBC_PUBLIC __attribute__((dllexport))
152 #else
153 # define ODBC_PUBLIC
154 #endif
155 
156 #define ODBC_MAX(a,b) ( (a) > (b) ? (a) : (b) )
157 #define ODBC_MIN(a,b) ( (a) < (b) ? (a) : (b) )
158 
160 {
161  const char *msg;
162  char state2[6];
163  char state3[6];
164  TDS_UINT native;
165  char *server;
166  int linenum;
167  int msgstate;
168  int row;
169 };
170 
172 {
173  struct _sql_error *errs;
174  int num_errors;
175  SQLRETURN lastrc;
176  char ranked;
177 };
178 
179 typedef struct _sql_errors TDS_ERRS;
180 
181 #if ENABLE_EXTRA_CHECKS
182 void odbc_check_struct_extra(void *p);
183 #else
184 static inline void odbc_check_struct_extra(void *p) {}
185 #endif
186 
187 #define ODBC_RETURN(handle, rc) \
188  do { odbc_check_struct_extra(handle); \
189  return handle->errs.lastrc = (rc); } while(0)
190 #define ODBC_RETURN_(handle) \
191  do { odbc_check_struct_extra(handle); \
192  return handle->errs.lastrc; } while(0)
193 
194 #define ODBC_EXIT(handle, rc) \
195  do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
196  odbc_check_struct_extra(handle); \
197  tds_mutex_unlock(&handle->mtx); \
198  return _odbc_rc; } while(0)
199 #define ODBC_EXIT_(handle) \
200  do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
201  odbc_check_struct_extra(handle); \
202  tds_mutex_unlock(&handle->mtx); \
203  return _odbc_rc; } while(0)
204 
205 
207 void odbc_errs_reset(struct _sql_errors *errs);
208 
210 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
211 
213 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
214  int msgstate, const char *server, int row);
215 
216 struct _dheader
217 {
218  SQLSMALLINT sql_desc_alloc_type;
219  SQLINTEGER sql_desc_bind_type;
220  SQLULEN sql_desc_array_size;
221  /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
222  SQLSMALLINT sql_desc_count;
223  SQLUSMALLINT *sql_desc_array_status_ptr;
224  SQLULEN *sql_desc_rows_processed_ptr;
225  SQLLEN *sql_desc_bind_offset_ptr;
226 };
227 
228 struct _drecord
229 {
230  SQLUINTEGER sql_desc_auto_unique_value;
231  DSTR sql_desc_base_column_name;
232  DSTR sql_desc_base_table_name;
233  SQLINTEGER sql_desc_case_sensitive;
234  DSTR sql_desc_catalog_name;
235  SQLSMALLINT sql_desc_concise_type;
236  SQLPOINTER sql_desc_data_ptr;
237  SQLSMALLINT sql_desc_datetime_interval_code;
238  SQLINTEGER sql_desc_datetime_interval_precision;
239  SQLLEN sql_desc_display_size;
240  SQLSMALLINT sql_desc_fixed_prec_scale;
241  SQLLEN *sql_desc_indicator_ptr;
242  DSTR sql_desc_label;
243  SQLULEN sql_desc_length;
244  /* this point to a constant buffer, do not free or modify */
245  const char *sql_desc_literal_prefix;
246  /* this point to a constant buffer, do not free or modify */
247  const char *sql_desc_literal_suffix;
248  DSTR sql_desc_local_type_name;
249  DSTR sql_desc_name;
250  SQLSMALLINT sql_desc_nullable;
251  SQLINTEGER sql_desc_num_prec_radix;
252  SQLLEN sql_desc_octet_length;
253  SQLLEN *sql_desc_octet_length_ptr;
254  SQLSMALLINT sql_desc_parameter_type;
255  SQLSMALLINT sql_desc_precision;
256  SQLSMALLINT sql_desc_rowver;
257  SQLSMALLINT sql_desc_scale;
258  DSTR sql_desc_schema_name;
259  SQLSMALLINT sql_desc_searchable;
260  DSTR sql_desc_table_name;
261  SQLSMALLINT sql_desc_type;
262  /* this point to a constant buffer, do not free or modify */
263  const char *sql_desc_type_name;
264  SQLSMALLINT sql_desc_unnamed;
265  SQLSMALLINT sql_desc_unsigned;
266  SQLSMALLINT sql_desc_updatable;
267 };
268 
269 struct _hdesc
270 {
271  SQLSMALLINT htype; /* do not reorder this field */
272  struct _sql_errors errs; /* do not reorder this field */
273  tds_mutex mtx;
274  int type;
275  SQLHANDLE parent;
276  struct _dheader header;
277  struct _drecord *records;
278 };
279 
280 typedef struct _hdesc TDS_DESC;
281 
282 #define DESC_IRD 1
283 #define DESC_IPD 2
284 #define DESC_ARD 3
285 #define DESC_APD 4
286 
287 struct _heattr
288 {
289  SQLUINTEGER connection_pooling;
290  SQLUINTEGER cp_match;
291  SQLINTEGER odbc_version;
292  SQLINTEGER output_nts;
293 };
294 
295 struct _hchk
296 {
297  SQLSMALLINT htype; /* do not reorder this field */
298  struct _sql_errors errs; /* do not reorder this field */
299  tds_mutex mtx;
300 };
301 
302 struct _henv
303 {
304  SQLSMALLINT htype; /* do not reorder this field */
305  struct _sql_errors errs; /* do not reorder this field */
306  tds_mutex mtx;
307  TDSCONTEXT *tds_ctx;
308  struct _heattr attr;
309 };
310 
311 struct _hcattr
312 {
313  SQLUINTEGER access_mode;
314  SQLUINTEGER async_enable;
315  SQLUINTEGER auto_ipd;
316  SQLUINTEGER autocommit;
317  SQLUINTEGER connection_dead;
318  SQLUINTEGER connection_timeout;
319  DSTR current_catalog;
320  SQLUINTEGER login_timeout;
321  SQLUINTEGER metadata_id;
322  SQLUINTEGER odbc_cursors;
323  SQLUINTEGER packet_size;
324  SQLHWND quite_mode;
325  DSTR translate_lib;
326  SQLUINTEGER translate_option;
327  SQLUINTEGER txn_isolation;
328  SQLUINTEGER mars_enabled;
329  SQLUINTEGER cursor_type;
330 #ifdef TDS_NO_DM
331  SQLUINTEGER trace;
332  DSTR tracefile;
333 #endif
334 };
335 
336 #define TDS_MAX_APP_DESC 100
337 
338 struct _hstmt;
339 struct _hdbc
340 {
341  SQLSMALLINT htype; /* do not reorder this field */
342  struct _sql_errors errs; /* do not reorder this field */
343  tds_mutex mtx;
344  struct _henv *env;
346  DSTR dsn;
347  DSTR server; /* aka Instance */
348  DSTR oldpwd;
349 #ifdef ENABLE_ODBC_WIDE
350  DSTR original_charset;
351  TDSICONV *mb_conv;
352 #endif
353 
361  struct _hstmt *stmt_list;
362  struct _hcattr attr;
364  TDS_DESC *uad[TDS_MAX_APP_DESC];
366  unsigned int cursor_support:1;
367  unsigned int use_oldpwd:1;
368  TDS_INT default_query_timeout;
369 };
370 
371 struct _hsattr
372 {
373  /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
374 /* TDS_DESC *app_row_desc; */
375 /* TDS_DESC *app_param_desc; */
376  SQLUINTEGER async_enable;
377  SQLUINTEGER concurrency;
378  SQLUINTEGER cursor_scrollable;
379  SQLUINTEGER cursor_sensitivity;
380  SQLUINTEGER cursor_type;
381  SQLUINTEGER enable_auto_ipd;
382  SQLPOINTER fetch_bookmark_ptr;
383  SQLULEN keyset_size;
384  SQLULEN max_length;
385  SQLULEN max_rows;
386  SQLUINTEGER metadata_id;
387  SQLUINTEGER noscan;
388  /* apd->sql_desc_bind_offset_ptr */
389  /* SQLUINTEGER *param_bind_offset_ptr; */
390  /* apd->sql_desc_bind_type */
391  /* SQLUINTEGER param_bind_type; */
392  /* apd->sql_desc_array_status_ptr */
393  /* SQLUSMALLINT *param_operation_ptr; */
394  /* ipd->sql_desc_array_status_ptr */
395  /* SQLUSMALLINT *param_status_ptr; */
396  /* ipd->sql_desc_rows_processed_ptr */
397  /* SQLUSMALLINT *params_processed_ptr; */
398  /* apd->sql_desc_array_size */
399  /* SQLUINTEGER paramset_size; */
400  SQLUINTEGER query_timeout;
401  SQLUINTEGER retrieve_data;
402  /* ard->sql_desc_bind_offset_ptr */
403  /* SQLUINTEGER *row_bind_offset_ptr; */
404  /* ard->sql_desc_array_size */
405  /* SQLUINTEGER row_array_size; */
406  /* ard->sql_desc_bind_type */
407  /* SQLUINTEGER row_bind_type; */
408  SQLULEN row_number;
409  /* ard->sql_desc_array_status_ptr */
410  /* SQLUINTEGER *row_operation_ptr; */
411  /* ird->sql_desc_array_status_ptr */
412  /* SQLUINTEGER *row_status_ptr; */
413  /* ird->sql_desc_rows_processed_ptr */
414  /* SQLUINTEGER *rows_fetched_ptr; */
415  SQLUINTEGER simulate_cursor;
416  SQLUINTEGER use_bookmarks;
417  /* SQLGetStmtAttr only */
418 /* TDS_DESC *imp_row_desc; */
419 /* TDS_DESC *imp_param_desc; */
420  DSTR qn_msgtext;
421  DSTR qn_options;
422  SQLUINTEGER qn_timeout;
423 };
424 
425 typedef enum
426 {
427  NOT_IN_ROW,
428  IN_NORMAL_ROW,
429  IN_COMPUTE_ROW,
430  AFTER_COMPUTE_ROW,
431  PRE_NORMAL_ROW
432 } TDS_ODBC_ROW_STATUS;
433 
434 typedef enum
435 {
436  ODBC_SPECIAL_NONE = 0,
437  ODBC_SPECIAL_GETTYPEINFO = 1,
438  ODBC_SPECIAL_COLUMNS = 2,
439  ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
440  ODBC_SPECIAL_SPECIALCOLUMNS = 4
441 } TDS_ODBC_SPECIAL_ROWS;
442 
443 struct _hstmt
444 {
445  SQLSMALLINT htype; /* do not reorder this field */
446  struct _sql_errors errs; /* do not reorder this field */
447  tds_mutex mtx;
448  struct _hdbc *dbc;
450  char *query;
453 
455  struct _hstmt *next;
457  struct _hstmt *prev;
458 
459  /* begin prepared query stuff */
460  char *prepared_query;
461  unsigned prepared_query_is_func:1;
462  unsigned prepared_query_is_rpc:1;
463  unsigned need_reprepare:1;
464  unsigned param_data_called:1;
465  /* end prepared query stuff */
466 
473 
474  unsigned int curr_param_row, num_param_rows;
475 
477  unsigned int param_count;
478  int row;
480  TDS_INT8 row_count;
482  TDS_ODBC_ROW_STATUS row_status;
483  /* do NOT free dynamic, free from socket or attach to connection */
484  TDSDYNAMIC *dyn;
485  TDS_DESC *ard, *ird, *apd, *ipd;
486  TDS_DESC *orig_ard, *orig_apd;
487  SQLULEN sql_rowset_size;
488  struct _hsattr attr;
489  DSTR cursor_name; /* auto generated cursor name */
490  TDS_ODBC_SPECIAL_ROWS special_row;
491  /* do NOT free cursor, free from socket or attach to connection */
492  TDSCURSOR *cursor;
493 };
494 
495 typedef struct _henv TDS_ENV;
496 typedef struct _hdbc TDS_DBC;
497 typedef struct _hstmt TDS_STMT;
498 typedef struct _hchk TDS_CHK;
499 
500 typedef struct {
501  /* this must be the first member */
502  TDSCOLUMNFUNCS common;
503  SQLSMALLINT (*server_to_sql_type)(TDSCOLUMN *col);
504  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
505 } TDS_FUNCS;
506 
507 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
508 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
509 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
510 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
511 
512 /* fix a bug in MingW headers */
513 #ifdef __MINGW32__
514 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
515 
516 #undef SQL_INTERVAL_YEAR
517 #undef SQL_INTERVAL_MONTH
518 #undef SQL_INTERVAL_DAY
519 #undef SQL_INTERVAL_HOUR
520 #undef SQL_INTERVAL_MINUTE
521 #undef SQL_INTERVAL_SECOND
522 #undef SQL_INTERVAL_YEAR_TO_MONTH
523 #undef SQL_INTERVAL_DAY_TO_HOUR
524 #undef SQL_INTERVAL_DAY_TO_MINUTE
525 #undef SQL_INTERVAL_DAY_TO_SECOND
526 #undef SQL_INTERVAL_HOUR_TO_MINUTE
527 #undef SQL_INTERVAL_HOUR_TO_SECOND
528 #undef SQL_INTERVAL_MINUTE_TO_SECOND
529 
530 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
531 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
532 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
533 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
534 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
535 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
536 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
537 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
538 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
539 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
540 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
541 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
542 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
543 
544 #endif
545 #endif
546 
547 #ifdef _WIN32
548 BOOL get_login_info(HWND hwndParent, TDSLOGIN * login);
549 #endif
550 
551 #define ODBC_PARAM_LIST \
552  ODBC_PARAM(Servername) \
553  ODBC_PARAM(Server) \
554  ODBC_PARAM(DSN) \
555  ODBC_PARAM(UID) \
556  ODBC_PARAM(PWD) \
557  ODBC_PARAM(Address) \
558  ODBC_PARAM(Port) \
559  ODBC_PARAM(TDS_Version) \
560  ODBC_PARAM(Language) \
561  ODBC_PARAM(Database) \
562  ODBC_PARAM(TextSize) \
563  ODBC_PARAM(PacketSize) \
564  ODBC_PARAM(ClientCharset) \
565  ODBC_PARAM(DumpFile) \
566  ODBC_PARAM(DumpFileAppend) \
567  ODBC_PARAM(DebugFlags) \
568  ODBC_PARAM(Encryption) \
569  ODBC_PARAM(Trusted_Connection) \
570  ODBC_PARAM(APP) \
571  ODBC_PARAM(WSID) \
572  ODBC_PARAM(UseNTLMv2) \
573  ODBC_PARAM(MARS_Connection) \
574  ODBC_PARAM(REALM) \
575  ODBC_PARAM(ServerSPN)
576 
577 #define ODBC_PARAM(p) ODBC_PARAM_##p,
578 enum {
579  ODBC_PARAM_LIST
580  ODBC_PARAM_SIZE
581 };
582 #undef ODBC_PARAM
583 
584 
585 /*
586  * connectparams.h
587  */
588 
589 typedef struct {
590  const char *p;
591  size_t len;
593 
601 int odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
602 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
603 #ifdef _WIN32
604 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
605 #endif
606 
607 /*
608  * convert_tds2sql.c
609  */
610 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);
611 
612 /*
613  * descriptor.c
614  */
615 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
616 SQLRETURN desc_free(TDS_DESC * desc);
617 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
618 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
619 SQLRETURN desc_free_records(TDS_DESC * desc);
620 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
621 
622 /*
623  * odbc.c
624  */
625 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
626 
627 /*
628  * odbc_checks.h
629  */
630 #if ENABLE_EXTRA_CHECKS
631 /* macro */
632 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
633 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
634 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
635 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
636 /* declarations*/
637 void odbc_check_env_extra(TDS_ENV * env);
638 void odbc_check_dbc_extra(TDS_DBC * dbc);
639 void odbc_check_stmt_extra(TDS_STMT * stmt);
640 void odbc_check_desc_extra(TDS_DESC * desc);
641 #else
642 /* macro */
643 #define CHECK_ENV_EXTRA(env)
644 #define CHECK_DBC_EXTRA(dbc)
645 #define CHECK_STMT_EXTRA(stmt)
646 #define CHECK_DESC_EXTRA(desc)
647 #endif
648 
649 /*
650  * odbc_util.h
651  */
652 
653 /* helpers for ODBC wide string support */
654 #undef _wide
655 #undef _WIDE
656 #ifdef ENABLE_ODBC_WIDE
657 typedef union {
658  char mb[1];
659  SQLWCHAR wide[1];
660 } ODBC_CHAR;
661 # define _wide ,wide
662 # define _wide0 ,0
663 # define _WIDE ,int wide
664 #else
665 # define _wide
666 # define _wide0
667 # define _WIDE
668 # define ODBC_CHAR SQLCHAR
669 #endif
670 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
671 int odbc_set_stmt_prepared_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
672 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
673 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
674 
678 static inline SQLSMALLINT
679 odbc_server_to_sql_type(TDSCOLUMN *col)
680 {
681  return ((TDS_FUNCS *) col->funcs)->server_to_sql_type(col);
682 }
683 
684 static inline void
685 odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver)
686 {
687  ((TDS_FUNCS *) col->funcs)->set_type_info(col, drec, odbc_ver);
688 }
689 
690 int odbc_sql_to_c_type_default(int sql_type);
691 int odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
692 int odbc_c_to_server_type(int c_type);
693 
694 SQLINTEGER odbc_sql_to_displaysize(int sqltype, TDSCOLUMN *col);
695 int odbc_get_string_size(int size, ODBC_CHAR * str _WIDE);
696 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
697 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
698 
699 #ifdef ENABLE_ODBC_WIDE
700 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, ODBC_CHAR * str, int flag);
701 #define odbc_dstr_copy(dbc, s, len, out) \
702  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
703 #define odbc_dstr_copy_oct(dbc, s, len, out) \
704  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
705 #else
706 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, ODBC_CHAR * str);
707 #define odbc_dstr_copy_oct odbc_dstr_copy
708 #endif
709 
710 
711 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
712 #ifdef ENABLE_ODBC_WIDE
713 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
714  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))
715 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
716  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
717 #else
718 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
719  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
720 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
721  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
722 #endif
723 
724 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
725 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
726 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
727 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
728 
729 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
730 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
731 
732 /*
733  * prepare_query.c
734  */
735 SQLRETURN prepare_call(struct _hstmt *stmt);
736 SQLRETURN native_sql(struct _hdbc *dbc, char *s);
737 int parse_prepared_query(struct _hstmt *stmt, int compute_row);
738 int start_parse_prepared_query(struct _hstmt *stmt, int compute_row);
739 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
740 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
741 
742 /*
743  * sql2tds.c
744  */
745 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);
746 
747 /*
748  * sqlwchar.c
749  */
750 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
751 size_t sqlwcslen(const SQLWCHAR * s);
752 
753 typedef struct sqlwstr_buf {
754  struct sqlwstr_buf *next;
755  wchar_t buf[256];
756 } SQLWSTRBUF;
757 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
758 void sqlwstr_free(SQLWSTRBUF *bufs);
759 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
760 #define SQLWSTR(s) sqlwstr(s, &bufs)
761 #define SQLWSTR_FREE() sqlwstr_free(bufs)
762 #else
763 #define sqlwcslen(s) wcslen(s)
764 
765 #define SQLWSTR_BUFS(n) do {} while(0)
766 #define SQLWSTR(s) ((const wchar_t*)(s))
767 #define SQLWSTR_FREE() do {} while(0)
768 #endif
769 
770 #if SIZEOF_SQLWCHAR == 2
771 # if WORDS_BIGENDIAN
772 # define ODBC_WIDE_NAME "UCS-2BE"
773 # define ODBC_WIDE_NAME_UTF "UTF-16BE"
774 # else
775 # define ODBC_WIDE_NAME "UCS-2LE"
776 # define ODBC_WIDE_NAME_UTF "UTF-16LE"
777 # endif
778 const char *odbc_get_wide_name(TDSCONNECTION *conn);
779 #elif SIZEOF_SQLWCHAR == 4
780 # if WORDS_BIGENDIAN
781 # define ODBC_WIDE_NAME "UCS-4BE"
782 # else
783 # define ODBC_WIDE_NAME "UCS-4LE"
784 # endif
785 static inline const char *
786 odbc_get_wide_name(TDSCONNECTION *conn)
787 {
788  return ODBC_WIDE_NAME;
789 }
790 #else
791 #error SIZEOF_SQLWCHAR not supported !!
792 #endif
793 
794 #include <freetds/popvis.h>
795 
796 #ifdef __cplusplus
797 #if 0
798 {
799 #endif
800 }
801 #endif
802 
803 #endif
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition: odbc_util.c:959
char * query
query to execute
Definition: odbc.h:450
Definition: tds.h:1001
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:482
Definition: odbc.h:443
Definition: odbc.h:589
Definition: odbc.h:171
Definition: odbc.h:216
Definition: tds.h:522
Definition: odbc.h:269
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition: odbc.h:364
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:1201
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:968
Definition: iconv.h:93
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:361
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:470
int 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:643
Definition: odbc.h:159
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:452
Structure to hold a string.
Definition: tds.h:93
Definition: tds.h:638
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:359
Definition: odbc.h:371
Definition: tds.h:1036
char * prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:472
Definition: odbc.h:500
unsigned int cursor_support
<>0 if server handle cursors
Definition: odbc.h:366
Definition: odbc.h:339
Metadata about columns in regular and compute rows.
Definition: tds.h:667
Definition: odbc.h:311
struct _hstmt * next
next in list
Definition: odbc.h:455
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:1079
struct _hstmt * prev
previous in list
Definition: odbc.h:457
Information for a server connection.
Definition: tds.h:1103
Definition: odbc.h:302
Holds informations about a cursor.
Definition: tds.h:912
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:322
unsigned int param_count
number of parameter in current query
Definition: odbc.h:477
Hold information for any results.
Definition: tds.h:744
Definition: odbc.h:295
Definition: odbc.h:228
Main include file for libtds.
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:468
TDS_INT8 row_count
row count to return
Definition: odbc.h:480
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:949
Definition: odbc.h:287