FreeTDS API: include/freetds/odbc.h Source File

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