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 _sql_h_
22#define _sql_h_
23
24#define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS
25#include <freetds/tds.h>
26#include <freetds/thread.h>
27#include <freetds/data.h>
28
29#if defined(UNIXODBC) || defined(_WIN32) || defined(TDS_NO_DM)
30#include <sql.h>
31#include <sqlext.h>
32#if defined(UNIXODBC) || defined(_WIN32)
33#include <odbcinst.h>
34#endif
35#else /* IODBC */
36#include <isql.h>
37#include <isqlext.h>
38#ifdef HAVE_IODBCINST_H
39#include <iodbcinst.h>
40#endif /* HAVE_IODBCINST_H */
41#endif
42
43#ifdef HAVE_WCHAR_H
44#include <wchar.h>
45#endif
46
47#ifndef HAVE_SQLLEN
48#ifndef SQLULEN
49#define SQLULEN SQLUINTEGER
50#endif
51#ifndef SQLLEN
52#define SQLLEN SQLINTEGER
53#endif
54#endif
55
56#ifndef HAVE_SQLSETPOSIROW
57#define SQLSETPOSIROW SQLUSMALLINT
58#endif
59
60#ifndef HAVE_SQLROWOFFSET
61#define SQLROWOFFSET SQLLEN
62#endif
63
64#ifndef HAVE_SQLROWSETSIZE
65#define SQLROWSETSIZE SQLULEN
66#endif
67
68#ifdef __cplusplus
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};
104
106{
107 struct _sql_error *errs;
108 int num_errors;
109 SQLRETURN lastrc;
110 char ranked;
111};
112
113typedef struct _sql_errors TDS_ERRS;
114
115#if ENABLE_EXTRA_CHECKS
116void odbc_check_struct_extra(void *p);
117#else
118static inline void odbc_check_struct_extra(void *p) {}
119#endif
120
121#define ODBC_RETURN(handle, rc) \
122 do { odbc_check_struct_extra(handle); \
123 return handle->errs.lastrc = (rc); } while(0)
124#define ODBC_RETURN_(handle) \
125 do { odbc_check_struct_extra(handle); \
126 return handle->errs.lastrc; } while(0)
127
128#define ODBC_EXIT(handle, rc) \
129 do { SQLRETURN _odbc_rc = handle->errs.lastrc = (rc); \
130 odbc_check_struct_extra(handle); \
131 tds_mutex_unlock(&handle->mtx); \
132 return _odbc_rc; } while(0)
133#define ODBC_EXIT_(handle) \
134 do { SQLRETURN _odbc_rc = handle->errs.lastrc; \
135 odbc_check_struct_extra(handle); \
136 tds_mutex_unlock(&handle->mtx); \
137 return _odbc_rc; } while(0)
138
139
141void odbc_errs_reset(struct _sql_errors *errs);
142
144void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg);
145
147void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
148 int msgstate, const char *server, int row);
149
152{
153 SQLSMALLINT sql_desc_alloc_type;
154 /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
155 SQLSMALLINT sql_desc_count;
156 SQLINTEGER sql_desc_bind_type;
157 SQLULEN sql_desc_array_size;
158 SQLUSMALLINT *sql_desc_array_status_ptr;
159 SQLULEN *sql_desc_rows_processed_ptr;
160 SQLLEN *sql_desc_bind_offset_ptr;
161};
162
165{
166 DSTR sql_desc_base_column_name;
167 DSTR sql_desc_base_table_name;
168 SQLUINTEGER sql_desc_auto_unique_value;
169 SQLINTEGER sql_desc_case_sensitive;
170 DSTR sql_desc_catalog_name;
171 SQLPOINTER sql_desc_data_ptr;
172 SQLSMALLINT sql_desc_concise_type;
173 SQLSMALLINT sql_desc_datetime_interval_code;
174 SQLINTEGER sql_desc_datetime_interval_precision;
175 SQLLEN sql_desc_display_size;
176 SQLLEN *sql_desc_indicator_ptr;
177 DSTR sql_desc_label;
178 SQLULEN sql_desc_length;
179 /* this point to a constant buffer, do not free or modify */
180 const char *sql_desc_literal_prefix;
181 /* this point to a constant buffer, do not free or modify */
182 const char *sql_desc_literal_suffix;
183 DSTR sql_desc_local_type_name;
184 DSTR sql_desc_name;
185 SQLSMALLINT sql_desc_fixed_prec_scale;
186 SQLSMALLINT sql_desc_nullable;
187 SQLINTEGER sql_desc_num_prec_radix;
188 SQLLEN sql_desc_octet_length;
189 SQLLEN *sql_desc_octet_length_ptr;
190 SQLSMALLINT sql_desc_parameter_type;
191 SQLSMALLINT sql_desc_precision;
192 SQLSMALLINT sql_desc_rowver;
193 SQLSMALLINT sql_desc_scale;
194 DSTR sql_desc_schema_name;
195 DSTR sql_desc_table_name;
196 SQLSMALLINT sql_desc_searchable;
197 SQLSMALLINT sql_desc_type;
198 /* this point to a constant buffer, do not free or modify */
199 const char *sql_desc_type_name;
200 SQLSMALLINT sql_desc_unnamed;
201 SQLSMALLINT sql_desc_unsigned;
202 SQLSMALLINT sql_desc_updatable;
203};
204
205struct _hdesc
206{
207 SQLSMALLINT htype; /* do not reorder this field */
208 struct _sql_errors errs; /* do not reorder this field */
209 tds_mutex mtx;
210 int type;
211 SQLHANDLE parent;
212 struct _dheader header;
213 struct _drecord *records;
214};
215
216typedef struct _hdesc TDS_DESC;
217
218#define DESC_IRD 1
219#define DESC_IPD 2
220#define DESC_ARD 3
221#define DESC_APD 4
222
224{
225 SQLUINTEGER connection_pooling;
226 SQLUINTEGER cp_match;
227 SQLINTEGER odbc_version;
228 SQLINTEGER output_nts;
229};
230
231struct _hchk
232{
233 SQLSMALLINT htype; /* do not reorder this field */
234 struct _sql_errors errs; /* do not reorder this field */
235 tds_mutex mtx;
236};
237
238struct _henv
239{
240 SQLSMALLINT htype; /* do not reorder this field */
241 struct _sql_errors errs; /* do not reorder this field */
242 tds_mutex mtx;
243 TDSCONTEXT *tds_ctx;
244 struct _heattr attr;
245};
246
248{
249 SQLUINTEGER access_mode;
250 SQLUINTEGER async_enable;
251 SQLUINTEGER auto_ipd;
252 SQLUINTEGER autocommit;
253 SQLUINTEGER connection_dead;
254 SQLUINTEGER connection_timeout;
255 DSTR current_catalog;
256 SQLUINTEGER login_timeout;
257 SQLUINTEGER metadata_id;
258 SQLUINTEGER odbc_cursors;
259 SQLUINTEGER packet_size;
260 SQLHWND quite_mode;
261 DSTR translate_lib;
262 SQLUINTEGER translate_option;
263 SQLUINTEGER txn_isolation;
264 SQLUINTEGER mars_enabled;
265 SQLUINTEGER cursor_type;
266 SQLUINTEGER bulk_enabled;
267#ifdef TDS_NO_DM
268 SQLUINTEGER trace;
269 DSTR tracefile;
270#endif
271};
272
273#define TDS_MAX_APP_DESC 100
274
275struct _hstmt;
276struct _hdbc
277{
278 SQLSMALLINT htype; /* do not reorder this field */
279 struct _sql_errors errs; /* do not reorder this field */
280 tds_mutex mtx;
281 struct _henv *env;
283 DSTR dsn;
284 DSTR oldpwd;
285#ifdef ENABLE_ODBC_WIDE
286 int original_charset_num;
287 TDSICONV *mb_conv;
288#endif
289
298 struct _hcattr attr;
300 TDS_DESC *uad[TDS_MAX_APP_DESC];
302 unsigned int cursor_support:1;
303 unsigned int use_oldpwd:1;
304 TDS_INT default_query_timeout;
305
306 TDSBCPINFO *bcpinfo;
307 char *bcphint;
308};
309
311{
312 /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
313/* TDS_DESC *app_row_desc; */
314/* TDS_DESC *app_param_desc; */
315 SQLUINTEGER async_enable;
316 SQLUINTEGER concurrency;
317 SQLUINTEGER cursor_scrollable;
318 SQLUINTEGER cursor_sensitivity;
319 SQLUINTEGER cursor_type;
320 SQLUINTEGER enable_auto_ipd;
321 SQLPOINTER fetch_bookmark_ptr;
322 SQLULEN keyset_size;
323 SQLULEN max_length;
324 SQLULEN max_rows;
325 SQLUINTEGER metadata_id;
326 SQLUINTEGER noscan;
327 /* apd->sql_desc_bind_offset_ptr */
328 /* SQLUINTEGER *param_bind_offset_ptr; */
329 /* apd->sql_desc_bind_type */
330 /* SQLUINTEGER param_bind_type; */
331 /* apd->sql_desc_array_status_ptr */
332 /* SQLUSMALLINT *param_operation_ptr; */
333 /* ipd->sql_desc_array_status_ptr */
334 /* SQLUSMALLINT *param_status_ptr; */
335 /* ipd->sql_desc_rows_processed_ptr */
336 /* SQLUSMALLINT *params_processed_ptr; */
337 /* apd->sql_desc_array_size */
338 /* SQLUINTEGER paramset_size; */
339 SQLUINTEGER query_timeout;
340 SQLUINTEGER retrieve_data;
341 /* ard->sql_desc_bind_offset_ptr */
342 /* SQLUINTEGER *row_bind_offset_ptr; */
343 /* ard->sql_desc_array_size */
344 /* SQLUINTEGER row_array_size; */
345 /* ard->sql_desc_bind_type */
346 /* SQLUINTEGER row_bind_type; */
347 SQLULEN row_number;
348 /* ard->sql_desc_array_status_ptr */
349 /* SQLUINTEGER *row_operation_ptr; */
350 /* ird->sql_desc_array_status_ptr */
351 /* SQLUINTEGER *row_status_ptr; */
352 /* ird->sql_desc_rows_processed_ptr */
353 /* SQLUINTEGER *rows_fetched_ptr; */
354 SQLUINTEGER simulate_cursor;
355 SQLUINTEGER use_bookmarks;
356 /* SQLGetStmtAttr only */
357/* TDS_DESC *imp_row_desc; */
358/* TDS_DESC *imp_param_desc; */
359 DSTR qn_msgtext;
360 DSTR qn_options;
361 SQLUINTEGER qn_timeout;
362 SQLUINTEGER param_focus;
363};
364
365typedef enum
366{
367 NOT_IN_ROW,
368 IN_NORMAL_ROW,
369 IN_COMPUTE_ROW,
370 AFTER_COMPUTE_ROW,
371 PRE_NORMAL_ROW
372} TDS_ODBC_ROW_STATUS;
373
374typedef enum
375{
376 ODBC_SPECIAL_NONE = 0,
377 ODBC_SPECIAL_GETTYPEINFO = 1,
378 ODBC_SPECIAL_COLUMNS = 2,
379 ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
380 ODBC_SPECIAL_SPECIALCOLUMNS = 4
381} TDS_ODBC_SPECIAL_ROWS;
382
383struct _hstmt
384{
385 SQLSMALLINT htype; /* do not reorder this field */
386 struct _sql_errors errs; /* do not reorder this field */
387 tds_mutex mtx;
388 struct _hdbc *dbc;
393
395 struct _hstmt *next;
397 struct _hstmt *prev;
398
399 /* begin prepared query stuff */
400 unsigned is_prepared_query:1;
401 unsigned prepared_query_is_func:1;
402 unsigned prepared_query_is_rpc:1;
407 unsigned need_reprepare:1;
408 unsigned param_data_called:1;
409 /* end prepared query stuff */
410
417
418 unsigned int curr_param_row, num_param_rows;
419
421 unsigned int param_count;
422 int row;
424 TDS_INT8 row_count;
426 TDS_ODBC_ROW_STATUS row_status;
427 /* do NOT free dynamic, free from socket or attach to connection */
428 TDSDYNAMIC *dyn;
429 TDS_DESC *ard, *ird, *apd, *ipd;
430 TDS_DESC *orig_ard, *orig_apd;
431 SQLULEN sql_rowset_size;
432 struct _hsattr attr;
433 DSTR cursor_name; /* auto generated cursor name */
434 TDS_ODBC_SPECIAL_ROWS special_row;
435 /* do NOT free cursor, free from socket or attach to connection */
436 TDSCURSOR *cursor;
437};
438
439typedef struct _henv TDS_ENV;
440typedef struct _hdbc TDS_DBC;
441typedef struct _hstmt TDS_STMT;
442typedef struct _hchk TDS_CHK;
443
444typedef struct {
445 /* this must be the first member */
446 TDSCOLUMNFUNCS common;
447 void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
448} TDS_FUNCS;
449
450#define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
451#define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
452#define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
453#define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
454
455/* fix a bug in MingW headers */
456#ifdef __MINGW32__
457#if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
458
459#undef SQL_INTERVAL_YEAR
460#undef SQL_INTERVAL_MONTH
461#undef SQL_INTERVAL_DAY
462#undef SQL_INTERVAL_HOUR
463#undef SQL_INTERVAL_MINUTE
464#undef SQL_INTERVAL_SECOND
465#undef SQL_INTERVAL_YEAR_TO_MONTH
466#undef SQL_INTERVAL_DAY_TO_HOUR
467#undef SQL_INTERVAL_DAY_TO_MINUTE
468#undef SQL_INTERVAL_DAY_TO_SECOND
469#undef SQL_INTERVAL_HOUR_TO_MINUTE
470#undef SQL_INTERVAL_HOUR_TO_SECOND
471#undef SQL_INTERVAL_MINUTE_TO_SECOND
472
473#define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
474#define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
475#define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
476#define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
477#define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
478#define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
479#define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
480#define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
481#define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
482#define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
483#define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
484#define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
485#define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
486
487#endif
488#endif
489
490#ifdef _WIN32
491bool get_login_info(HWND hwndParent, TDSLOGIN * login);
492#endif
493
494#define ODBC_PARAM_LIST \
495 ODBC_PARAM(Servername) \
496 ODBC_PARAM(Server) \
497 ODBC_PARAM(DSN) \
498 ODBC_PARAM(UID) \
499 ODBC_PARAM(PWD) \
500 ODBC_PARAM(Address) \
501 ODBC_PARAM(Port) \
502 ODBC_PARAM(TDS_Version) \
503 ODBC_PARAM(Language) \
504 ODBC_PARAM(Database) \
505 ODBC_PARAM(TextSize) \
506 ODBC_PARAM(PacketSize) \
507 ODBC_PARAM(ClientCharset) \
508 ODBC_PARAM(DumpFile) \
509 ODBC_PARAM(DumpFileAppend) \
510 ODBC_PARAM(DebugFlags) \
511 ODBC_PARAM(Encryption) \
512 ODBC_PARAM(Trusted_Connection) \
513 ODBC_PARAM(APP) \
514 ODBC_PARAM(WSID) \
515 ODBC_PARAM(UseNTLMv2) \
516 ODBC_PARAM(MARS_Connection) \
517 ODBC_PARAM(REALM) \
518 ODBC_PARAM(ServerSPN) \
519 ODBC_PARAM(AttachDbFilename) \
520 ODBC_PARAM(ApplicationIntent) \
521 ODBC_PARAM(Timeout)
522
523#define ODBC_PARAM(p) ODBC_PARAM_##p,
524enum {
525 ODBC_PARAM_LIST
526 ODBC_PARAM_SIZE
527};
528#undef ODBC_PARAM
529
530
531/*
532 * connectparams.h
533 */
534
535typedef struct {
536 const char *p;
537 size_t len;
539
547bool odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
548int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
549#ifdef _WIN32
550int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
551#endif
552
553/*
554 * convert_tds2sql.c
555 */
556SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
557SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
558
559
560
561/*
562 * descriptor.c
563 */
564TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
565SQLRETURN desc_free(TDS_DESC * desc);
566SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
567SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
568SQLRETURN desc_free_records(TDS_DESC * desc);
569TDS_DBC *desc_get_dbc(TDS_DESC *desc);
570
571/*
572 * odbc.c
573 */
574/* Temporarily store the bound TVP columns */
575/* Follow the naming in _SQLBindParameter for convenience */
576typedef struct {
577 SQLSMALLINT fParamType; /* InputOutputParam */
578 SQLSMALLINT fCType; /* C data type */
579 SQLSMALLINT fSqlType; /* SQL data type */
580 SQLULEN cbColDef; /* columnsize */
581 SQLSMALLINT ibScale; /* precision */
582 SQLPOINTER rgbValue; /* content buffer */
583 SQLLEN cbValueMax; /* buffer length */
584 SQLLEN *pcbValue; /* content length buffer */
586
587typedef struct {
588 DSTR type_name;
589 int num_cols;
590 SQLTVPCOLUMN **columns;
591} SQLTVP;
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, const TDS_DESC* axd, unsigned int n_row);
651
652#ifdef ENABLE_ODBC_WIDE
653DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
654#define odbc_dstr_copy(dbc, s, len, out) \
655 odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
656#define odbc_dstr_copy_oct(dbc, s, len, out) \
657 odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
658#else
659DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
660#define odbc_dstr_copy_oct odbc_dstr_copy
661#endif
662
663
664SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
665#ifdef ENABLE_ODBC_WIDE
666#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
667 odbc_set_string_flag(dbc, sizeof((buf)->mb) ? (buf) : (buf), buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
668#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
669 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
670#else
671#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
672 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
673#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
674 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
675#endif
676
677#define odbc_set_dstr_oct(dbc, buf, buf_len, out_len, s) odbc_set_string_oct(dbc, buf, buf_len, out_len, tds_dstr_cstr(s), tds_dstr_len(s))
678#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))
679
680SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
681SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
682SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
683SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
684
685SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
686void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
687
688/*
689 * prepare_query.c
690 */
691SQLRETURN prepare_call(struct _hstmt *stmt);
692SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
693int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
694int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
695int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
696const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
697const char *odbc_skip_rpc_name(const char *s);
698
699/*
700 * sql2tds.c
701 */
702SQLRETURN odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _drecord *drec_axd, TDSCOLUMN *curcol, bool compute_row, const TDS_DESC* axd, unsigned int n_row);
703TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
704
705/*
706 * bcp.c
707 */
708void odbc_bcp_free_storage(TDS_DBC *dbc);
709void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
710void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
711void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
712void odbc_bcp_sendrow(TDS_DBC *dbc);
713int odbc_bcp_batch(TDS_DBC *dbc);
714int odbc_bcp_done(TDS_DBC *dbc);
715void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
716
717/*
718 * sqlwchar.c
719 */
720#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
721size_t sqlwcslen(const SQLWCHAR * s);
722
723typedef struct sqlwstr_buf {
724 struct sqlwstr_buf *next;
725 wchar_t buf[256];
726} SQLWSTRBUF;
727const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
728void sqlwstr_free(SQLWSTRBUF *bufs);
729#define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
730#define SQLWSTR(s) sqlwstr(s, &bufs)
731#define SQLWSTR_FREE() sqlwstr_free(bufs)
732#else
733#define sqlwcslen(s) wcslen(s)
734
735#define SQLWSTR_BUFS(n) do {} while(0)
736#define SQLWSTR(s) ((const wchar_t*)(s))
737#define SQLWSTR_FREE() do {} while(0)
738#endif
739
740int odbc_get_wide_canonic(TDSCONNECTION *conn);
741
742#include <freetds/popvis.h>
743
744#ifdef __cplusplus
745#if 0
746{
747#endif
748}
749#endif
750
751#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:984
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:1109
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:867
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:858
Definition iconv.h:92
Definition odbc.h:94
Definition odbc.h:106
Descriptor header.
Definition odbc.h:152
Descriptor record.
Definition odbc.h:165
Definition odbc.h:206
Definition odbc.h:224
Definition odbc.h:232
Definition odbc.h:239
Definition odbc.h:248
Definition odbc.h:277
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition odbc.h:297
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition odbc.h:300
struct _hstmt * current_statement
Statement executing.
Definition odbc.h:295
unsigned int cursor_support
<>0 if server handle cursors
Definition odbc.h:302
Definition odbc.h:311
Definition odbc.h:384
unsigned int param_count
number of parameter in current query
Definition odbc.h:421
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:426
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition odbc.h:416
TDS_INT8 row_count
row count to return
Definition odbc.h:424
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor)
Definition odbc.h:414
DSTR query
query to execute
Definition odbc.h:390
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition odbc.h:407
struct _hstmt * next
next in list
Definition odbc.h:395
TDSSOCKET * tds
socket (only if active)
Definition odbc.h:392
struct _hstmt * prev
previous in list
Definition odbc.h:397
TDSPARAMINFO * params
parameters saved
Definition odbc.h:412
Definition odbc.h:444
Definition odbc.h:535
Definition odbc.h:576
Definition odbc.h:587
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
Definition tds.h:145
Definition tds.h:518
Definition tds.h:646
Metadata about columns in regular and compute rows.
Definition tds.h:692
Hold information for any results.
Definition tds.h:772
Holds informations about a cursor.
Definition tds.h:940
Holds information for a dynamic (also called prepared) query.
Definition tds.h:980
Definition tds.h:1032
Definition tds.h:1094
Information for a server connection.
Definition tds.h:1179
Definition tds.h:1699
Structure to hold a string.
Definition string.h:36