FreeTDS API
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 _tdsguard_gQHaPEvp2dAAa45TAutROb_
22 #define _tdsguard_gQHaPEvp2dAAa45TAutROb_
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 #ifdef HAVE_WCHAR_H
44 #include <wchar.h>
45 #endif
46 
47 #ifndef HAVE_SQLLEN
48 #ifndef SQLULEN
49 #define SQLULEN SQLUINTEGER
50 #endif
51 #ifndef SQLLEN
52 #define SQLLEN SQLINTEGER
53 #endif
54 #endif
55 
56 #ifndef HAVE_SQLSETPOSIROW
57 #define SQLSETPOSIROW SQLUSMALLINT
58 #endif
59 
60 #ifndef HAVE_SQLROWOFFSET
61 #define SQLROWOFFSET SQLLEN
62 #endif
63 
64 #ifndef HAVE_SQLROWSETSIZE
65 #define SQLROWSETSIZE SQLULEN
66 #endif
67 
68 #ifdef __cplusplus
69 extern "C"
70 {
71 #if 0
72 }
73 #endif
74 #endif
75 
76 #include <freetds/pushvis.h>
77 #ifdef __clang__
78 #define ODBC_API SQL_API __attribute__((visibility("default")))
79 #elif defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
80 #define ODBC_API SQL_API __attribute__((externally_visible))
81 #else
82 #define ODBC_API SQL_API
83 #endif
84 
85 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(__GNUC__)
86 # define ODBC_PUBLIC __attribute__((dllexport))
87 #else
88 # define ODBC_PUBLIC
89 #endif
90 
91 struct _sql_error
92 {
93  const char *msg;
94  char state2[6];
95  char state3[6];
96  TDS_UINT native;
97  char *server;
98  int linenum;
99  int msgstate;
100  int row;
101  bool msg_is_static;
102 };
103 
105 {
106  struct _sql_error *errs;
107  int num_errors;
108  SQLRETURN lastrc;
109  char ranked;
110 };
111 
112 typedef struct _sql_errors TDS_ERRS;
113 
114 #if ENABLE_EXTRA_CHECKS
115 void odbc_check_struct_extra(void *p);
116 #else
117 static inline void odbc_check_struct_extra(void *p TDS_UNUSED) {}
118 #endif
119 
120 #define ODBC_RETURN(handle, rc) \
121  do { odbc_check_struct_extra(handle); \
122  return handle->errs.lastrc = (rc); } while(0)
123 #define ODBC_RETURN_(handle) \
124  do { odbc_check_struct_extra(handle); \
125  return handle->errs.lastrc; } while(0)
126 
127 #define ODBC_EXIT(handle, rc) \
128  do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
129  odbc_check_struct_extra(handle); \
130  tds_mutex_unlock(&handle->mtx); \
131  return _odbc_rc; } while(0)
132 #define ODBC_EXIT_(handle) \
133  do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
134  odbc_check_struct_extra(handle); \
135  tds_mutex_unlock(&handle->mtx); \
136  return _odbc_rc; } while(0)
137 
138 
140 void odbc_errs_reset(struct _sql_errors *errs);
141 
143 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
144 
146 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
147  int msgstate, const char *server, int row);
148 
150 struct _dheader
151 {
152  SQLSMALLINT sql_desc_alloc_type;
153  /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
154  SQLSMALLINT sql_desc_count;
155  SQLINTEGER sql_desc_bind_type;
156  SQLULEN sql_desc_array_size;
157  SQLUSMALLINT *sql_desc_array_status_ptr;
158  SQLULEN *sql_desc_rows_processed_ptr;
159  SQLLEN *sql_desc_bind_offset_ptr;
160 };
161 
163 struct _drecord
164 {
165  DSTR sql_desc_base_column_name;
166  DSTR sql_desc_base_table_name;
167  SQLUINTEGER sql_desc_auto_unique_value;
168  SQLINTEGER sql_desc_case_sensitive;
169  DSTR sql_desc_catalog_name;
170  SQLPOINTER sql_desc_data_ptr;
171  SQLSMALLINT sql_desc_concise_type;
172  SQLSMALLINT sql_desc_datetime_interval_code;
173  SQLINTEGER sql_desc_datetime_interval_precision;
174  SQLLEN sql_desc_display_size;
175  SQLLEN *sql_desc_indicator_ptr;
176  DSTR sql_desc_label;
177  SQLULEN sql_desc_length;
178  /* this point to a constant buffer, do not free or modify */
179  const char *sql_desc_literal_prefix;
180  /* this point to a constant buffer, do not free or modify */
181  const char *sql_desc_literal_suffix;
182  DSTR sql_desc_local_type_name;
183  DSTR sql_desc_name;
184  SQLSMALLINT sql_desc_fixed_prec_scale;
185  SQLSMALLINT sql_desc_nullable;
186  SQLINTEGER sql_desc_num_prec_radix;
187  SQLLEN sql_desc_octet_length;
188  SQLLEN *sql_desc_octet_length_ptr;
189  SQLSMALLINT sql_desc_parameter_type;
190  SQLSMALLINT sql_desc_precision;
191  SQLSMALLINT sql_desc_rowver;
192  SQLSMALLINT sql_desc_scale;
193  DSTR sql_desc_schema_name;
194  DSTR sql_desc_table_name;
195  SQLSMALLINT sql_desc_searchable;
196  SQLSMALLINT sql_desc_type;
197  /* this point to a constant buffer, do not free or modify */
198  const char *sql_desc_type_name;
199  SQLSMALLINT sql_desc_unnamed;
200  SQLSMALLINT sql_desc_unsigned;
201  SQLSMALLINT sql_desc_updatable;
202 };
203 
204 struct _hdesc
205 {
206  SQLSMALLINT htype; /* do not reorder this field */
207  struct _sql_errors errs; /* do not reorder this field */
208  tds_mutex mtx;
209  int type;
216  int focus;
217  SQLHANDLE parent;
218  struct _dheader header;
219  struct _drecord *records;
220 };
221 
222 typedef struct _hdesc TDS_DESC;
223 
224 #define DESC_IRD 1
225 #define DESC_IPD 2
226 #define DESC_ARD 3
227 #define DESC_APD 4
228 
229 struct _heattr
230 {
231  SQLUINTEGER connection_pooling;
232  SQLUINTEGER cp_match;
233  SQLINTEGER odbc_version;
234  SQLINTEGER output_nts;
235 };
236 
237 struct _hchk
238 {
239  SQLSMALLINT htype; /* do not reorder this field */
240  struct _sql_errors errs; /* do not reorder this field */
241  tds_mutex mtx;
242 };
243 
244 struct _henv
245 {
246  SQLSMALLINT htype; /* do not reorder this field */
247  struct _sql_errors errs; /* do not reorder this field */
248  tds_mutex mtx;
249  TDSCONTEXT *tds_ctx;
250  struct _heattr attr;
251 };
252 
253 struct _hcattr
254 {
255  SQLUINTEGER access_mode;
256  SQLUINTEGER async_enable;
257  SQLUINTEGER auto_ipd;
258  SQLUINTEGER autocommit;
259  SQLUINTEGER connection_dead;
260  SQLUINTEGER connection_timeout;
261  DSTR current_catalog;
262  SQLUINTEGER login_timeout;
263  SQLUINTEGER metadata_id;
264  SQLUINTEGER odbc_cursors;
265  SQLUINTEGER packet_size;
266  SQLHWND quite_mode;
267  DSTR translate_lib;
268  SQLUINTEGER translate_option;
269  SQLUINTEGER txn_isolation;
270  SQLUINTEGER mars_enabled;
271  SQLUINTEGER cursor_type;
272  SQLUINTEGER bulk_enabled;
273 #ifdef TDS_NO_DM
274  SQLUINTEGER trace;
275  DSTR tracefile;
276 #endif
277 };
278 
279 #define TDS_MAX_APP_DESC 100
280 
281 struct _hstmt;
282 struct _hdbc
283 {
284  SQLSMALLINT htype; /* do not reorder this field */
285  struct _sql_errors errs; /* do not reorder this field */
286  tds_mutex mtx;
287  struct _henv *env;
289  DSTR dsn;
290  DSTR oldpwd;
291  DSTR db_filename;
292 #ifdef ENABLE_ODBC_WIDE
293  int original_charset_num;
294  TDSICONV *mb_conv;
295 #endif
296 
304  struct _hstmt *stmt_list;
305  struct _hcattr attr;
307  TDS_DESC *uad[TDS_MAX_APP_DESC];
309  unsigned int cursor_support:1;
310  unsigned int use_oldpwd:1;
311  TDS_INT default_query_timeout;
312 
313  TDSBCPINFO *bcpinfo;
314 };
315 
316 struct _hsattr
317 {
318  /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
319 /* TDS_DESC *app_row_desc; */
320 /* TDS_DESC *app_param_desc; */
321  SQLUINTEGER async_enable;
322  SQLUINTEGER concurrency;
323  SQLUINTEGER cursor_scrollable;
324  SQLUINTEGER cursor_sensitivity;
325  SQLUINTEGER cursor_type;
326  SQLUINTEGER enable_auto_ipd;
327  SQLPOINTER fetch_bookmark_ptr;
328  SQLULEN keyset_size;
329  SQLULEN max_length;
330  SQLULEN max_rows;
331  SQLUINTEGER metadata_id;
332  SQLUINTEGER noscan;
333  /* apd->sql_desc_bind_offset_ptr */
334  /* SQLUINTEGER *param_bind_offset_ptr; */
335  /* apd->sql_desc_bind_type */
336  /* SQLUINTEGER param_bind_type; */
337  /* apd->sql_desc_array_status_ptr */
338  /* SQLUSMALLINT *param_operation_ptr; */
339  /* ipd->sql_desc_array_status_ptr */
340  /* SQLUSMALLINT *param_status_ptr; */
341  /* ipd->sql_desc_rows_processed_ptr */
342  /* SQLUSMALLINT *params_processed_ptr; */
343  /* apd->sql_desc_array_size */
344  /* SQLUINTEGER paramset_size; */
345  SQLUINTEGER query_timeout;
346  SQLUINTEGER retrieve_data;
347  /* ard->sql_desc_bind_offset_ptr */
348  /* SQLUINTEGER *row_bind_offset_ptr; */
349  /* ard->sql_desc_array_size */
350  /* SQLUINTEGER row_array_size; */
351  /* ard->sql_desc_bind_type */
352  /* SQLUINTEGER row_bind_type; */
353  SQLULEN row_number;
354  /* ard->sql_desc_array_status_ptr */
355  /* SQLUINTEGER *row_operation_ptr; */
356  /* ird->sql_desc_array_status_ptr */
357  /* SQLUINTEGER *row_status_ptr; */
358  /* ird->sql_desc_rows_processed_ptr */
359  /* SQLUINTEGER *rows_fetched_ptr; */
360  SQLUINTEGER simulate_cursor;
361  SQLUINTEGER use_bookmarks;
362  /* SQLGetStmtAttr only */
363 /* TDS_DESC *imp_row_desc; */
364 /* TDS_DESC *imp_param_desc; */
365  DSTR qn_msgtext;
366  DSTR qn_options;
367  SQLUINTEGER qn_timeout;
368  SQLUINTEGER param_focus;
369 };
370 
371 typedef enum
372 {
373  NOT_IN_ROW,
374  IN_NORMAL_ROW,
375  IN_COMPUTE_ROW,
376  AFTER_COMPUTE_ROW,
377  PRE_NORMAL_ROW
378 } TDS_ODBC_ROW_STATUS;
379 
380 typedef enum
381 {
382  ODBC_SPECIAL_NONE = 0,
383  ODBC_SPECIAL_GETTYPEINFO = 1,
384  ODBC_SPECIAL_COLUMNS = 2,
385  ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
386  ODBC_SPECIAL_SPECIALCOLUMNS = 4
387 } TDS_ODBC_SPECIAL_ROWS;
388 
389 struct _hstmt
390 {
391  SQLSMALLINT htype; /* do not reorder this field */
392  struct _sql_errors errs; /* do not reorder this field */
393  tds_mutex mtx;
394  struct _hdbc *dbc;
399 
401  struct _hstmt *next;
403  struct _hstmt *prev;
404 
405  /* begin prepared query stuff */
406  unsigned is_prepared_query:1;
407  unsigned prepared_query_is_func:1;
408  unsigned prepared_query_is_rpc:1;
413  unsigned need_reprepare:1;
414  unsigned param_data_called:1;
415  unsigned params_queried:1;
416  unsigned params_set:1;
417  /* end prepared query stuff */
418 
424  size_t prepared_pos;
425 
426  unsigned int curr_param_row, num_param_rows;
427 
429  unsigned int param_count;
430  int row;
432  TDS_INT8 row_count;
434  TDS_ODBC_ROW_STATUS row_status;
435  /* do NOT free dynamic, free from socket or attach to connection */
436  TDSDYNAMIC *dyn;
437  TDS_DESC *ard, *ird, *apd, *ipd;
438  TDS_DESC *orig_ard, *orig_apd;
439  SQLULEN sql_rowset_size;
440  struct _hsattr attr;
441  DSTR cursor_name; /* auto generated cursor name */
442  TDS_ODBC_SPECIAL_ROWS special_row;
443  /* do NOT free cursor, free from socket or attach to connection */
444  TDSCURSOR *cursor;
445 };
446 
447 typedef struct _henv TDS_ENV;
448 typedef struct _hdbc TDS_DBC;
449 typedef struct _hstmt TDS_STMT;
450 typedef struct _hchk TDS_CHK;
451 
452 typedef struct {
453  /* this must be the first member */
454  TDSCOLUMNFUNCS common;
455  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
456 } TDS_FUNCS;
457 
458 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
459 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
460 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
461 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
462 
463 /* fix a bug in MingW headers */
464 #ifdef __MINGW32__
465 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
466 
467 #undef SQL_INTERVAL_YEAR
468 #undef SQL_INTERVAL_MONTH
469 #undef SQL_INTERVAL_DAY
470 #undef SQL_INTERVAL_HOUR
471 #undef SQL_INTERVAL_MINUTE
472 #undef SQL_INTERVAL_SECOND
473 #undef SQL_INTERVAL_YEAR_TO_MONTH
474 #undef SQL_INTERVAL_DAY_TO_HOUR
475 #undef SQL_INTERVAL_DAY_TO_MINUTE
476 #undef SQL_INTERVAL_DAY_TO_SECOND
477 #undef SQL_INTERVAL_HOUR_TO_MINUTE
478 #undef SQL_INTERVAL_HOUR_TO_SECOND
479 #undef SQL_INTERVAL_MINUTE_TO_SECOND
480 
481 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
482 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
483 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
484 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
485 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
486 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
487 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
488 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
489 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
490 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
491 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
492 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
493 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
494 
495 #endif
496 #endif
497 
498 #ifdef _WIN32
499 bool get_login_info(HWND hwndParent, TDSLOGIN * login);
500 #endif
501 
502 #define ODBC_PARAM_LIST \
503  ODBC_PARAM(Address) \
504  ODBC_PARAM(APP) \
505  ODBC_PARAM(ApplicationIntent) \
506  ODBC_PARAM(AttachDbFilename) \
507  ODBC_PARAM(ClientCharset) \
508  ODBC_PARAM(ConnectionTimeout) \
509  ODBC_PARAM(Database) \
510  ODBC_PARAM(DebugFlags) \
511  ODBC_PARAM(DSN) \
512  ODBC_PARAM(DumpFile) \
513  ODBC_PARAM(DumpFileAppend) \
514  ODBC_PARAM(Encrypt) \
515  ODBC_PARAM(Encryption) \
516  ODBC_PARAM(HostNameInCertificate) \
517  ODBC_PARAM(Language) \
518  ODBC_PARAM(MARS_Connection) \
519  ODBC_PARAM(PacketSize) \
520  ODBC_PARAM(Port) \
521  ODBC_PARAM(PWD) \
522  ODBC_PARAM(REALM) \
523  ODBC_PARAM(Server) \
524  ODBC_PARAM(ServerCertificate) \
525  ODBC_PARAM(Servername) \
526  ODBC_PARAM(ServerSPN) \
527  ODBC_PARAM(TDS_Version) \
528  ODBC_PARAM(TextSize) \
529  ODBC_PARAM(Timeout) \
530  ODBC_PARAM(Trusted_Connection) \
531  ODBC_PARAM(UID) \
532  ODBC_PARAM(UseNTLMv2) \
533  ODBC_PARAM(WSID)
534 
535 #define ODBC_PARAM(p) ODBC_PARAM_##p,
536 enum {
537  ODBC_PARAM_LIST
538  ODBC_PARAM_SIZE
539 };
540 #undef ODBC_PARAM
541 
542 #define ODBC_PARAM(p) extern const char odbc_param_##p[];
543 ODBC_PARAM_LIST
544 #undef ODBC_PARAM
545 
546 /*
547  * connectparams.h
548  */
549 
550 typedef struct {
551  const char *p;
552  size_t len;
554 
562 bool odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end,
563  TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
564 bool odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
565 #ifdef _WIN32
566 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
567 #endif
568 
569 /*
570  * convert_tds2sql.c
571  */
572 SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype,
573  TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
574 SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
575 
576 
577 
578 /*
579  * descriptor.c
580  */
581 typedef struct {
582  DSTR type_name;
583  TDS_DESC *apd;
584  TDS_DESC *ipd;
585 } SQLTVP;
586 
587 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
588 SQLRETURN desc_free(TDS_DESC * desc);
589 SQLRETURN desc_alloc_records(TDS_DESC * desc, SQLSMALLINT count);
590 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
591 SQLRETURN desc_free_records(TDS_DESC * desc);
592 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
593 SQLTVP *tvp_alloc(TDS_STMT *stmt);
594 void tvp_free(SQLTVP *tvp);
595 
596 /*
597  * odbc.c
598  */
599 
600 SQLRETURN odbc_SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
601 
602 /*
603  * odbc_checks.h
604  */
605 #if ENABLE_EXTRA_CHECKS
606 /* macro */
607 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
608 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
609 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
610 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
611 /* declarations*/
612 void odbc_check_env_extra(TDS_ENV * env);
613 void odbc_check_dbc_extra(TDS_DBC * dbc);
614 void odbc_check_stmt_extra(TDS_STMT * stmt);
615 void odbc_check_desc_extra(TDS_DESC * desc);
616 #else
617 /* macro */
618 #define CHECK_ENV_EXTRA(env)
619 #define CHECK_DBC_EXTRA(dbc)
620 #define CHECK_STMT_EXTRA(stmt)
621 #define CHECK_DESC_EXTRA(desc)
622 #endif
623 
624 /*
625  * odbc_util.h
626  */
627 
628 /* helpers for ODBC wide string support */
629 #undef _wide
630 #undef _WIDE
631 #ifdef ENABLE_ODBC_WIDE
632 typedef union {
633  char mb[1];
634  SQLWCHAR wide[1];
635 } ODBC_CHAR;
636 # define _wide ,wide
637 # define _wide0 ,0
638 # define _WIDE ,int wide
639 #else
640 # define _wide
641 # define _wide0
642 # define _WIDE
643 # define ODBC_CHAR SQLCHAR
644 #endif
645 SQLRETURN odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, ptrdiff_t sql_len _WIDE);
646 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
647 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
648 
649 void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
650 
651 int odbc_sql_to_c_type_default(int sql_type);
652 TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
653 TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
654 
655 size_t odbc_get_string_size(ptrdiff_t size, const ODBC_CHAR * str _WIDE);
656 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
657 SQLLEN odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd,
658  const TDS_DESC* axd, SQLSETPOSIROW n_row);
659 
660 #ifdef ENABLE_ODBC_WIDE
661 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str, int flag);
662 #define odbc_dstr_copy(dbc, s, len, out) \
663  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
664 #define odbc_dstr_copy_oct(dbc, s, len, out) \
665  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
666 #else
667 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str);
668 #define odbc_dstr_copy_oct odbc_dstr_copy
669 #endif
670 
671 
672 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer,
673  const char *s, ptrdiff_t len, int flag);
674 #ifdef ENABLE_ODBC_WIDE
675 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
676  odbc_set_string_flag(dbc, sizeof((buf)->mb) ? (buf) : (buf), buf_len, out_len, s, s_len, \
677  (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
678 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
679  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
680 #else
681 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
682  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
683 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
684  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
685 #endif
686 
687 #define odbc_set_dstr_oct(dbc, buf, buf_len, out_len, s) \
688  odbc_set_string_oct(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
689 #define odbc_set_dstr(dbc, buf, buf_len, out_len, s) odbc_set_string(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
690 
691 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
692 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
693 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
694 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
695 
696 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
697 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
698 
699 /*
700  * prepare_query.c
701  */
702 SQLRETURN prepare_call(struct _hstmt *stmt);
703 SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
704 int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
705 int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
706 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
707 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
708 const char *odbc_skip_rpc_name(const char *s);
709 
710 /*
711  * sql2tds.c
712  */
713 typedef union {
714  TDS_DATETIMEALL dta;
715  TDS_NUMERIC num;
717 
718 SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol,
719  bool compute_row, const TDS_DESC* axd, SQLSETPOSIROW n_row);
720 TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
721 TDS_INT convert_numeric2server(struct _sql_errors *errs, const void *src, TDS_NUMERIC *num);
722 
723 /*
724  * bcp.c
725  */
726 void odbc_bcp_free_storage(TDS_DBC *dbc);
727 void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
728 void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
729 void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
730 void odbc_bcp_sendrow(TDS_DBC *dbc);
731 int odbc_bcp_batch(TDS_DBC *dbc);
732 int odbc_bcp_done(TDS_DBC *dbc);
733 void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen,
734  int vartype, int table_column);
735 
736 /*
737  * sqlwchar.c
738  */
739 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
740 size_t sqlwcslen(const SQLWCHAR * s);
741 #else
742 #define sqlwcslen(s) wcslen(s)
743 #endif
744 
745 #ifdef ENABLE_ODBC_WIDE
746 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
747 typedef struct sqlwstr_buf {
748  struct sqlwstr_buf *next;
749  wchar_t buf[256];
750 } SQLWSTRBUF;
751 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
752 void sqlwstr_free(SQLWSTRBUF *bufs);
753 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
754 #define SQLWSTR(s) sqlwstr(s, &bufs)
755 #define SQLWSTR_FREE() sqlwstr_free(bufs)
756 #else
757 #define SQLWSTR_BUFS(n) do {} while(0)
758 #define SQLWSTR(s) ((const wchar_t*)(s))
759 #define SQLWSTR_FREE() do {} while(0)
760 #endif
761 #endif
762 
763 int odbc_get_wide_canonic(TDSCONNECTION *conn);
764 
765 /* compatibility with old BCP implementation */
766 #define BCPHINTS_OLD 6
767 #define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL_OLD (SQL_COPT_TDSODBC_IMPL_BASE+1)
768 
769 /* iODBC extensions used by our driver */
770 #ifndef SQL_ATTR_DRIVER_UNICODE_TYPE
771 #define SQL_ATTR_DRIVER_UNICODE_TYPE 1065
772 #endif
773 
774 #ifndef SQL_DM_CP_UTF16
775 #define SQL_DM_CP_UTF16 1
776 #endif
777 #ifndef SQL_DM_CP_UTF8
778 #define SQL_DM_CP_UTF8 2
779 #endif
780 #ifndef SQL_DM_CP_UCS4
781 #define SQL_DM_CP_UCS4 3
782 #endif
783 
784 #include <freetds/popvis.h>
785 
786 #ifdef __cplusplus
787 #if 0
788 {
789 #endif
790 }
791 #endif
792 
793 #endif
Definition: proto.h:25
Definition: odbc.h:204
Definition: odbc.h:550
Definition: tds.h:1022
Definition: odbc.h:316
Definition: tds.h:1697
unsigned int cursor_support
<>0 if server handle cursors
Definition: odbc.h:309
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:304
Information for a server connection.
Definition: tds.h:1170
Definition: odbc.h:713
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition: odbc_util.c:861
Definition: odbc.h:104
SQLLEN odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC *axd, SQLSETPOSIROW n_row)
Return length of parameter from parameter information.
Definition: odbc_util.c:870
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:424
Definition: odbc.h:237
Structure to hold a string.
Definition: string.h:37
Holds information about a cursor.
Definition: tds.h:928
Descriptor record.
Definition: odbc.h:163
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:420
Definition: odbc.h:91
Metadata about columns in regular and compute rows.
Definition: tds.h:680
SQLRETURN odbc_set_string_flag(TDS_DBC *dbc TDS_UNUSED, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR *pcbBuffer, const char *s, ptrdiff_t len, int flag)
Copy a string to client setting size according to ODBC convenction.
Definition: odbc_util.c:304
Definition: odbc.h:253
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:969
Definition: odbc.h:229
DSTR query
query to execute
Definition: odbc.h:396
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:988
TDS_ODBC_ROW_STATUS row_status
status of row, it can happen that this flag mark that we are still parsing row, this it&#39;s normal ...
Definition: odbc.h:434
int focus
Nested descriptor to use.
Definition: odbc.h:216
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:398
unsigned int param_count
number of parameter in current query
Definition: odbc.h:429
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition: odbc.h:413
Definition: odbc.h:452
Definition: odbc.h:282
int param_num
last valid parameter in params, it&#39;s a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:422
Definition: tds.h:501
Definition: tds.h:1084
Definition: odbc.h:581
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:302
TDS_SERVER_TYPE 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:605
Descriptor header.
Definition: odbc.h:150
Hold information for any results.
Definition: tds.h:760
This structure is not directly connected to TDS protocol but keeps any DATE/TIME information.
Definition: tds.h:144
Definition: odbc.h:389
Definition: iconv.h:97
Definition: tds.h:634
struct _hstmt * next
next in list
Definition: odbc.h:401
struct _hstmt * prev
previous in list
Definition: odbc.h:403
TDS_INT8 row_count
row count to return
Definition: odbc.h:432
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:1115
Main include file for libtds.
Definition: odbc.h:244