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