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