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
153void odbc_errs_reset(struct _sql_errors *errs);
154
156void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
157
159void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
160 int msgstate, const char *server, int row);
161
164{
165 SQLSMALLINT sql_desc_alloc_type;
166 /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
167 SQLSMALLINT sql_desc_count;
168 SQLINTEGER sql_desc_bind_type;
169 SQLULEN sql_desc_array_size;
170 SQLUSMALLINT *sql_desc_array_status_ptr;
171 SQLULEN *sql_desc_rows_processed_ptr;
172 const SQLLEN *sql_desc_bind_offset_ptr;
173};
174
177{
178 DSTR sql_desc_base_column_name;
179 DSTR sql_desc_base_table_name;
180 SQLUINTEGER sql_desc_auto_unique_value;
181 SQLINTEGER sql_desc_case_sensitive;
182 DSTR sql_desc_catalog_name;
183 SQLPOINTER sql_desc_data_ptr;
184 SQLSMALLINT sql_desc_concise_type;
185 SQLSMALLINT sql_desc_datetime_interval_code;
186 SQLINTEGER sql_desc_datetime_interval_precision;
187 SQLLEN sql_desc_display_size;
188 SQLLEN *sql_desc_indicator_ptr;
189 DSTR sql_desc_label;
190 SQLULEN sql_desc_length;
191 /* this point to a constant buffer, do not free or modify */
192 const char *sql_desc_literal_prefix;
193 /* this point to a constant buffer, do not free or modify */
194 const char *sql_desc_literal_suffix;
195 DSTR sql_desc_local_type_name;
196 DSTR sql_desc_name;
197 SQLSMALLINT sql_desc_fixed_prec_scale;
198 SQLSMALLINT sql_desc_nullable;
199 SQLINTEGER sql_desc_num_prec_radix;
200 SQLLEN sql_desc_octet_length;
201 SQLLEN *sql_desc_octet_length_ptr;
202 SQLSMALLINT sql_desc_parameter_type;
203 SQLSMALLINT sql_desc_precision;
204 SQLSMALLINT sql_desc_rowver;
205 SQLSMALLINT sql_desc_scale;
206 DSTR sql_desc_schema_name;
207 DSTR sql_desc_table_name;
208 SQLSMALLINT sql_desc_searchable;
209 SQLSMALLINT sql_desc_type;
210 /* this point to a constant buffer, do not free or modify */
211 const char *sql_desc_type_name;
212 SQLSMALLINT sql_desc_unnamed;
213 SQLSMALLINT sql_desc_unsigned;
214 SQLSMALLINT sql_desc_updatable;
215};
216
217struct _hdesc
218{
219 SQLSMALLINT htype; /* do not reorder this field */
220 struct _sql_errors errs; /* do not reorder this field */
221 tds_mutex mtx;
222 int type;
229 int focus;
230 SQLHANDLE parent;
231 struct _dheader header;
232 struct _drecord *records;
233};
234
235typedef struct _hdesc TDS_DESC;
236
237#define DESC_IRD 1
238#define DESC_IPD 2
239#define DESC_ARD 3
240#define DESC_APD 4
241
243{
244 SQLUINTEGER connection_pooling;
245 SQLUINTEGER cp_match;
246 SQLINTEGER odbc_version;
247 SQLINTEGER output_nts;
248};
249
250struct _hchk
251{
252 SQLSMALLINT htype; /* do not reorder this field */
253 struct _sql_errors errs; /* do not reorder this field */
254 tds_mutex mtx;
255};
256
257struct _henv
258{
259 SQLSMALLINT htype; /* do not reorder this field */
260 struct _sql_errors errs; /* do not reorder this field */
261 tds_mutex mtx;
262 TDSCONTEXT *tds_ctx;
263 struct _heattr attr;
264};
265
267{
268 SQLUINTEGER access_mode;
269 SQLUINTEGER async_enable;
270 SQLUINTEGER auto_ipd;
271 SQLUINTEGER autocommit;
272 SQLUINTEGER connection_dead;
273 SQLUINTEGER connection_timeout;
274 DSTR current_catalog;
275 SQLUINTEGER login_timeout;
276 SQLUINTEGER metadata_id;
277 SQLUINTEGER odbc_cursors;
278 SQLUINTEGER packet_size;
279 SQLHWND quite_mode;
280 DSTR translate_lib;
281 SQLUINTEGER translate_option;
282 SQLUINTEGER txn_isolation;
283 SQLUINTEGER mars_enabled;
284 SQLUINTEGER cursor_type;
285 SQLUINTEGER bulk_enabled;
286#ifdef TDS_NO_DM
287 SQLUINTEGER trace;
288 DSTR tracefile;
289#endif
290};
291
292#define TDS_MAX_APP_DESC 100
293
294struct _hstmt;
295struct _hdbc
296{
297 SQLSMALLINT htype; /* do not reorder this field */
298 struct _sql_errors errs; /* do not reorder this field */
299 tds_mutex mtx;
300 struct _henv *env;
301 TDSSOCKET *tds_socket;
302 DSTR dsn;
303 DSTR oldpwd;
304 DSTR db_filename;
305#ifdef ENABLE_ODBC_WIDE
306 int original_charset_num;
307 TDSICONV *mb_conv;
308#endif
309
318 struct _hcattr attr;
320 TDS_DESC *uad[TDS_MAX_APP_DESC];
322 unsigned int cursor_support:1;
323 unsigned int use_oldpwd:1;
324 TDS_INT default_query_timeout;
325
326 TDSBCPINFO *bcpinfo;
327
328 /* ODBC extra options. Format strings for tds_strftime()
329 * to be applied when a client application fetches a date/time field
330 * as a character type. (Not used for the reverse direction)
331 */
332 DSTR datetime_fmt;
333 DSTR date_fmt;
334 DSTR time_fmt;
335};
336
338{
339 /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
340/* TDS_DESC *app_row_desc; */
341/* TDS_DESC *app_param_desc; */
342 SQLUINTEGER async_enable;
343 SQLUINTEGER concurrency;
344 SQLUINTEGER cursor_scrollable;
345 SQLUINTEGER cursor_sensitivity;
346 SQLUINTEGER cursor_type;
347 SQLUINTEGER enable_auto_ipd;
348 SQLPOINTER fetch_bookmark_ptr;
349 SQLULEN keyset_size;
350 SQLULEN max_length;
351 SQLULEN max_rows;
352 SQLUINTEGER metadata_id;
353 SQLUINTEGER noscan;
354 /* apd->sql_desc_bind_offset_ptr */
355 /* SQLUINTEGER *param_bind_offset_ptr; */
356 /* apd->sql_desc_bind_type */
357 /* SQLUINTEGER param_bind_type; */
358 /* apd->sql_desc_array_status_ptr */
359 /* SQLUSMALLINT *param_operation_ptr; */
360 /* ipd->sql_desc_array_status_ptr */
361 /* SQLUSMALLINT *param_status_ptr; */
362 /* ipd->sql_desc_rows_processed_ptr */
363 /* SQLUSMALLINT *params_processed_ptr; */
364 /* apd->sql_desc_array_size */
365 /* SQLUINTEGER paramset_size; */
366 SQLUINTEGER query_timeout;
367 SQLUINTEGER retrieve_data;
368 /* ard->sql_desc_bind_offset_ptr */
369 /* SQLUINTEGER *row_bind_offset_ptr; */
370 /* ard->sql_desc_array_size */
371 /* SQLUINTEGER row_array_size; */
372 /* ard->sql_desc_bind_type */
373 /* SQLUINTEGER row_bind_type; */
374 SQLULEN row_number;
375 /* ard->sql_desc_array_status_ptr */
376 /* SQLUINTEGER *row_operation_ptr; */
377 /* ird->sql_desc_array_status_ptr */
378 /* SQLUINTEGER *row_status_ptr; */
379 /* ird->sql_desc_rows_processed_ptr */
380 /* SQLUINTEGER *rows_fetched_ptr; */
381 SQLUINTEGER simulate_cursor;
382 SQLUINTEGER use_bookmarks;
383 /* SQLGetStmtAttr only */
384/* TDS_DESC *imp_row_desc; */
385/* TDS_DESC *imp_param_desc; */
386 DSTR qn_msgtext;
387 DSTR qn_options;
388 SQLUINTEGER qn_timeout;
389 SQLUINTEGER param_focus;
390};
391
392typedef enum
393{
394 NOT_IN_ROW,
395 IN_NORMAL_ROW,
396 IN_COMPUTE_ROW,
397 AFTER_COMPUTE_ROW,
398 PRE_NORMAL_ROW
399} TDS_ODBC_ROW_STATUS;
400
401typedef enum
402{
403 ODBC_SPECIAL_NONE = 0,
404 ODBC_SPECIAL_GETTYPEINFO = 1,
405 ODBC_SPECIAL_COLUMNS = 2,
406 ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
407 ODBC_SPECIAL_SPECIALCOLUMNS = 4
408} TDS_ODBC_SPECIAL_ROWS;
409
410struct _hstmt
411{
412 SQLSMALLINT htype; /* do not reorder this field */
413 struct _sql_errors errs; /* do not reorder this field */
414 tds_mutex mtx;
415 struct _hdbc *dbc;
419 TDSSOCKET *tds;
420
422 struct _hstmt *next;
424 struct _hstmt *prev;
425
426 /* begin prepared query stuff */
427 unsigned is_prepared_query:1;
428 unsigned prepared_query_is_func:1;
429 unsigned prepared_query_is_rpc:1;
434 unsigned need_reprepare:1;
435 unsigned param_data_called:1;
436 unsigned params_queried:1;
437 unsigned params_set:1;
438 /* end prepared query stuff */
439
441 TDSPARAMINFO *params;
446
447 unsigned int curr_param_row, num_param_rows;
448
450 unsigned int param_count;
451 int row;
453 TDS_INT8 row_count;
455 TDS_ODBC_ROW_STATUS row_status;
456 /* do NOT free dynamic, free from socket or attach to connection */
457 TDSDYNAMIC *dyn;
458 TDS_DESC *ard, *ird, *apd, *ipd;
459 TDS_DESC *orig_ard, *orig_apd;
460 SQLULEN sql_rowset_size;
461 struct _hsattr attr;
462 DSTR cursor_name; /* auto generated cursor name */
463 TDS_ODBC_SPECIAL_ROWS special_row;
464 /* do NOT free cursor, free from socket or attach to connection */
465 TDSCURSOR *cursor;
466};
467
468typedef struct _henv TDS_ENV;
469typedef struct _hdbc TDS_DBC;
470typedef struct _hstmt TDS_STMT;
471typedef struct _hchk TDS_CHK;
472
473typedef struct
474{
475 /* this must be the first member */
476 TDSCOLUMNFUNCS common;
477 void (*set_type_info)(TDSCOLUMN * col, struct _drecord * drec, const TDS_DBC * dbc);
478} TDS_FUNCS;
479
480#define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
481#define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
482#define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
483#define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
484
485/* fix a bug in MingW headers */
486#ifdef __MINGW32__
487#if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
488
489#undef SQL_INTERVAL_YEAR
490#undef SQL_INTERVAL_MONTH
491#undef SQL_INTERVAL_DAY
492#undef SQL_INTERVAL_HOUR
493#undef SQL_INTERVAL_MINUTE
494#undef SQL_INTERVAL_SECOND
495#undef SQL_INTERVAL_YEAR_TO_MONTH
496#undef SQL_INTERVAL_DAY_TO_HOUR
497#undef SQL_INTERVAL_DAY_TO_MINUTE
498#undef SQL_INTERVAL_DAY_TO_SECOND
499#undef SQL_INTERVAL_HOUR_TO_MINUTE
500#undef SQL_INTERVAL_HOUR_TO_SECOND
501#undef SQL_INTERVAL_MINUTE_TO_SECOND
502
503#define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
504#define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
505#define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
506#define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
507#define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
508#define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
509#define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
510#define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
511#define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
512#define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
513#define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
514#define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
515#define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
516
517#endif
518#endif
519
520#ifdef _WIN32
521bool get_login_info(HWND hwndParent, TDSLOGIN * login);
522#endif
523
524#define ODBC_PARAM_LIST \
525 ODBC_PARAM(Address) \
526 ODBC_PARAM(APP) \
527 ODBC_PARAM(ApplicationIntent) \
528 ODBC_PARAM(AttachDbFilename) \
529 ODBC_PARAM(ClientCharset) \
530 ODBC_PARAM(ConnectionTimeout) \
531 ODBC_PARAM(Database) \
532 ODBC_PARAM(DateFmt) \
533 ODBC_PARAM(DateTimeFmt) \
534 ODBC_PARAM(DebugFlags) \
535 ODBC_PARAM(DSN) \
536 ODBC_PARAM(DumpFile) \
537 ODBC_PARAM(DumpFileAppend) \
538 ODBC_PARAM(Encrypt) \
539 ODBC_PARAM(Encryption) \
540 ODBC_PARAM(HostNameInCertificate) \
541 ODBC_PARAM(Language) \
542 ODBC_PARAM(MARS_Connection) \
543 ODBC_PARAM(PacketSize) \
544 ODBC_PARAM(Port) \
545 ODBC_PARAM(PWD) \
546 ODBC_PARAM(REALM) \
547 ODBC_PARAM(Server) \
548 ODBC_PARAM(ServerCertificate) \
549 ODBC_PARAM(Servername) \
550 ODBC_PARAM(ServerSPN) \
551 ODBC_PARAM(TDS_Version) \
552 ODBC_PARAM(TextSize) \
553 ODBC_PARAM(TimeFmt) \
554 ODBC_PARAM(Timeout) \
555 ODBC_PARAM(Trusted_Connection) \
556 ODBC_PARAM(UID) \
557 ODBC_PARAM(UseNTLMv2) \
558 ODBC_PARAM(WSID)
559
560#define ODBC_PARAM(p) ODBC_PARAM_##p,
561enum {
562 ODBC_PARAM_LIST
563 ODBC_PARAM_SIZE
564};
565#undef ODBC_PARAM
566
567#define ODBC_PARAM(p) extern const char odbc_param_##p[];
568ODBC_PARAM_LIST
569#undef ODBC_PARAM
570
571/*
572 * connectparams.h
573 */
574
575typedef struct {
576 const char *p;
577 size_t len;
579
590bool odbc_parse_connect_string(TDS_ERRS * errs, const char *connect_string, const char *connect_string_end,
591 TDSLOGIN * login, TDS_DBC * dbc, TDS_PARSED_PARAM * parsed_params);
592bool odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
593#ifdef _WIN32
594int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
595#endif
596
597/*
598 * convert_tds2sql.c
599 */
600SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype,
601 TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
602SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
603
604
605
606/*
607 * descriptor.c
608 */
609typedef struct {
610 DSTR type_name;
611 TDS_DESC *apd;
612 TDS_DESC *ipd;
613} SQLTVP;
614
615TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
616SQLRETURN desc_free(TDS_DESC * desc);
617SQLRETURN desc_alloc_records(TDS_DESC * desc, SQLSMALLINT count);
618SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
619SQLRETURN desc_free_records(TDS_DESC * desc);
620TDS_DBC *desc_get_dbc(TDS_DESC *desc);
621SQLTVP *tvp_alloc(TDS_STMT *stmt);
622void tvp_free(SQLTVP *tvp);
623
624/*
625 * odbc.c
626 */
627
628SQLRETURN odbc_SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
629
630/*
631 * odbc_checks.h
632 */
633#if ENABLE_EXTRA_CHECKS
634/* macro */
635#define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
636#define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
637#define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
638#define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
639/* declarations*/
640void odbc_check_env_extra(TDS_ENV * env);
641void odbc_check_dbc_extra(TDS_DBC * dbc);
642void odbc_check_stmt_extra(TDS_STMT * stmt);
643void odbc_check_desc_extra(TDS_DESC * desc);
644#else
645/* macro */
646#define CHECK_ENV_EXTRA(env)
647#define CHECK_DBC_EXTRA(dbc)
648#define CHECK_STMT_EXTRA(stmt)
649#define CHECK_DESC_EXTRA(desc)
650#endif
651
652/*
653 * odbc_util.h
654 */
655
656/* helpers for ODBC wide string support */
657#undef _wide
658#undef _WIDE
659#ifdef ENABLE_ODBC_WIDE
660typedef union {
661 char mb[1];
662 SQLWCHAR wide[1];
663} ODBC_CHAR;
664# define _wide ,wide
665# define _wide0 ,0
666# define _WIDE ,int wide
667#else
668# define _wide
669# define _wide0
670# define _WIDE
671# define ODBC_CHAR SQLCHAR
672#endif
673SQLRETURN odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, ptrdiff_t sql_len _WIDE);
674void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
675void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
676
677void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, const TDS_DBC * dbc);
678
679int odbc_sql_to_c_type_default(int sql_type);
680TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
681TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
682
683size_t odbc_get_string_size(ptrdiff_t size, const ODBC_CHAR * str _WIDE);
684void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
685SQLLEN odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd,
686 const TDS_DESC* axd, SQLSETPOSIROW n_row);
687
688#ifdef ENABLE_ODBC_WIDE
689DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str, int flag);
690#define odbc_dstr_copy(dbc, s, len, out) \
691 odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
692#define odbc_dstr_copy_oct(dbc, s, len, out) \
693 odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
694#else
695DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, ptrdiff_t size, const ODBC_CHAR * str);
696#define odbc_dstr_copy_oct odbc_dstr_copy
697#endif
698
699
700SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer,
701 const char *s, ptrdiff_t len, int flag);
702#ifdef ENABLE_ODBC_WIDE
703#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
704 odbc_set_string_flag(dbc, sizeof((buf)->mb) ? (buf) : (buf), buf_len, out_len, s, s_len, \
705 (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
706#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
707 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
708#else
709#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
710 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
711#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
712 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
713#endif
714
715#define odbc_set_dstr_oct(dbc, buf, buf_len, out_len, s) \
716 odbc_set_string_oct(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
717#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))
718
719SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
720SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
721SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
722SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
723
724SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
725void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
726
727/*
728 * info.c
729 */
730SQLRETURN odbc_SQLGetInfo(TDS_DBC * dbc, SQLUSMALLINT fInfoType, SQLPOINTER rgbInfoValue, SQLSMALLINT cbInfoValueMax,
731 SQLSMALLINT FAR * pcbInfoValue _WIDE);
732
733/*
734 * prepare_query.c
735 */
736SQLRETURN prepare_call(struct _hstmt *stmt);
737SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
738int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
739int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
740int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
741const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
742const char *odbc_skip_rpc_name(const char *s);
743
744/*
745 * sql2tds.c
746 */
747typedef union {
748 TDS_DATETIMEALL dta;
749 TDS_NUMERIC num;
751
752SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol,
753 bool compute_row, const TDS_DESC* axd, SQLSETPOSIROW n_row);
754TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
755TDS_INT convert_numeric2server(struct _sql_errors *errs, const void *src, TDS_NUMERIC *num);
756
757/*
758 * bcp.c
759 */
760void odbc_bcp_free_storage(TDS_DBC *dbc);
761void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
762void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
763void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
764void odbc_bcp_sendrow(TDS_DBC *dbc);
765int odbc_bcp_batch(TDS_DBC *dbc);
766int odbc_bcp_done(TDS_DBC *dbc);
767void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen,
768 int vartype, int table_column);
769
770/*
771 * sqlwchar.c
772 */
773#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
774size_t sqlwcslen(const SQLWCHAR * s);
775#else
776#define sqlwcslen(s) wcslen(s)
777#endif
778
779#ifdef ENABLE_ODBC_WIDE
780#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
781typedef struct sqlwstr_buf {
782 struct sqlwstr_buf *next;
783 wchar_t buf[256];
784} SQLWSTRBUF;
785const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
786void sqlwstr_free(SQLWSTRBUF *bufs);
787#define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
788#define SQLWSTR(s) sqlwstr(s, &bufs)
789#define SQLWSTR_FREE() sqlwstr_free(bufs)
790#else
791#define SQLWSTR_BUFS(n) do {} while(0)
792#define SQLWSTR(s) ((const wchar_t*)(s))
793#define SQLWSTR_FREE() do {} while(0)
794#endif
795#endif
796
797int odbc_get_wide_canonic(TDSCONNECTION *conn);
798
799/* compatibility with old BCP implementation */
800#define BCPHINTS_OLD 6
801#define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL_OLD (SQL_COPT_TDSODBC_IMPL_BASE+1)
802
803/* iODBC extensions used by our driver */
804#ifndef SQL_ATTR_DRIVER_UNICODE_TYPE
805#define SQL_ATTR_DRIVER_UNICODE_TYPE 1065
806#endif
807
808#ifndef SQL_DM_CP_UTF16
809#define SQL_DM_CP_UTF16 1
810#endif
811#ifndef SQL_DM_CP_UTF8
812#define SQL_DM_CP_UTF8 2
813#endif
814#ifndef SQL_DM_CP_UCS4
815#define SQL_DM_CP_UCS4 3
816#endif
817
818#include <freetds/popvis.h>
819
820#ifdef __cplusplus
821#if 0
822{
823#endif
824}
825#endif
826
827#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
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:164
Descriptor record.
Definition odbc.h:177
Definition odbc.h:218
int focus
Nested descriptor to use.
Definition odbc.h:229
Definition odbc.h:243
Definition odbc.h:251
Definition odbc.h:258
Definition odbc.h:267
Definition odbc.h:296
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition odbc.h:317
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition odbc.h:320
struct _hstmt * current_statement
Statement executing.
Definition odbc.h:315
unsigned int cursor_support
<>0 if server handle cursors
Definition odbc.h:322
Definition odbc.h:338
Definition odbc.h:411
unsigned int param_count
number of parameter in current query
Definition odbc.h:450
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:455
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition odbc.h:445
TDS_INT8 row_count
row count to return
Definition odbc.h:453
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor)
Definition odbc.h:443
DSTR query
query to execute
Definition odbc.h:417
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition odbc.h:434
struct _hstmt * next
next in list
Definition odbc.h:422
TDSSOCKET * tds
socket (only if active)
Definition odbc.h:419
struct _hstmt * prev
previous in list
Definition odbc.h:424
TDSPARAMINFO * params
parameters saved
Definition odbc.h:441
Definition odbc.h:474
Definition odbc.h:575
Definition odbc.h:609
Definition odbc.h:747
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:1190