NCBI C++ ToolKit
odbc.h
Go to the documentation of this file.

Go to the SVN repository for this file.

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