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