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