FreeTDS API
Loading...
Searching...
No Matches
odbc.h
1/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns
3 * Copyright (C) 2004-2010 Frediano Ziglio
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#ifndef _tdsguard_gQHaPEvp2dAAa45TAutROb_
22#define _tdsguard_gQHaPEvp2dAAa45TAutROb_
23
24#define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS
25#include <freetds/tds.h>
26#include <freetds/thread.h>
27#include <freetds/tds/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
69extern "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
92{
93 const char *msg;
94 char state2[6];
95 char state3[6];
96 TDS_UINT native;
97 char *server;
98 int linenum;
99 int msgstate;
100 int row;
101 bool msg_is_static;
102};
103
105{
106 struct _sql_error *errs;
107 int num_errors;
108 SQLRETURN lastrc;
109 char ranked;
110};
111
112typedef struct _sql_errors TDS_ERRS;
113
114#if ENABLE_EXTRA_CHECKS
115void odbc_check_struct_extra(void *p);
116#else
117static inline void odbc_check_struct_extra(void *p TDS_UNUSED) {}
118#endif
119
120#define ODBC_RETURN(handle, rc) \
121 do { odbc_check_struct_extra(handle); \
122 return handle->errs.lastrc = (rc); } while(0)
123#define ODBC_RETURN_(handle) \
124 do { odbc_check_struct_extra(handle); \
125 return handle->errs.lastrc; } while(0)
126
127#define ODBC_EXIT(handle, rc) \
128 do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
129 odbc_check_struct_extra(handle); \
130 tds_mutex_unlock(&handle->mtx); \
131 return _odbc_rc; } while(0)
132#define ODBC_EXIT_(handle) \
133 do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
134 odbc_check_struct_extra(handle); \
135 tds_mutex_unlock(&handle->mtx); \
136 return _odbc_rc; } while(0)
137
138/* utils to check handles */
139#define INIT_HANDLE(t, n) \
140 TDS_##t *n = (TDS_##t*)h##n; \
141 if (SQL_NULL_H##t == h##n || (n)->htype != SQL_HANDLE_##t) return SQL_INVALID_HANDLE; \
142 tds_mutex_lock(&n->mtx); \
143 CHECK_##t##_EXTRA(n); \
144 odbc_errs_reset(&n->errs);
145
146#define ODBC_ENTER_HSTMT INIT_HANDLE(STMT, stmt)
147#define ODBC_ENTER_HDBC INIT_HANDLE(DBC, dbc)
148#define ODBC_ENTER_HENV INIT_HANDLE(ENV, env)
149#define ODBC_ENTER_HDESC INIT_HANDLE(DESC, desc)
150
151#define IS_VALID_LEN(len) ((len) >= 0 || (len) == SQL_NTS || (len) == SQL_NULL_DATA)
152
153
155void odbc_errs_reset(struct _sql_errors *errs);
156
158void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
159
161void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
162 int msgstate, const char *server, int row);
163
166{
167 SQLSMALLINT sql_desc_alloc_type;
168 /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
169 SQLSMALLINT sql_desc_count;
170 SQLINTEGER sql_desc_bind_type;
171 SQLULEN sql_desc_array_size;
172 SQLUSMALLINT *sql_desc_array_status_ptr;
173 SQLULEN *sql_desc_rows_processed_ptr;
174 const SQLLEN *sql_desc_bind_offset_ptr;
175};
176
179{
180 DSTR sql_desc_base_column_name;
181 DSTR sql_desc_base_table_name;
182 SQLUINTEGER sql_desc_auto_unique_value;
183 SQLINTEGER sql_desc_case_sensitive;
184 DSTR sql_desc_catalog_name;
185 SQLPOINTER sql_desc_data_ptr;
186 SQLSMALLINT sql_desc_concise_type;
187 SQLSMALLINT sql_desc_datetime_interval_code;
188 SQLINTEGER sql_desc_datetime_interval_precision;
189 SQLLEN sql_desc_display_size;
190 SQLLEN *sql_desc_indicator_ptr;
191 DSTR sql_desc_label;
192 SQLULEN sql_desc_length;
193 /* this point to a constant buffer, do not free or modify */
194 const char *sql_desc_literal_prefix;
195 /* this point to a constant buffer, do not free or modify */
196 const char *sql_desc_literal_suffix;
197 DSTR sql_desc_local_type_name;
198 DSTR sql_desc_name;
199 SQLSMALLINT sql_desc_fixed_prec_scale;
200 SQLSMALLINT sql_desc_nullable;
201 SQLINTEGER sql_desc_num_prec_radix;
202 SQLLEN sql_desc_octet_length;
203 SQLLEN *sql_desc_octet_length_ptr;
204 SQLSMALLINT sql_desc_parameter_type;
205 SQLSMALLINT sql_desc_precision;
206 SQLSMALLINT sql_desc_rowver;
207 SQLSMALLINT sql_desc_scale;
208 DSTR sql_desc_schema_name;
209 DSTR sql_desc_table_name;
210 SQLSMALLINT sql_desc_searchable;
211 SQLSMALLINT sql_desc_type;
212 /* this point to a constant buffer, do not free or modify */
213 const char *sql_desc_type_name;
214 SQLSMALLINT sql_desc_unnamed;
215 SQLSMALLINT sql_desc_unsigned;
216 SQLSMALLINT sql_desc_updatable;
217};
218
219struct _hdesc
220{
221 SQLSMALLINT htype; /* do not reorder this field */
222 struct _sql_errors errs; /* do not reorder this field */
223 tds_mutex mtx;
224 int type;
231 int focus;
232 SQLHANDLE parent;
233 struct _dheader header;
234 struct _drecord *records;
235};
236
237typedef struct _hdesc TDS_DESC;
238
239#define DESC_IRD 1
240#define DESC_IPD 2
241#define DESC_ARD 3
242#define DESC_APD 4
243
245{
246 SQLUINTEGER connection_pooling;
247 SQLUINTEGER cp_match;
248 SQLINTEGER odbc_version;
249 SQLINTEGER output_nts;
250};
251
252struct _hchk
253{
254 SQLSMALLINT htype; /* do not reorder this field */
255 struct _sql_errors errs; /* do not reorder this field */
256 tds_mutex mtx;
257};
258
259struct _henv
260{
261 SQLSMALLINT htype; /* do not reorder this field */
262 struct _sql_errors errs; /* do not reorder this field */
263 tds_mutex mtx;
264 TDSCONTEXT *tds_ctx;
265 struct _heattr attr;
266};
267
269{
270 SQLUINTEGER access_mode;
271 SQLUINTEGER async_enable;
272 SQLUINTEGER auto_ipd;
273 SQLUINTEGER autocommit;
274 SQLUINTEGER connection_dead;
275 SQLUINTEGER connection_timeout;
276 DSTR current_catalog;
277 SQLUINTEGER login_timeout;
278 SQLUINTEGER metadata_id;
279 SQLUINTEGER odbc_cursors;
280 SQLUINTEGER packet_size;
281 SQLHWND quite_mode;
282 DSTR translate_lib;
283 SQLUINTEGER translate_option;
284 SQLUINTEGER txn_isolation;
285 SQLUINTEGER mars_enabled;
286 SQLUINTEGER cursor_type;
287 SQLUINTEGER bulk_enabled;
288#ifdef TDS_NO_DM
289 SQLUINTEGER trace;
290 DSTR tracefile;
291#endif
292};
293
294#define TDS_MAX_APP_DESC 100
295
296struct _hstmt;
297struct _hdbc
298{
299 SQLSMALLINT htype; /* do not reorder this field */
300 struct _sql_errors errs; /* do not reorder this field */
301 tds_mutex mtx;
302 struct _henv *env;
303 TDSSOCKET *tds_socket;
304 DSTR dsn;
305 DSTR oldpwd;
306 DSTR db_filename;
307#ifdef ENABLE_ODBC_WIDE
308 int original_charset_num;
309 TDSICONV *mb_conv;
310#endif
311
320 struct _hcattr attr;
322 TDS_DESC *uad[TDS_MAX_APP_DESC];
324 unsigned int cursor_support:1;
325 unsigned int use_oldpwd:1;
326 TDS_INT default_query_timeout;
327
328 TDSBCPINFO *bcpinfo;
329
330 /* ODBC extra options. Format strings for tds_strftime()
331 * to be applied when a client application fetches a date/time field
332 * as a character type. (Not used for the reverse direction)
333 */
334 DSTR datetime_fmt;
335 DSTR date_fmt;
336 DSTR time_fmt;
337};
338
340{
341 /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
342/* TDS_DESC *app_row_desc; */
343/* TDS_DESC *app_param_desc; */
344 SQLUINTEGER async_enable;
345 SQLUINTEGER concurrency;
346 SQLUINTEGER cursor_scrollable;
347 SQLUINTEGER cursor_sensitivity;
348 SQLUINTEGER cursor_type;
349 SQLUINTEGER enable_auto_ipd;
350 SQLPOINTER fetch_bookmark_ptr;
351 SQLULEN keyset_size;
352 SQLULEN max_length;
353 SQLULEN max_rows;
354 SQLUINTEGER metadata_id;
355 SQLUINTEGER noscan;
356 /* apd->sql_desc_bind_offset_ptr */
357 /* SQLUINTEGER *param_bind_offset_ptr; */
358 /* apd->sql_desc_bind_type */
359 /* SQLUINTEGER param_bind_type; */
360 /* apd->sql_desc_array_status_ptr */
361 /* SQLUSMALLINT *param_operation_ptr; */
362 /* ipd->sql_desc_array_status_ptr */
363 /* SQLUSMALLINT *param_status_ptr; */
364 /* ipd->sql_desc_rows_processed_ptr */
365 /* SQLUSMALLINT *params_processed_ptr; */
366 /* apd->sql_desc_array_size */
367 /* SQLUINTEGER paramset_size; */
368 SQLUINTEGER query_timeout;
369 SQLUINTEGER retrieve_data;
370 /* ard->sql_desc_bind_offset_ptr */
371 /* SQLUINTEGER *row_bind_offset_ptr; */
372 /* ard->sql_desc_array_size */
373 /* SQLUINTEGER row_array_size; */
374 /* ard->sql_desc_bind_type */
375 /* SQLUINTEGER row_bind_type; */
376 SQLULEN row_number;
377 /* ard->sql_desc_array_status_ptr */
378 /* SQLUINTEGER *row_operation_ptr; */
379 /* ird->sql_desc_array_status_ptr */
380 /* SQLUINTEGER *row_status_ptr; */
381 /* ird->sql_desc_rows_processed_ptr */
382 /* SQLUINTEGER *rows_fetched_ptr; */
383 SQLUINTEGER simulate_cursor;
384 SQLUINTEGER use_bookmarks;
385 /* SQLGetStmtAttr only */
386/* TDS_DESC *imp_row_desc; */
387/* TDS_DESC *imp_param_desc; */
388 DSTR qn_msgtext;
389 DSTR qn_options;
390 SQLUINTEGER qn_timeout;
391 SQLUINTEGER param_focus;
392};
393
394typedef enum
395{
396 NOT_IN_ROW,
397 IN_NORMAL_ROW,
398 IN_COMPUTE_ROW,
399 AFTER_COMPUTE_ROW,
400 PRE_NORMAL_ROW
401} TDS_ODBC_ROW_STATUS;
402
403typedef enum
404{
405 ODBC_SPECIAL_NONE = 0,
406 ODBC_SPECIAL_GETTYPEINFO = 1,
407 ODBC_SPECIAL_COLUMNS = 2,
408 ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
409 ODBC_SPECIAL_SPECIALCOLUMNS = 4
410} TDS_ODBC_SPECIAL_ROWS;
411
412struct _hstmt
413{
414 SQLSMALLINT htype; /* do not reorder this field */
415 struct _sql_errors errs; /* do not reorder this field */
416 tds_mutex mtx;
417 struct _hdbc *dbc;
421 TDSSOCKET *tds;
422
424 struct _hstmt *next;
426 struct _hstmt *prev;
427
428 /* begin prepared query stuff */
429 unsigned is_prepared_query:1;
430 unsigned prepared_query_is_func:1;
431 unsigned prepared_query_is_rpc:1;
436 unsigned need_reprepare:1;
437 unsigned param_data_called:1;
438 unsigned params_queried:1;
439 unsigned params_set:1;
440 /* end prepared query stuff */
441
443 TDSPARAMINFO *params;
448
449 unsigned int curr_param_row, num_param_rows;
450
452 unsigned int param_count;
453 int row;
455 TDS_INT8 row_count;
457 TDS_ODBC_ROW_STATUS row_status;
458 /* do NOT free dynamic, free from socket or attach to connection */
459 TDSDYNAMIC *dyn;
460 TDS_DESC *ard, *ird, *apd, *ipd;
461 TDS_DESC *orig_ard, *orig_apd;
462 SQLULEN sql_rowset_size;
463 struct _hsattr attr;
464 DSTR cursor_name; /* auto generated cursor name */
465 TDS_ODBC_SPECIAL_ROWS special_row;
466 /* do NOT free cursor, free from socket or attach to connection */
467 TDSCURSOR *cursor;
468};
469
470typedef struct _henv TDS_ENV;
471typedef struct _hdbc TDS_DBC;
472typedef struct _hstmt TDS_STMT;
473typedef struct _hchk TDS_CHK;
474
475typedef struct
476{
477 /* this must be the first member */
478 TDSCOLUMNFUNCS common;
479 void (*set_type_info)(TDSCOLUMN * col, struct _drecord * drec, const TDS_DBC * dbc);
480} TDS_FUNCS;
481
482#define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
483#define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
484#define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
485#define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
486
487/* fix a bug in MingW headers */
488#ifdef __MINGW32__
489#if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
490
491#undef SQL_INTERVAL_YEAR
492#undef SQL_INTERVAL_MONTH
493#undef SQL_INTERVAL_DAY
494#undef SQL_INTERVAL_HOUR
495#undef SQL_INTERVAL_MINUTE
496#undef SQL_INTERVAL_SECOND
497#undef SQL_INTERVAL_YEAR_TO_MONTH
498#undef SQL_INTERVAL_DAY_TO_HOUR
499#undef SQL_INTERVAL_DAY_TO_MINUTE
500#undef SQL_INTERVAL_DAY_TO_SECOND
501#undef SQL_INTERVAL_HOUR_TO_MINUTE
502#undef SQL_INTERVAL_HOUR_TO_SECOND
503#undef SQL_INTERVAL_MINUTE_TO_SECOND
504
505#define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
506#define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
507#define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
508#define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
509#define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
510#define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
511#define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
512#define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
513#define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
514#define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
515#define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
516#define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
517#define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
518
519#endif
520#endif
521
522#ifdef _WIN32
523bool get_login_info(HWND hwndParent, TDSLOGIN * login);
524#endif
525
526#define ODBC_PARAM_LIST \
527 ODBC_PARAM(Address) \
528 ODBC_PARAM(APP) \
529 ODBC_PARAM(ApplicationIntent) \
530 ODBC_PARAM(AttachDbFilename) \
531 ODBC_PARAM(ClientCharset) \
532 ODBC_PARAM(ConnectionTimeout) \
533 ODBC_PARAM(Database) \
534 ODBC_PARAM(DateFmt) \
535 ODBC_PARAM(DateTimeFmt) \
536 ODBC_PARAM(DebugFlags) \
537 ODBC_PARAM(DSN) \
538 ODBC_PARAM(DumpFile) \
539 ODBC_PARAM(DumpFileAppend) \
540 ODBC_PARAM(Encrypt) \
541 ODBC_PARAM(Encryption) \
542 ODBC_PARAM(HostNameInCertificate) \
543 ODBC_PARAM(Language) \
544 ODBC_PARAM(MARS_Connection) \
545 ODBC_PARAM(PacketSize) \
546 ODBC_PARAM(Port) \
547 ODBC_PARAM(PWD) \
548 ODBC_PARAM(REALM) \
549 ODBC_PARAM(Server) \
550 ODBC_PARAM(ServerCertificate) \
551 ODBC_PARAM(Servername) \
552 ODBC_PARAM(ServerSPN) \
553 ODBC_PARAM(TDS_Version) \
554 ODBC_PARAM(TextSize) \
555 ODBC_PARAM(TimeFmt) \
556 ODBC_PARAM(Timeout) \
557 ODBC_PARAM(Trusted_Connection) \
558 ODBC_PARAM(UID) \
559 ODBC_PARAM(UseNTLMv2) \
560 ODBC_PARAM(WSID)
561
562#define ODBC_PARAM(p) ODBC_PARAM_##p,
563enum {
564 ODBC_PARAM_LIST
565 ODBC_PARAM_SIZE
566};
567#undef ODBC_PARAM
568
569#define ODBC_PARAM(p) extern const char odbc_param_##p[];
570ODBC_PARAM_LIST
571#undef ODBC_PARAM
572
573/*
574 * connectparams.h
575 */
576
577typedef struct {
578 const char *p;
579 size_t len;
581
592bool odbc_parse_connect_string(TDS_ERRS * errs, const char *connect_string, const char *connect_string_end,
593 TDSLOGIN * login, TDS_DBC * dbc, TDS_PARSED_PARAM * parsed_params);
594bool odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
595#ifdef _WIN32
596int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
597#endif
598
599/*
600 * convert_tds2sql.c
601 */
602SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype,
603 TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
604SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
605
606
607
608/*
609 * descriptor.c
610 */
611typedef struct {
612 DSTR type_name;
613 TDS_DESC *apd;
614 TDS_DESC *ipd;
615} SQLTVP;
616
617TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
618SQLRETURN desc_free(TDS_DESC * desc);
619SQLRETURN desc_alloc_records(TDS_DESC * desc, SQLSMALLINT count);
620SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
621SQLRETURN desc_free_records(TDS_DESC * desc);
622TDS_DBC *desc_get_dbc(TDS_DESC *desc);
623SQLTVP *tvp_alloc(TDS_STMT *stmt);
624void tvp_free(SQLTVP *tvp);
625
626/*
627 * odbc.c
628 */
629
630SQLRETURN odbc_SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
631SQLRETURN odbc_SQLExecute(TDS_STMT * stmt);
632
633#if ENABLE_EXTRA_CHECKS
634void odbc_ird_check(TDS_STMT * stmt);
635
636#define IRD_CHECK odbc_ird_check(stmt)
637#else
638#define IRD_CHECK
639#endif
640
641/*
642 * odbc_checks.h
643 */
644#if ENABLE_EXTRA_CHECKS
645/* macro */
646#define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
647#define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
648#define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
649#define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
650/* declarations*/
651void odbc_check_env_extra(TDS_ENV * env);
652void odbc_check_dbc_extra(TDS_DBC * dbc);
653void odbc_check_stmt_extra(TDS_STMT * stmt);
654void odbc_check_desc_extra(TDS_DESC * desc);
655#else
656/* macro */
657#define CHECK_ENV_EXTRA(env)
658#define CHECK_DBC_EXTRA(dbc)
659#define CHECK_STMT_EXTRA(stmt)
660#define CHECK_DESC_EXTRA(desc)
661#endif
662
663/*
664 * odbc_util.h
665 */
666
667/* helpers for ODBC wide string support */
668#undef _wide
669#undef _WIDE
670#ifdef ENABLE_ODBC_WIDE
671typedef union {
672 char mb[1];
673 SQLWCHAR wide[1];
674} ODBC_CHAR;
675# define _wide ,wide
676# define _wide0 ,0
677# define _WIDE ,int wide
678#else
679# define _wide
680# define _wide0
681# define _WIDE
682# define ODBC_CHAR SQLCHAR
683#endif
684SQLRETURN odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, ptrdiff_t sql_len _WIDE);
685void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
686void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
687
688void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, const TDS_DBC * dbc);
689
690int odbc_sql_to_c_type_default(int sql_type);
691TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
692TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
693
694size_t odbc_get_string_size(ptrdiff_t size, const ODBC_CHAR * str _WIDE);
695void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
696SQLLEN odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd,
697 const TDS_DESC* axd, SQLSETPOSIROW n_row);
698
699#ifdef ENABLE_ODBC_WIDE
700DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str, int flag);
701#define odbc_dstr_copy(dbc, s, len, out) \
702 odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
703#define odbc_dstr_copy_oct(dbc, s, len, out) \
704 odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
705#else
706DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str);
707#define odbc_dstr_copy_oct odbc_dstr_copy
708#endif
709
710
711SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer,
712 const char *s, ptrdiff_t len, int flag);
713#ifdef ENABLE_ODBC_WIDE
714#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
715 odbc_set_string_flag(dbc, sizeof((buf)->mb) ? (buf) : (buf), buf_len, out_len, s, s_len, \
716 (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
717#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
718 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
719#else
720#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
721 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
722#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
723 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
724#endif
725
726#define odbc_set_dstr_oct(dbc, buf, buf_len, out_len, s) \
727 odbc_set_string_oct(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
728#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))
729
730SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
731SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
732SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
733SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
734
735SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
736void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
737SQLSMALLINT odbc_swap_datetime_sql_type(SQLSMALLINT sql_type, int version);
738TDSPARAMINFO *odbc_add_char_param(TDSSOCKET * tds, TDSPARAMINFO * params, const char *name, const char *value, TDS_INT len);
739TDSPARAMINFO *odbc_add_int_param(TDSSOCKET * tds, TDSPARAMINFO * params, const char *name, int value);
740
741/*
742 * info.c
743 */
744SQLRETURN odbc_SQLGetInfo(TDS_DBC * dbc, SQLUSMALLINT fInfoType, SQLPOINTER rgbInfoValue, SQLSMALLINT cbInfoValueMax,
745 SQLSMALLINT FAR * pcbInfoValue _WIDE);
746
747/*
748 * prepare_query.c
749 */
750SQLRETURN prepare_call(struct _hstmt *stmt);
751SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
752int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
753int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
754int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
755const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
756const char *odbc_skip_rpc_name(const char *s);
757
758/*
759 * sql2tds.c
760 */
761typedef union {
762 TDS_DATETIMEALL dta;
763 TDS_NUMERIC num;
765
766SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol,
767 bool compute_row, const TDS_DESC* axd, SQLSETPOSIROW n_row);
768TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
769TDS_INT convert_numeric2server(struct _sql_errors *errs, const void *src, TDS_NUMERIC *num);
770
771/*
772 * bcp.c
773 */
774void odbc_bcp_free_storage(TDS_DBC *dbc);
775void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
776void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
777void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
778void odbc_bcp_sendrow(TDS_DBC *dbc);
779int odbc_bcp_batch(TDS_DBC *dbc);
780int odbc_bcp_done(TDS_DBC *dbc);
781void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen,
782 int vartype, int table_column);
783
784/*
785 * sqlwchar.c
786 */
787#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
788size_t sqlwcslen(const SQLWCHAR * s);
789#else
790#define sqlwcslen(s) wcslen(s)
791#endif
792
793#ifdef ENABLE_ODBC_WIDE
794#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
795typedef struct sqlwstr_buf {
796 struct sqlwstr_buf *next;
797 wchar_t buf[256];
798} SQLWSTRBUF;
799const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
800void sqlwstr_free(SQLWSTRBUF *bufs);
801#define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
802#define SQLWSTR(s) sqlwstr(s, &bufs)
803#define SQLWSTR_FREE() sqlwstr_free(bufs)
804#else
805#define SQLWSTR_BUFS(n) do {} while(0)
806#define SQLWSTR(s) ((const wchar_t*)(s))
807#define SQLWSTR_FREE() do {} while(0)
808#endif
809#endif
810
811int odbc_get_wide_canonic(TDSCONNECTION *conn);
812
813/* compatibility with old BCP implementation */
814#define BCPHINTS_OLD 6
815#define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL_OLD (SQL_COPT_TDSODBC_IMPL_BASE+1)
816
817/* iODBC extensions used by our driver */
818#ifndef SQL_ATTR_DRIVER_UNICODE_TYPE
819#define SQL_ATTR_DRIVER_UNICODE_TYPE 1065
820#endif
821
822#ifndef SQL_DM_CP_UTF16
823#define SQL_DM_CP_UTF16 1
824#endif
825#ifndef SQL_DM_CP_UTF8
826#define SQL_DM_CP_UTF8 2
827#endif
828#ifndef SQL_DM_CP_UCS4
829#define SQL_DM_CP_UCS4 3
830#endif
831
832#include <freetds/popvis.h>
833
834#ifdef __cplusplus
835#if 0
836{
837#endif
838}
839#endif
840
841#endif
Main include file for libtds.
struct tds_dynamic TDSDYNAMIC
Holds information for a dynamic (also called prepared) query.
struct tds_cursor TDSCURSOR
Holds information about a cursor.
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:996
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:1123
SQLSMALLINT odbc_swap_datetime_sql_type(SQLSMALLINT sql_type, int version)
Change sql datatype to a specific version.
Definition odbc_util.c:1230
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:613
SQLLEN odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC *axd, SQLSETPOSIROW n_row)
Return length of parameter from parameter information.
Definition odbc_util.c:878
SQLRETURN odbc_set_string_flag(TDS_DBC *dbc TDS_UNUSED, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR *pcbBuffer, const char *s, ptrdiff_t len, int flag)
Copy a string to client setting size according to ODBC convenction.
Definition odbc_util.c:304
void odbc_rdbms_version(TDSSOCKET *tds_socket, char *pversion_string)
Returns the version of the RDBMS in the ODBC format.
Definition odbc_util.c:869
struct tds_dstr * DSTR
Structure to hold a string.
Definition odbc.h:92
Definition odbc.h:105
Descriptor header.
Definition odbc.h:166
Descriptor record.
Definition odbc.h:179
Definition odbc.h:220
int focus
Nested descriptor to use.
Definition odbc.h:231
Definition odbc.h:245
Definition odbc.h:253
Definition odbc.h:260
Definition odbc.h:269
Definition odbc.h:298
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition odbc.h:319
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition odbc.h:322
struct _hstmt * current_statement
Statement executing.
Definition odbc.h:317
unsigned int cursor_support
<>0 if server handle cursors
Definition odbc.h:324
Definition odbc.h:340
Definition odbc.h:413
unsigned int param_count
number of parameter in current query
Definition odbc.h:452
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:457
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition odbc.h:447
TDS_INT8 row_count
row count to return
Definition odbc.h:455
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor)
Definition odbc.h:445
DSTR query
query to execute
Definition odbc.h:419
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition odbc.h:436
struct _hstmt * next
next in list
Definition odbc.h:424
TDSSOCKET * tds
socket (only if active)
Definition odbc.h:421
struct _hstmt * prev
previous in list
Definition odbc.h:426
TDSPARAMINFO * params
parameters saved
Definition odbc.h:443
Definition odbc.h:476
Definition odbc.h:577
Definition odbc.h:611
Definition odbc.h:761
This structure is not directly connected to TDS protocol but keeps any DATE/TIME information.
Definition tds.h:146
Information for a server connection.
Definition tds.h:1193