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