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 _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 #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 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
78 #define ODBC_API SQL_API __attribute__((externally_visible))
79 #else
80 #define ODBC_API SQL_API
81 #endif
82 
83 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(__GNUC__)
84 # define ODBC_PUBLIC __attribute__((dllexport))
85 #else
86 # define ODBC_PUBLIC
87 #endif
88 
89 #define ODBC_MAX(a,b) ( (a) > (b) ? (a) : (b) )
90 #define ODBC_MIN(a,b) ( (a) < (b) ? (a) : (b) )
91 #define ODBC_CLAMP(x,a,b) ( (x) < (a) ? (a) : (x) > (b) ? (b) : (x) )
92 
93 struct _sql_error
94 {
95  const char *msg;
96  char state2[6];
97  char state3[6];
98  TDS_UINT native;
99  char *server;
100  int linenum;
101  int msgstate;
102  int row;
103 };
104 
106 {
107  struct _sql_error *errs;
108  int num_errors;
109  SQLRETURN lastrc;
110  char ranked;
111 };
112 
113 typedef struct _sql_errors TDS_ERRS;
114 
115 #if ENABLE_EXTRA_CHECKS
116 void odbc_check_struct_extra(void *p);
117 #else
118 static inline void odbc_check_struct_extra(void *p) {}
119 #endif
120 
121 #define ODBC_RETURN(handle, rc) \
122  do { odbc_check_struct_extra(handle); \
123  return handle->errs.lastrc = (rc); } while(0)
124 #define ODBC_RETURN_(handle) \
125  do { odbc_check_struct_extra(handle); \
126  return handle->errs.lastrc; } while(0)
127 
128 #define ODBC_EXIT(handle, rc) \
129  do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
130  odbc_check_struct_extra(handle); \
131  tds_mutex_unlock(&handle->mtx); \
132  return _odbc_rc; } while(0)
133 #define ODBC_EXIT_(handle) \
134  do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
135  odbc_check_struct_extra(handle); \
136  tds_mutex_unlock(&handle->mtx); \
137  return _odbc_rc; } while(0)
138 
139 
141 void odbc_errs_reset(struct _sql_errors *errs);
142 
144 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
145 
147 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
148  int msgstate, const char *server, int row);
149 
151 struct _dheader
152 {
153  SQLSMALLINT sql_desc_alloc_type;
154  /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
155  SQLSMALLINT sql_desc_count;
156  SQLINTEGER sql_desc_bind_type;
157  SQLULEN sql_desc_array_size;
158  SQLUSMALLINT *sql_desc_array_status_ptr;
159  SQLULEN *sql_desc_rows_processed_ptr;
160  SQLLEN *sql_desc_bind_offset_ptr;
161 };
162 
164 struct _drecord
165 {
166  DSTR sql_desc_base_column_name;
167  DSTR sql_desc_base_table_name;
168  SQLUINTEGER sql_desc_auto_unique_value;
169  SQLINTEGER sql_desc_case_sensitive;
170  DSTR sql_desc_catalog_name;
171  SQLPOINTER sql_desc_data_ptr;
172  SQLSMALLINT sql_desc_concise_type;
173  SQLSMALLINT sql_desc_datetime_interval_code;
174  SQLINTEGER sql_desc_datetime_interval_precision;
175  SQLLEN sql_desc_display_size;
176  SQLLEN *sql_desc_indicator_ptr;
177  DSTR sql_desc_label;
178  SQLULEN sql_desc_length;
179  /* this point to a constant buffer, do not free or modify */
180  const char *sql_desc_literal_prefix;
181  /* this point to a constant buffer, do not free or modify */
182  const char *sql_desc_literal_suffix;
183  DSTR sql_desc_local_type_name;
184  DSTR sql_desc_name;
185  SQLSMALLINT sql_desc_fixed_prec_scale;
186  SQLSMALLINT sql_desc_nullable;
187  SQLINTEGER sql_desc_num_prec_radix;
188  SQLLEN sql_desc_octet_length;
189  SQLLEN *sql_desc_octet_length_ptr;
190  SQLSMALLINT sql_desc_parameter_type;
191  SQLSMALLINT sql_desc_precision;
192  SQLSMALLINT sql_desc_rowver;
193  SQLSMALLINT sql_desc_scale;
194  DSTR sql_desc_schema_name;
195  DSTR sql_desc_table_name;
196  SQLSMALLINT sql_desc_searchable;
197  SQLSMALLINT sql_desc_type;
198  /* this point to a constant buffer, do not free or modify */
199  const char *sql_desc_type_name;
200  SQLSMALLINT sql_desc_unnamed;
201  SQLSMALLINT sql_desc_unsigned;
202  SQLSMALLINT sql_desc_updatable;
203 };
204 
205 struct _hdesc
206 {
207  SQLSMALLINT htype; /* do not reorder this field */
208  struct _sql_errors errs; /* do not reorder this field */
209  tds_mutex mtx;
210  int type;
217  int focus;
218  SQLHANDLE parent;
219  struct _dheader header;
220  struct _drecord *records;
221 };
222 
223 typedef struct _hdesc TDS_DESC;
224 
225 #define DESC_IRD 1
226 #define DESC_IPD 2
227 #define DESC_ARD 3
228 #define DESC_APD 4
229 
230 struct _heattr
231 {
232  SQLUINTEGER connection_pooling;
233  SQLUINTEGER cp_match;
234  SQLINTEGER odbc_version;
235  SQLINTEGER output_nts;
236 };
237 
238 struct _hchk
239 {
240  SQLSMALLINT htype; /* do not reorder this field */
241  struct _sql_errors errs; /* do not reorder this field */
242  tds_mutex mtx;
243 };
244 
245 struct _henv
246 {
247  SQLSMALLINT htype; /* do not reorder this field */
248  struct _sql_errors errs; /* do not reorder this field */
249  tds_mutex mtx;
250  TDSCONTEXT *tds_ctx;
251  struct _heattr attr;
252 };
253 
254 struct _hcattr
255 {
256  SQLUINTEGER access_mode;
257  SQLUINTEGER async_enable;
258  SQLUINTEGER auto_ipd;
259  SQLUINTEGER autocommit;
260  SQLUINTEGER connection_dead;
261  SQLUINTEGER connection_timeout;
262  DSTR current_catalog;
263  SQLUINTEGER login_timeout;
264  SQLUINTEGER metadata_id;
265  SQLUINTEGER odbc_cursors;
266  SQLUINTEGER packet_size;
267  SQLHWND quite_mode;
268  DSTR translate_lib;
269  SQLUINTEGER translate_option;
270  SQLUINTEGER txn_isolation;
271  SQLUINTEGER mars_enabled;
272  SQLUINTEGER cursor_type;
273  SQLUINTEGER bulk_enabled;
274 #ifdef TDS_NO_DM
275  SQLUINTEGER trace;
276  DSTR tracefile;
277 #endif
278 };
279 
280 #define TDS_MAX_APP_DESC 100
281 
282 struct _hstmt;
283 struct _hdbc
284 {
285  SQLSMALLINT htype; /* do not reorder this field */
286  struct _sql_errors errs; /* do not reorder this field */
287  tds_mutex mtx;
288  struct _henv *env;
290  DSTR dsn;
291  DSTR oldpwd;
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  /* end prepared query stuff */
416 
422  size_t prepared_pos;
423 
424  unsigned int curr_param_row, num_param_rows;
425 
427  unsigned int param_count;
428  int row;
430  TDS_INT8 row_count;
432  TDS_ODBC_ROW_STATUS row_status;
433  /* do NOT free dynamic, free from socket or attach to connection */
434  TDSDYNAMIC *dyn;
435  TDS_DESC *ard, *ird, *apd, *ipd;
436  TDS_DESC *orig_ard, *orig_apd;
437  SQLULEN sql_rowset_size;
438  struct _hsattr attr;
439  DSTR cursor_name; /* auto generated cursor name */
440  TDS_ODBC_SPECIAL_ROWS special_row;
441  /* do NOT free cursor, free from socket or attach to connection */
442  TDSCURSOR *cursor;
443 };
444 
445 typedef struct _henv TDS_ENV;
446 typedef struct _hdbc TDS_DBC;
447 typedef struct _hstmt TDS_STMT;
448 typedef struct _hchk TDS_CHK;
449 
450 typedef struct {
451  /* this must be the first member */
452  TDSCOLUMNFUNCS common;
453  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
454 } TDS_FUNCS;
455 
456 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
457 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
458 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
459 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
460 
461 /* fix a bug in MingW headers */
462 #ifdef __MINGW32__
463 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
464 
465 #undef SQL_INTERVAL_YEAR
466 #undef SQL_INTERVAL_MONTH
467 #undef SQL_INTERVAL_DAY
468 #undef SQL_INTERVAL_HOUR
469 #undef SQL_INTERVAL_MINUTE
470 #undef SQL_INTERVAL_SECOND
471 #undef SQL_INTERVAL_YEAR_TO_MONTH
472 #undef SQL_INTERVAL_DAY_TO_HOUR
473 #undef SQL_INTERVAL_DAY_TO_MINUTE
474 #undef SQL_INTERVAL_DAY_TO_SECOND
475 #undef SQL_INTERVAL_HOUR_TO_MINUTE
476 #undef SQL_INTERVAL_HOUR_TO_SECOND
477 #undef SQL_INTERVAL_MINUTE_TO_SECOND
478 
479 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
480 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
481 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
482 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
483 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
484 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
485 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
486 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
487 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
488 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
489 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
490 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
491 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
492 
493 #endif
494 #endif
495 
496 #ifdef _WIN32
497 bool get_login_info(HWND hwndParent, TDSLOGIN * login);
498 #endif
499 
500 #define ODBC_PARAM_LIST \
501  ODBC_PARAM(Servername) \
502  ODBC_PARAM(Server) \
503  ODBC_PARAM(DSN) \
504  ODBC_PARAM(UID) \
505  ODBC_PARAM(PWD) \
506  ODBC_PARAM(Address) \
507  ODBC_PARAM(Port) \
508  ODBC_PARAM(TDS_Version) \
509  ODBC_PARAM(Language) \
510  ODBC_PARAM(Database) \
511  ODBC_PARAM(TextSize) \
512  ODBC_PARAM(PacketSize) \
513  ODBC_PARAM(ClientCharset) \
514  ODBC_PARAM(DumpFile) \
515  ODBC_PARAM(DumpFileAppend) \
516  ODBC_PARAM(DebugFlags) \
517  ODBC_PARAM(Encryption) \
518  ODBC_PARAM(Trusted_Connection) \
519  ODBC_PARAM(APP) \
520  ODBC_PARAM(WSID) \
521  ODBC_PARAM(UseNTLMv2) \
522  ODBC_PARAM(MARS_Connection) \
523  ODBC_PARAM(REALM) \
524  ODBC_PARAM(ServerSPN) \
525  ODBC_PARAM(AttachDbFilename) \
526  ODBC_PARAM(ApplicationIntent) \
527  ODBC_PARAM(Timeout)
528 
529 #define ODBC_PARAM(p) ODBC_PARAM_##p,
530 enum {
531  ODBC_PARAM_LIST
532  ODBC_PARAM_SIZE
533 };
534 #undef ODBC_PARAM
535 
536 
537 /*
538  * connectparams.h
539  */
540 
541 typedef struct {
542  const char *p;
543  size_t len;
545 
553 bool odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
554 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
555 #ifdef _WIN32
556 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
557 #endif
558 
559 /*
560  * convert_tds2sql.c
561  */
562 SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
563 SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
564 
565 
566 
567 /*
568  * descriptor.c
569  */
570 typedef struct {
571  DSTR type_name;
572  TDS_DESC *apd;
573  TDS_DESC *ipd;
574 } SQLTVP;
575 
576 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
577 SQLRETURN desc_free(TDS_DESC * desc);
578 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
579 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
580 SQLRETURN desc_free_records(TDS_DESC * desc);
581 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
582 SQLTVP *tvp_alloc(TDS_STMT *stmt);
583 void tvp_free(SQLTVP *tvp);
584 
585 /*
586  * odbc.c
587  */
588 
589 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
590 
591 /*
592  * odbc_checks.h
593  */
594 #if ENABLE_EXTRA_CHECKS
595 /* macro */
596 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
597 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
598 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
599 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
600 /* declarations*/
601 void odbc_check_env_extra(TDS_ENV * env);
602 void odbc_check_dbc_extra(TDS_DBC * dbc);
603 void odbc_check_stmt_extra(TDS_STMT * stmt);
604 void odbc_check_desc_extra(TDS_DESC * desc);
605 #else
606 /* macro */
607 #define CHECK_ENV_EXTRA(env)
608 #define CHECK_DBC_EXTRA(dbc)
609 #define CHECK_STMT_EXTRA(stmt)
610 #define CHECK_DESC_EXTRA(desc)
611 #endif
612 
613 /*
614  * odbc_util.h
615  */
616 
617 /* helpers for ODBC wide string support */
618 #undef _wide
619 #undef _WIDE
620 #ifdef ENABLE_ODBC_WIDE
621 typedef union {
622  char mb[1];
623  SQLWCHAR wide[1];
624 } ODBC_CHAR;
625 # define _wide ,wide
626 # define _wide0 ,0
627 # define _WIDE ,int wide
628 #else
629 # define _wide
630 # define _wide0
631 # define _WIDE
632 # define ODBC_CHAR SQLCHAR
633 #endif
634 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
635 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
636 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
637 
638 void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
639 
640 int odbc_sql_to_c_type_default(int sql_type);
641 TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
642 TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
643 
644 unsigned int odbc_get_string_size(int size, const ODBC_CHAR * str _WIDE);
645 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
646 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
647 
648 #ifdef ENABLE_ODBC_WIDE
649 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
650 #define odbc_dstr_copy(dbc, s, len, out) \
651  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
652 #define odbc_dstr_copy_oct(dbc, s, len, out) \
653  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
654 #else
655 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
656 #define odbc_dstr_copy_oct odbc_dstr_copy
657 #endif
658 
659 
660 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
661 #ifdef ENABLE_ODBC_WIDE
662 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
663  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))
664 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
665  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
666 #else
667 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
668  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
669 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
670  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
671 #endif
672 
673 #define odbc_set_dstr_oct(dbc, buf, buf_len, out_len, s) odbc_set_string_oct(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
674 #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))
675 
676 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
677 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
678 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
679 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
680 
681 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
682 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
683 
684 /*
685  * prepare_query.c
686  */
687 SQLRETURN prepare_call(struct _hstmt *stmt);
688 SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
689 int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
690 int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
691 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
692 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
693 const char *odbc_skip_rpc_name(const char *s);
694 
695 /*
696  * sql2tds.c
697  */
698 SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol, bool compute_row, const TDS_DESC* axd, unsigned int n_row);
699 TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
700 
701 /*
702  * bcp.c
703  */
704 void odbc_bcp_free_storage(TDS_DBC *dbc);
705 void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
706 void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
707 void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
708 void odbc_bcp_sendrow(TDS_DBC *dbc);
709 int odbc_bcp_batch(TDS_DBC *dbc);
710 int odbc_bcp_done(TDS_DBC *dbc);
711 void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
712 
713 /*
714  * sqlwchar.c
715  */
716 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
717 size_t sqlwcslen(const SQLWCHAR * s);
718 
719 typedef struct sqlwstr_buf {
720  struct sqlwstr_buf *next;
721  wchar_t buf[256];
722 } SQLWSTRBUF;
723 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
724 void sqlwstr_free(SQLWSTRBUF *bufs);
725 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
726 #define SQLWSTR(s) sqlwstr(s, &bufs)
727 #define SQLWSTR_FREE() sqlwstr_free(bufs)
728 #else
729 #define sqlwcslen(s) wcslen(s)
730 
731 #define SQLWSTR_BUFS(n) do {} while(0)
732 #define SQLWSTR(s) ((const wchar_t*)(s))
733 #define SQLWSTR_FREE() do {} while(0)
734 #endif
735 
736 int odbc_get_wide_canonic(TDSCONNECTION *conn);
737 
738 #include <freetds/popvis.h>
739 
740 #ifdef __cplusplus
741 #if 0
742 {
743 #endif
744 }
745 #endif
746 
747 #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:857
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:302
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
Definition: odbc.h:105
Holds informations about a cursor.
Definition: tds.h:940
Definition: iconv.h:91
Descriptor record.
Definition: odbc.h:164
Definition: odbc.h:230
Definition: tds.h:517
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:980
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:432
Hold information for any results.
Definition: tds.h:772
Main include file for libtds.
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:601
Definition: odbc.h:93
Definition: tds.h:1032
struct _hstmt * next
next in list
Definition: odbc.h:401
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:1111
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:398
Definition: odbc.h:389
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:420
int focus
Nested descriptor to use.
Definition: odbc.h:217
unsigned int param_count
number of parameter in current query
Definition: odbc.h:427
Descriptor header.
Definition: odbc.h:151
Definition: odbc.h:450
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information...
Definition: tds.h:144
Definition: odbc.h:205
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:422
Definition: odbc.h:238
Definition: tds.h:1699
unsigned int cursor_support
<>0 if server handle cursors
Definition: odbc.h:309
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition: odbc.h:307
Structure to hold a string.
Definition: string.h:36
Definition: odbc.h:316
Definition: tds.h:646
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:984
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:418
struct _hstmt * prev
previous in list
Definition: odbc.h:403
Definition: tds.h:1094
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:304
Information for a server connection.
Definition: tds.h:1179
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition: odbc.h:413
Definition: odbc.h:283
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:301
Definition: odbc.h:541
Definition: odbc.h:254
DSTR query
query to execute
Definition: odbc.h:396
TDS_INT8 row_count
row count to return
Definition: odbc.h:430
Definition: odbc.h:570
Definition: odbc.h:245
Metadata about columns in regular and compute rows.
Definition: tds.h:692