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(_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 #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 #ifdef ENABLE_ODBC_WIDE
349  DSTR original_charset;
350  TDSICONV *mb_conv;
351 #endif
352 
360  struct _hstmt *stmt_list;
361  struct _hcattr attr;
363  TDS_DESC *uad[TDS_MAX_APP_DESC];
365  unsigned int cursor_support;
366  TDS_INT default_query_timeout;
367 };
368 
369 struct _hsattr
370 {
371  /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
372 /* TDS_DESC *app_row_desc; */
373 /* TDS_DESC *app_param_desc; */
374  SQLUINTEGER async_enable;
375  SQLUINTEGER concurrency;
376  SQLUINTEGER cursor_scrollable;
377  SQLUINTEGER cursor_sensitivity;
378  SQLUINTEGER cursor_type;
379  SQLUINTEGER enable_auto_ipd;
380  SQLPOINTER fetch_bookmark_ptr;
381  SQLULEN keyset_size;
382  SQLULEN max_length;
383  SQLULEN max_rows;
384  SQLUINTEGER metadata_id;
385  SQLUINTEGER noscan;
386  /* apd->sql_desc_bind_offset_ptr */
387  /* SQLUINTEGER *param_bind_offset_ptr; */
388  /* apd->sql_desc_bind_type */
389  /* SQLUINTEGER param_bind_type; */
390  /* apd->sql_desc_array_status_ptr */
391  /* SQLUSMALLINT *param_operation_ptr; */
392  /* ipd->sql_desc_array_status_ptr */
393  /* SQLUSMALLINT *param_status_ptr; */
394  /* ipd->sql_desc_rows_processed_ptr */
395  /* SQLUSMALLINT *params_processed_ptr; */
396  /* apd->sql_desc_array_size */
397  /* SQLUINTEGER paramset_size; */
398  SQLUINTEGER query_timeout;
399  SQLUINTEGER retrieve_data;
400  /* ard->sql_desc_bind_offset_ptr */
401  /* SQLUINTEGER *row_bind_offset_ptr; */
402  /* ard->sql_desc_array_size */
403  /* SQLUINTEGER row_array_size; */
404  /* ard->sql_desc_bind_type */
405  /* SQLUINTEGER row_bind_type; */
406  SQLULEN row_number;
407  /* ard->sql_desc_array_status_ptr */
408  /* SQLUINTEGER *row_operation_ptr; */
409  /* ird->sql_desc_array_status_ptr */
410  /* SQLUINTEGER *row_status_ptr; */
411  /* ird->sql_desc_rows_processed_ptr */
412  /* SQLUINTEGER *rows_fetched_ptr; */
413  SQLUINTEGER simulate_cursor;
414  SQLUINTEGER use_bookmarks;
415  /* SQLGetStmtAttr only */
416 /* TDS_DESC *imp_row_desc; */
417 /* TDS_DESC *imp_param_desc; */
418  DSTR qn_msgtext;
419  DSTR qn_options;
420  SQLUINTEGER qn_timeout;
421 };
422 
423 typedef enum
424 {
425  NOT_IN_ROW,
426  IN_NORMAL_ROW,
427  IN_COMPUTE_ROW,
428  AFTER_COMPUTE_ROW,
429  PRE_NORMAL_ROW
430 } TDS_ODBC_ROW_STATUS;
431 
432 typedef enum
433 {
434  ODBC_SPECIAL_NONE = 0,
435  ODBC_SPECIAL_GETTYPEINFO = 1,
436  ODBC_SPECIAL_COLUMNS = 2,
437  ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
438  ODBC_SPECIAL_SPECIALCOLUMNS = 4
439 } TDS_ODBC_SPECIAL_ROWS;
440 
441 struct _hstmt
442 {
443  SQLSMALLINT htype; /* do not reorder this field */
444  struct _sql_errors errs; /* do not reorder this field */
445  tds_mutex mtx;
446  struct _hdbc *dbc;
448  char *query;
451 
453  struct _hstmt *next;
455  struct _hstmt *prev;
456 
457  /* begin prepared query stuff */
458  char *prepared_query;
459  unsigned prepared_query_is_func:1;
460  unsigned prepared_query_is_rpc:1;
461  unsigned need_reprepare:1;
462  unsigned param_data_called:1;
463  /* end prepared query stuff */
464 
471 
472  unsigned int curr_param_row, num_param_rows;
473 
475  unsigned int param_count;
476  int row;
478  TDS_INT8 row_count;
480  TDS_ODBC_ROW_STATUS row_status;
481  /* do NOT free dynamic, free from socket or attach to connection */
482  TDSDYNAMIC *dyn;
483  TDS_DESC *ard, *ird, *apd, *ipd;
484  TDS_DESC *orig_ard, *orig_apd;
485  SQLULEN sql_rowset_size;
486  struct _hsattr attr;
487  DSTR cursor_name; /* auto generated cursor name */
488  TDS_ODBC_SPECIAL_ROWS special_row;
489  /* do NOT free cursor, free from socket or attach to connection */
490  TDSCURSOR *cursor;
491 };
492 
493 typedef struct _henv TDS_ENV;
494 typedef struct _hdbc TDS_DBC;
495 typedef struct _hstmt TDS_STMT;
496 typedef struct _hchk TDS_CHK;
497 
498 typedef struct {
499  /* this must be the first member */
500  TDSCOLUMNFUNCS common;
501  SQLSMALLINT (*server_to_sql_type)(TDSCOLUMN *col);
502  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
503 } TDS_FUNCS;
504 
505 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
506 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
507 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
508 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
509 
510 /* fix a bug in MingW headers */
511 #ifdef __MINGW32__
512 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
513 
514 #undef SQL_INTERVAL_YEAR
515 #undef SQL_INTERVAL_MONTH
516 #undef SQL_INTERVAL_DAY
517 #undef SQL_INTERVAL_HOUR
518 #undef SQL_INTERVAL_MINUTE
519 #undef SQL_INTERVAL_SECOND
520 #undef SQL_INTERVAL_YEAR_TO_MONTH
521 #undef SQL_INTERVAL_DAY_TO_HOUR
522 #undef SQL_INTERVAL_DAY_TO_MINUTE
523 #undef SQL_INTERVAL_DAY_TO_SECOND
524 #undef SQL_INTERVAL_HOUR_TO_MINUTE
525 #undef SQL_INTERVAL_HOUR_TO_SECOND
526 #undef SQL_INTERVAL_MINUTE_TO_SECOND
527 
528 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
529 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
530 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
531 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
532 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
533 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
534 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
535 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
536 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
537 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
538 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
539 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
540 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
541 
542 #endif
543 #endif
544 
545 #ifdef _WIN32
546 BOOL get_login_info(HWND hwndParent, TDSLOGIN * login);
547 #endif
548 
549 #define ODBC_PARAM_LIST \
550  ODBC_PARAM(Servername) \
551  ODBC_PARAM(Server) \
552  ODBC_PARAM(DSN) \
553  ODBC_PARAM(UID) \
554  ODBC_PARAM(PWD) \
555  ODBC_PARAM(Address) \
556  ODBC_PARAM(Port) \
557  ODBC_PARAM(TDS_Version) \
558  ODBC_PARAM(Language) \
559  ODBC_PARAM(Database) \
560  ODBC_PARAM(TextSize) \
561  ODBC_PARAM(PacketSize) \
562  ODBC_PARAM(ClientCharset) \
563  ODBC_PARAM(DumpFile) \
564  ODBC_PARAM(DumpFileAppend) \
565  ODBC_PARAM(DebugFlags) \
566  ODBC_PARAM(Encryption) \
567  ODBC_PARAM(Trusted_Connection) \
568  ODBC_PARAM(APP) \
569  ODBC_PARAM(WSID) \
570  ODBC_PARAM(UseNTLMv2) \
571  ODBC_PARAM(MARS_Connection) \
572  ODBC_PARAM(REALM) \
573  ODBC_PARAM(ServerSPN)
574 
575 #define ODBC_PARAM(p) ODBC_PARAM_##p,
576 enum {
577  ODBC_PARAM_LIST
578  ODBC_PARAM_SIZE
579 };
580 #undef ODBC_PARAM
581 
582 
583 /*
584  * connectparams.h
585  */
586 
587 typedef struct {
588  const char *p;
589  size_t len;
591 
599 int odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
600 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
601 #ifdef _WIN32
602 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
603 #endif
604 
605 /*
606  * convert_tds2sql.c
607  */
608 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);
609 
610 /*
611  * descriptor.c
612  */
613 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
614 SQLRETURN desc_free(TDS_DESC * desc);
615 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
616 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
617 SQLRETURN desc_free_records(TDS_DESC * desc);
618 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
619 
620 /*
621  * odbc.c
622  */
623 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
624 
625 /*
626  * odbc_checks.h
627  */
628 #if ENABLE_EXTRA_CHECKS
629 /* macro */
630 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
631 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
632 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
633 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
634 /* declarations*/
635 void odbc_check_env_extra(TDS_ENV * env);
636 void odbc_check_dbc_extra(TDS_DBC * dbc);
637 void odbc_check_stmt_extra(TDS_STMT * stmt);
638 void odbc_check_desc_extra(TDS_DESC * desc);
639 #else
640 /* macro */
641 #define CHECK_ENV_EXTRA(env)
642 #define CHECK_DBC_EXTRA(dbc)
643 #define CHECK_STMT_EXTRA(stmt)
644 #define CHECK_DESC_EXTRA(desc)
645 #endif
646 
647 /*
648  * odbc_util.h
649  */
650 
651 /* helpers for ODBC wide string support */
652 #undef _wide
653 #undef _WIDE
654 #ifdef ENABLE_ODBC_WIDE
655 typedef union {
656  char mb[1];
657  SQLWCHAR wide[1];
658 } ODBC_CHAR;
659 # define _wide ,wide
660 # define _wide0 ,0
661 # define _WIDE ,int wide
662 #else
663 # define _wide
664 # define _wide0
665 # define _WIDE
666 # define ODBC_CHAR SQLCHAR
667 #endif
668 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
669 int odbc_set_stmt_prepared_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
670 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
671 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
672 
676 static inline SQLSMALLINT
677 odbc_server_to_sql_type(TDSCOLUMN *col)
678 {
679  return ((TDS_FUNCS *) col->funcs)->server_to_sql_type(col);
680 }
681 
682 static inline void
683 odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver)
684 {
685  ((TDS_FUNCS *) col->funcs)->set_type_info(col, drec, odbc_ver);
686 }
687 
688 int odbc_sql_to_c_type_default(int sql_type);
689 int odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
690 int odbc_c_to_server_type(int c_type);
691 
692 SQLINTEGER odbc_sql_to_displaysize(int sqltype, TDSCOLUMN *col);
693 int odbc_get_string_size(int size, ODBC_CHAR * str _WIDE);
694 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
695 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
696 
697 #ifdef ENABLE_ODBC_WIDE
698 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, ODBC_CHAR * str, int flag);
699 #define odbc_dstr_copy(dbc, s, len, out) \
700  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
701 #define odbc_dstr_copy_oct(dbc, s, len, out) \
702  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
703 #else
704 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, ODBC_CHAR * str);
705 #define odbc_dstr_copy_oct odbc_dstr_copy
706 #endif
707 
708 
709 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
710 #ifdef ENABLE_ODBC_WIDE
711 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
712  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))
713 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
714  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
715 #else
716 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
717  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
718 #define odbc_set_string_oct(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)?0x20:0x30))
720 #endif
721 
722 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
723 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
724 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
725 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
726 
727 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
728 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
729 
730 /*
731  * prepare_query.c
732  */
733 SQLRETURN prepare_call(struct _hstmt *stmt);
734 SQLRETURN native_sql(struct _hdbc *dbc, char *s);
735 int parse_prepared_query(struct _hstmt *stmt, int compute_row);
736 int start_parse_prepared_query(struct _hstmt *stmt, int compute_row);
737 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
738 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
739 
740 /*
741  * sql2tds.c
742  */
743 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);
744 
745 /*
746  * sqlwchar.c
747  */
748 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
749 size_t sqlwcslen(const SQLWCHAR * s);
750 
751 typedef struct sqlwstr_buf {
752  struct sqlwstr_buf *next;
753  wchar_t buf[256];
754 } SQLWSTRBUF;
755 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
756 void sqlwstr_free(SQLWSTRBUF *bufs);
757 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
758 #define SQLWSTR(s) sqlwstr(s, &bufs)
759 #define SQLWSTR_FREE() sqlwstr_free(bufs)
760 #else
761 #define sqlwcslen(s) wcslen(s)
762 
763 #define SQLWSTR_BUFS(n) do {} while(0)
764 #define SQLWSTR(s) ((const wchar_t*)(s))
765 #define SQLWSTR_FREE() do {} while(0)
766 #endif
767 
768 #if SIZEOF_SQLWCHAR == 2
769 # if WORDS_BIGENDIAN
770 # define ODBC_WIDE_NAME "UCS-2BE"
771 # define ODBC_WIDE_NAME_UTF "UTF-16BE"
772 # else
773 # define ODBC_WIDE_NAME "UCS-2LE"
774 # define ODBC_WIDE_NAME_UTF "UTF-16LE"
775 # endif
776 const char *odbc_get_wide_name(TDSCONNECTION *conn);
777 #elif SIZEOF_SQLWCHAR == 4
778 # if WORDS_BIGENDIAN
779 # define ODBC_WIDE_NAME "UCS-4BE"
780 # else
781 # define ODBC_WIDE_NAME "UCS-4LE"
782 # endif
783 static inline const char *
784 odbc_get_wide_name(TDSCONNECTION *conn)
785 {
786  return ODBC_WIDE_NAME;
787 }
788 #else
789 #error SIZEOF_SQLWCHAR not supported !!
790 #endif
791 
792 #include <freetds/popvis.h>
793 
794 #ifdef __cplusplus
795 #if 0
796 {
797 #endif
798 }
799 #endif
800 
801 #endif
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:324
char * query
query to execute
Definition: odbc.h:448
Definition: tds.h:996
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:480
Definition: odbc.h:441
Definition: odbc.h:171
Definition: odbc.h:216
Definition: tds.h:519
Definition: odbc.h:269
Definition: iconv.h:93
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition: odbc.h:363
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:360
Information for a server connection.
Definition: tds.h:1098
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:468
Main include file for libtds.
Definition: odbc.h:159
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:450
Structure to hold a string.
Definition: tds.h:93
Definition: odbc.h:587
Definition: tds.h:633
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:358
Definition: odbc.h:369
Definition: tds.h:1031
char * prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:470
Definition: odbc.h:498
unsigned int cursor_support
<>0 if server handle cursors
Definition: odbc.h:365
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition: odbc_util.c:961
Hold information for any results.
Definition: tds.h:739
Definition: odbc.h:339
Metadata about columns in regular and compute rows.
Definition: tds.h:662
Definition: odbc.h:311
struct _hstmt * next
next in list
Definition: odbc.h:453
struct _hstmt * prev
previous in list
Definition: odbc.h:455
Definition: odbc.h:302
Holds informations about a cursor.
Definition: tds.h:907
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:1081
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:1203
unsigned int param_count
number of parameter in current query
Definition: odbc.h:475
Definition: odbc.h:295
Definition: odbc.h:228
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:466
TDS_INT8 row_count
row count to return
Definition: odbc.h:478
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:970
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:645
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:944
Definition: odbc.h:287
Definition: thread.h:190