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 #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 oldpwd;
278 #ifdef ENABLE_ODBC_WIDE
279  DSTR original_charset;
280  TDSICONV *mb_conv;
281 #endif
282 
290  struct _hstmt *stmt_list;
291  struct _hcattr attr;
293  TDS_DESC *uad[TDS_MAX_APP_DESC];
295  unsigned int cursor_support:1;
296  unsigned int use_oldpwd:1;
297  TDS_INT default_query_timeout;
298 
299  TDSBCPINFO *bcpinfo;
300  char *bcphint;
301 };
302 
303 struct _hsattr
304 {
305  /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
306 /* TDS_DESC *app_row_desc; */
307 /* TDS_DESC *app_param_desc; */
308  SQLUINTEGER async_enable;
309  SQLUINTEGER concurrency;
310  SQLUINTEGER cursor_scrollable;
311  SQLUINTEGER cursor_sensitivity;
312  SQLUINTEGER cursor_type;
313  SQLUINTEGER enable_auto_ipd;
314  SQLPOINTER fetch_bookmark_ptr;
315  SQLULEN keyset_size;
316  SQLULEN max_length;
317  SQLULEN max_rows;
318  SQLUINTEGER metadata_id;
319  SQLUINTEGER noscan;
320  /* apd->sql_desc_bind_offset_ptr */
321  /* SQLUINTEGER *param_bind_offset_ptr; */
322  /* apd->sql_desc_bind_type */
323  /* SQLUINTEGER param_bind_type; */
324  /* apd->sql_desc_array_status_ptr */
325  /* SQLUSMALLINT *param_operation_ptr; */
326  /* ipd->sql_desc_array_status_ptr */
327  /* SQLUSMALLINT *param_status_ptr; */
328  /* ipd->sql_desc_rows_processed_ptr */
329  /* SQLUSMALLINT *params_processed_ptr; */
330  /* apd->sql_desc_array_size */
331  /* SQLUINTEGER paramset_size; */
332  SQLUINTEGER query_timeout;
333  SQLUINTEGER retrieve_data;
334  /* ard->sql_desc_bind_offset_ptr */
335  /* SQLUINTEGER *row_bind_offset_ptr; */
336  /* ard->sql_desc_array_size */
337  /* SQLUINTEGER row_array_size; */
338  /* ard->sql_desc_bind_type */
339  /* SQLUINTEGER row_bind_type; */
340  SQLULEN row_number;
341  /* ard->sql_desc_array_status_ptr */
342  /* SQLUINTEGER *row_operation_ptr; */
343  /* ird->sql_desc_array_status_ptr */
344  /* SQLUINTEGER *row_status_ptr; */
345  /* ird->sql_desc_rows_processed_ptr */
346  /* SQLUINTEGER *rows_fetched_ptr; */
347  SQLUINTEGER simulate_cursor;
348  SQLUINTEGER use_bookmarks;
349  /* SQLGetStmtAttr only */
350 /* TDS_DESC *imp_row_desc; */
351 /* TDS_DESC *imp_param_desc; */
352  DSTR qn_msgtext;
353  DSTR qn_options;
354  SQLUINTEGER qn_timeout;
355 };
356 
357 typedef enum
358 {
359  NOT_IN_ROW,
360  IN_NORMAL_ROW,
361  IN_COMPUTE_ROW,
362  AFTER_COMPUTE_ROW,
363  PRE_NORMAL_ROW
364 } TDS_ODBC_ROW_STATUS;
365 
366 typedef enum
367 {
368  ODBC_SPECIAL_NONE = 0,
369  ODBC_SPECIAL_GETTYPEINFO = 1,
370  ODBC_SPECIAL_COLUMNS = 2,
371  ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
372  ODBC_SPECIAL_SPECIALCOLUMNS = 4
373 } TDS_ODBC_SPECIAL_ROWS;
374 
375 struct _hstmt
376 {
377  SQLSMALLINT htype; /* do not reorder this field */
378  struct _sql_errors errs; /* do not reorder this field */
379  tds_mutex mtx;
380  struct _hdbc *dbc;
385 
387  struct _hstmt *next;
389  struct _hstmt *prev;
390 
391  /* begin prepared query stuff */
392  unsigned is_prepared_query:1;
393  unsigned prepared_query_is_func:1;
394  unsigned prepared_query_is_rpc:1;
399  unsigned need_reprepare:1;
400  unsigned param_data_called:1;
401  /* end prepared query stuff */
402 
409 
410  unsigned int curr_param_row, num_param_rows;
411 
413  unsigned int param_count;
414  int row;
416  TDS_INT8 row_count;
418  TDS_ODBC_ROW_STATUS row_status;
419  /* do NOT free dynamic, free from socket or attach to connection */
420  TDSDYNAMIC *dyn;
421  TDS_DESC *ard, *ird, *apd, *ipd;
422  TDS_DESC *orig_ard, *orig_apd;
423  SQLULEN sql_rowset_size;
424  struct _hsattr attr;
425  DSTR cursor_name; /* auto generated cursor name */
426  TDS_ODBC_SPECIAL_ROWS special_row;
427  /* do NOT free cursor, free from socket or attach to connection */
428  TDSCURSOR *cursor;
429 };
430 
431 typedef struct _henv TDS_ENV;
432 typedef struct _hdbc TDS_DBC;
433 typedef struct _hstmt TDS_STMT;
434 typedef struct _hchk TDS_CHK;
435 
436 typedef struct {
437  /* this must be the first member */
438  TDSCOLUMNFUNCS common;
439  void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
440 } TDS_FUNCS;
441 
442 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
443 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
444 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
445 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
446 
447 /* fix a bug in MingW headers */
448 #ifdef __MINGW32__
449 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
450 
451 #undef SQL_INTERVAL_YEAR
452 #undef SQL_INTERVAL_MONTH
453 #undef SQL_INTERVAL_DAY
454 #undef SQL_INTERVAL_HOUR
455 #undef SQL_INTERVAL_MINUTE
456 #undef SQL_INTERVAL_SECOND
457 #undef SQL_INTERVAL_YEAR_TO_MONTH
458 #undef SQL_INTERVAL_DAY_TO_HOUR
459 #undef SQL_INTERVAL_DAY_TO_MINUTE
460 #undef SQL_INTERVAL_DAY_TO_SECOND
461 #undef SQL_INTERVAL_HOUR_TO_MINUTE
462 #undef SQL_INTERVAL_HOUR_TO_SECOND
463 #undef SQL_INTERVAL_MINUTE_TO_SECOND
464 
465 #define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
466 #define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
467 #define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
468 #define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
469 #define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
470 #define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
471 #define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
472 #define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
473 #define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
474 #define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
475 #define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
476 #define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
477 #define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
478 
479 #endif
480 #endif
481 
482 #ifdef _WIN32
483 BOOL get_login_info(HWND hwndParent, TDSLOGIN * login);
484 #endif
485 
486 #define ODBC_PARAM_LIST \
487  ODBC_PARAM(Servername) \
488  ODBC_PARAM(Server) \
489  ODBC_PARAM(DSN) \
490  ODBC_PARAM(UID) \
491  ODBC_PARAM(PWD) \
492  ODBC_PARAM(Address) \
493  ODBC_PARAM(Port) \
494  ODBC_PARAM(TDS_Version) \
495  ODBC_PARAM(Language) \
496  ODBC_PARAM(Database) \
497  ODBC_PARAM(TextSize) \
498  ODBC_PARAM(PacketSize) \
499  ODBC_PARAM(ClientCharset) \
500  ODBC_PARAM(DumpFile) \
501  ODBC_PARAM(DumpFileAppend) \
502  ODBC_PARAM(DebugFlags) \
503  ODBC_PARAM(Encryption) \
504  ODBC_PARAM(Trusted_Connection) \
505  ODBC_PARAM(APP) \
506  ODBC_PARAM(WSID) \
507  ODBC_PARAM(UseNTLMv2) \
508  ODBC_PARAM(MARS_Connection) \
509  ODBC_PARAM(REALM) \
510  ODBC_PARAM(ServerSPN) \
511  ODBC_PARAM(AttachDbFilename) \
512  ODBC_PARAM(ApplicationIntent)
513 
514 #define ODBC_PARAM(p) ODBC_PARAM_##p,
515 enum {
516  ODBC_PARAM_LIST
517  ODBC_PARAM_SIZE
518 };
519 #undef ODBC_PARAM
520 
521 
522 /*
523  * connectparams.h
524  */
525 
526 typedef struct {
527  const char *p;
528  size_t len;
530 
538 int odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
539 int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
540 #ifdef _WIN32
541 int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
542 #endif
543 
544 /*
545  * convert_tds2sql.c
546  */
547 SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
548 SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
549 
550 
551 
552 /*
553  * descriptor.c
554  */
555 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
556 SQLRETURN desc_free(TDS_DESC * desc);
557 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
558 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
559 SQLRETURN desc_free_records(TDS_DESC * desc);
560 TDS_DBC *desc_get_dbc(TDS_DESC *desc);
561 
562 /*
563  * odbc.c
564  */
565 SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
566 
567 /*
568  * odbc_checks.h
569  */
570 #if ENABLE_EXTRA_CHECKS
571 /* macro */
572 #define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
573 #define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
574 #define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
575 #define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
576 /* declarations*/
577 void odbc_check_env_extra(TDS_ENV * env);
578 void odbc_check_dbc_extra(TDS_DBC * dbc);
579 void odbc_check_stmt_extra(TDS_STMT * stmt);
580 void odbc_check_desc_extra(TDS_DESC * desc);
581 #else
582 /* macro */
583 #define CHECK_ENV_EXTRA(env)
584 #define CHECK_DBC_EXTRA(dbc)
585 #define CHECK_STMT_EXTRA(stmt)
586 #define CHECK_DESC_EXTRA(desc)
587 #endif
588 
589 /*
590  * odbc_util.h
591  */
592 
593 /* helpers for ODBC wide string support */
594 #undef _wide
595 #undef _WIDE
596 #ifdef ENABLE_ODBC_WIDE
597 typedef union {
598  char mb[1];
599  SQLWCHAR wide[1];
600 } ODBC_CHAR;
601 # define _wide ,wide
602 # define _wide0 ,0
603 # define _WIDE ,int wide
604 #else
605 # define _wide
606 # define _wide0
607 # define _WIDE
608 # define ODBC_CHAR SQLCHAR
609 #endif
610 int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
611 void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
612 void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
613 
614 void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
615 
616 int odbc_sql_to_c_type_default(int sql_type);
617 TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
618 TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
619 
620 unsigned int odbc_get_string_size(int size, const ODBC_CHAR * str _WIDE);
621 void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
622 SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
623 
624 #ifdef ENABLE_ODBC_WIDE
625 DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
626 #define odbc_dstr_copy(dbc, s, len, out) \
627  odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
628 #define odbc_dstr_copy_oct(dbc, s, len, out) \
629  odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
630 #else
631 DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
632 #define odbc_dstr_copy_oct odbc_dstr_copy
633 #endif
634 
635 
636 SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
637 #ifdef ENABLE_ODBC_WIDE
638 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
639  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))
640 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
641  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
642 #else
643 #define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
644  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
645 #define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
646  odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
647 #endif
648 
649 #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))
650 #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))
651 
652 SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
653 SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
654 SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
655 SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
656 
657 SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
658 void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
659 
660 /*
661  * prepare_query.c
662  */
663 SQLRETURN prepare_call(struct _hstmt *stmt);
664 SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
665 int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
666 int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
667 int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
668 const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
669 const char *odbc_skip_rpc_name(const char *s);
670 
671 /*
672  * sql2tds.c
673  */
674 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);
675 TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
676 
677 /*
678  * bcp.c
679  */
680 void odbc_bcp_free_storage(TDS_DBC *dbc);
681 void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
682 void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
683 void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
684 void odbc_bcp_sendrow(TDS_DBC *dbc);
685 int odbc_bcp_batch(TDS_DBC *dbc);
686 int odbc_bcp_done(TDS_DBC *dbc);
687 void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
688 
689 /*
690  * sqlwchar.c
691  */
692 #if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
693 size_t sqlwcslen(const SQLWCHAR * s);
694 
695 typedef struct sqlwstr_buf {
696  struct sqlwstr_buf *next;
697  wchar_t buf[256];
698 } SQLWSTRBUF;
699 const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
700 void sqlwstr_free(SQLWSTRBUF *bufs);
701 #define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
702 #define SQLWSTR(s) sqlwstr(s, &bufs)
703 #define SQLWSTR_FREE() sqlwstr_free(bufs)
704 #else
705 #define sqlwcslen(s) wcslen(s)
706 
707 #define SQLWSTR_BUFS(n) do {} while(0)
708 #define SQLWSTR(s) ((const wchar_t*)(s))
709 #define SQLWSTR_FREE() do {} while(0)
710 #endif
711 
712 #if SIZEOF_SQLWCHAR == 2
713 # if WORDS_BIGENDIAN
714 # define ODBC_WIDE_NAME "UCS-2BE"
715 # define ODBC_WIDE_NAME_UTF "UTF-16BE"
716 # else
717 # define ODBC_WIDE_NAME "UCS-2LE"
718 # define ODBC_WIDE_NAME_UTF "UTF-16LE"
719 # endif
720 const char *odbc_get_wide_name(TDSCONNECTION *conn);
721 #elif SIZEOF_SQLWCHAR == 4
722 # if WORDS_BIGENDIAN
723 # define ODBC_WIDE_NAME "UCS-4BE"
724 # else
725 # define ODBC_WIDE_NAME "UCS-4LE"
726 # endif
727 static inline const char *
728 odbc_get_wide_name(TDSCONNECTION *conn)
729 {
730  return ODBC_WIDE_NAME;
731 }
732 #else
733 #error SIZEOF_SQLWCHAR not supported !!
734 #endif
735 
736 #include <freetds/popvis.h>
737 
738 #ifdef __cplusplus
739 #if 0
740 {
741 #endif
742 }
743 #endif
744 
745 #endif
Definition: odbc.h:375
Holds informations about a cursor.
Definition: tds.h:932
Information for a server connection.
Definition: tds.h:1135
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:970
Definition: odbc.h:240
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:418
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:595
Definition: iconv.h:91
Definition: odbc.h:526
Definition: tds.h:508
Definition: odbc.h:198
Definition: odbc.h:100
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition: odbc.h:399
Metadata about columns in regular and compute rows.
Definition: tds.h:685
TDS_INT8 row_count
row count to return
Definition: odbc.h:416
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:972
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:1092
Definition: odbc.h:157
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition: odbc.h:290
Hold information for any results.
Definition: tds.h:764
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition: odbc_util.c:847
DSTR query
query to execute
Definition: odbc.h:382
struct _hstmt * next
next in list
Definition: odbc.h:387
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:279
Definition: tds.h:1024
unsigned int param_count
number of parameter in current query
Definition: odbc.h:413
char * prepared_pos
position in prepared query to check parameters, used only in RPC
Definition: odbc.h:408
struct _hstmt * prev
previous in list
Definition: odbc.h:389
int param_num
last valid parameter in params, it&#39;s a ODBC index (from 1 relative to descriptor) ...
Definition: odbc.h:406
struct _hstmt * current_statement
Statement executing.
Definition: odbc.h:288
Main include file for libtds.
Definition: odbc.h:303
Definition: tds.h:1063
Definition: odbc.h:231
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information...
Definition: tds.h:136
TDSSOCKET * tds
socket (only if active)
Definition: odbc.h:384
Definition: odbc.h:436
Definition: tds.h:1556
Definition: odbc.h:88
Definition: tds.h:633
TDSPARAMINFO * params
parameters saved
Definition: odbc.h:404
Definition: odbc.h:216
Definition: odbc.h:269
Definition: odbc.h:145
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:856
Structure to hold a string.
Definition: string.h:36