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;
217 int focus;
218 SQLHANDLE parent;
219 struct _dheader header;
220 struct _drecord *records;
221};
222
223typedef struct _hdesc TDS_DESC;
224
225#define DESC_IRD 1
226#define DESC_IPD 2
227#define DESC_ARD 3
228#define DESC_APD 4
229
231{
232 SQLUINTEGER connection_pooling;
233 SQLUINTEGER cp_match;
234 SQLINTEGER odbc_version;
235 SQLINTEGER output_nts;
236};
237
238struct _hchk
239{
240 SQLSMALLINT htype; /* do not reorder this field */
241 struct _sql_errors errs; /* do not reorder this field */
242 tds_mutex mtx;
243};
244
245struct _henv
246{
247 SQLSMALLINT htype; /* do not reorder this field */
248 struct _sql_errors errs; /* do not reorder this field */
249 tds_mutex mtx;
250 TDSCONTEXT *tds_ctx;
251 struct _heattr attr;
252};
253
255{
256 SQLUINTEGER access_mode;
257 SQLUINTEGER async_enable;
258 SQLUINTEGER auto_ipd;
259 SQLUINTEGER autocommit;
260 SQLUINTEGER connection_dead;
261 SQLUINTEGER connection_timeout;
262 DSTR current_catalog;
263 SQLUINTEGER login_timeout;
264 SQLUINTEGER metadata_id;
265 SQLUINTEGER odbc_cursors;
266 SQLUINTEGER packet_size;
267 SQLHWND quite_mode;
268 DSTR translate_lib;
269 SQLUINTEGER translate_option;
270 SQLUINTEGER txn_isolation;
271 SQLUINTEGER mars_enabled;
272 SQLUINTEGER cursor_type;
273 SQLUINTEGER bulk_enabled;
274#ifdef TDS_NO_DM
275 SQLUINTEGER trace;
276 DSTR tracefile;
277#endif
278};
279
280#define TDS_MAX_APP_DESC 100
281
282struct _hstmt;
283struct _hdbc
284{
285 SQLSMALLINT htype; /* do not reorder this field */
286 struct _sql_errors errs; /* do not reorder this field */
287 tds_mutex mtx;
288 struct _henv *env;
290 DSTR dsn;
291 DSTR oldpwd;
292#ifdef ENABLE_ODBC_WIDE
293 int original_charset_num;
294 TDSICONV *mb_conv;
295#endif
296
305 struct _hcattr attr;
307 TDS_DESC *uad[TDS_MAX_APP_DESC];
309 unsigned int cursor_support:1;
310 unsigned int use_oldpwd:1;
311 TDS_INT default_query_timeout;
312
313 TDSBCPINFO *bcpinfo;
314};
315
317{
318 /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
319/* TDS_DESC *app_row_desc; */
320/* TDS_DESC *app_param_desc; */
321 SQLUINTEGER async_enable;
322 SQLUINTEGER concurrency;
323 SQLUINTEGER cursor_scrollable;
324 SQLUINTEGER cursor_sensitivity;
325 SQLUINTEGER cursor_type;
326 SQLUINTEGER enable_auto_ipd;
327 SQLPOINTER fetch_bookmark_ptr;
328 SQLULEN keyset_size;
329 SQLULEN max_length;
330 SQLULEN max_rows;
331 SQLUINTEGER metadata_id;
332 SQLUINTEGER noscan;
333 /* apd->sql_desc_bind_offset_ptr */
334 /* SQLUINTEGER *param_bind_offset_ptr; */
335 /* apd->sql_desc_bind_type */
336 /* SQLUINTEGER param_bind_type; */
337 /* apd->sql_desc_array_status_ptr */
338 /* SQLUSMALLINT *param_operation_ptr; */
339 /* ipd->sql_desc_array_status_ptr */
340 /* SQLUSMALLINT *param_status_ptr; */
341 /* ipd->sql_desc_rows_processed_ptr */
342 /* SQLUSMALLINT *params_processed_ptr; */
343 /* apd->sql_desc_array_size */
344 /* SQLUINTEGER paramset_size; */
345 SQLUINTEGER query_timeout;
346 SQLUINTEGER retrieve_data;
347 /* ard->sql_desc_bind_offset_ptr */
348 /* SQLUINTEGER *row_bind_offset_ptr; */
349 /* ard->sql_desc_array_size */
350 /* SQLUINTEGER row_array_size; */
351 /* ard->sql_desc_bind_type */
352 /* SQLUINTEGER row_bind_type; */
353 SQLULEN row_number;
354 /* ard->sql_desc_array_status_ptr */
355 /* SQLUINTEGER *row_operation_ptr; */
356 /* ird->sql_desc_array_status_ptr */
357 /* SQLUINTEGER *row_status_ptr; */
358 /* ird->sql_desc_rows_processed_ptr */
359 /* SQLUINTEGER *rows_fetched_ptr; */
360 SQLUINTEGER simulate_cursor;
361 SQLUINTEGER use_bookmarks;
362 /* SQLGetStmtAttr only */
363/* TDS_DESC *imp_row_desc; */
364/* TDS_DESC *imp_param_desc; */
365 DSTR qn_msgtext;
366 DSTR qn_options;
367 SQLUINTEGER qn_timeout;
368 SQLUINTEGER param_focus;
369};
370
371typedef enum
372{
373 NOT_IN_ROW,
374 IN_NORMAL_ROW,
375 IN_COMPUTE_ROW,
376 AFTER_COMPUTE_ROW,
377 PRE_NORMAL_ROW
378} TDS_ODBC_ROW_STATUS;
379
380typedef enum
381{
382 ODBC_SPECIAL_NONE = 0,
383 ODBC_SPECIAL_GETTYPEINFO = 1,
384 ODBC_SPECIAL_COLUMNS = 2,
385 ODBC_SPECIAL_PROCEDURECOLUMNS = 3,
386 ODBC_SPECIAL_SPECIALCOLUMNS = 4
387} TDS_ODBC_SPECIAL_ROWS;
388
389struct _hstmt
390{
391 SQLSMALLINT htype; /* do not reorder this field */
392 struct _sql_errors errs; /* do not reorder this field */
393 tds_mutex mtx;
394 struct _hdbc *dbc;
399
401 struct _hstmt *next;
403 struct _hstmt *prev;
404
405 /* begin prepared query stuff */
406 unsigned is_prepared_query:1;
407 unsigned prepared_query_is_func:1;
408 unsigned prepared_query_is_rpc:1;
413 unsigned need_reprepare:1;
414 unsigned param_data_called:1;
415 /* end prepared query stuff */
416
423
424 unsigned int curr_param_row, num_param_rows;
425
427 unsigned int param_count;
428 int row;
430 TDS_INT8 row_count;
432 TDS_ODBC_ROW_STATUS row_status;
433 /* do NOT free dynamic, free from socket or attach to connection */
434 TDSDYNAMIC *dyn;
435 TDS_DESC *ard, *ird, *apd, *ipd;
436 TDS_DESC *orig_ard, *orig_apd;
437 SQLULEN sql_rowset_size;
438 struct _hsattr attr;
439 DSTR cursor_name; /* auto generated cursor name */
440 TDS_ODBC_SPECIAL_ROWS special_row;
441 /* do NOT free cursor, free from socket or attach to connection */
442 TDSCURSOR *cursor;
443};
444
445typedef struct _henv TDS_ENV;
446typedef struct _hdbc TDS_DBC;
447typedef struct _hstmt TDS_STMT;
448typedef struct _hchk TDS_CHK;
449
450typedef struct {
451 /* this must be the first member */
452 TDSCOLUMNFUNCS common;
453 void (*set_type_info)(TDSCOLUMN *col, struct _drecord *drec, SQLINTEGER odbc_ver);
454} TDS_FUNCS;
455
456#define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
457#define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
458#define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
459#define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
460
461/* fix a bug in MingW headers */
462#ifdef __MINGW32__
463#if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
464
465#undef SQL_INTERVAL_YEAR
466#undef SQL_INTERVAL_MONTH
467#undef SQL_INTERVAL_DAY
468#undef SQL_INTERVAL_HOUR
469#undef SQL_INTERVAL_MINUTE
470#undef SQL_INTERVAL_SECOND
471#undef SQL_INTERVAL_YEAR_TO_MONTH
472#undef SQL_INTERVAL_DAY_TO_HOUR
473#undef SQL_INTERVAL_DAY_TO_MINUTE
474#undef SQL_INTERVAL_DAY_TO_SECOND
475#undef SQL_INTERVAL_HOUR_TO_MINUTE
476#undef SQL_INTERVAL_HOUR_TO_SECOND
477#undef SQL_INTERVAL_MINUTE_TO_SECOND
478
479#define SQL_INTERVAL_YEAR (100 + SQL_CODE_YEAR)
480#define SQL_INTERVAL_MONTH (100 + SQL_CODE_MONTH)
481#define SQL_INTERVAL_DAY (100 + SQL_CODE_DAY)
482#define SQL_INTERVAL_HOUR (100 + SQL_CODE_HOUR)
483#define SQL_INTERVAL_MINUTE (100 + SQL_CODE_MINUTE)
484#define SQL_INTERVAL_SECOND (100 + SQL_CODE_SECOND)
485#define SQL_INTERVAL_YEAR_TO_MONTH (100 + SQL_CODE_YEAR_TO_MONTH)
486#define SQL_INTERVAL_DAY_TO_HOUR (100 + SQL_CODE_DAY_TO_HOUR)
487#define SQL_INTERVAL_DAY_TO_MINUTE (100 + SQL_CODE_DAY_TO_MINUTE)
488#define SQL_INTERVAL_DAY_TO_SECOND (100 + SQL_CODE_DAY_TO_SECOND)
489#define SQL_INTERVAL_HOUR_TO_MINUTE (100 + SQL_CODE_HOUR_TO_MINUTE)
490#define SQL_INTERVAL_HOUR_TO_SECOND (100 + SQL_CODE_HOUR_TO_SECOND)
491#define SQL_INTERVAL_MINUTE_TO_SECOND (100 + SQL_CODE_MINUTE_TO_SECOND)
492
493#endif
494#endif
495
496#ifdef _WIN32
497bool get_login_info(HWND hwndParent, TDSLOGIN * login);
498#endif
499
500#define ODBC_PARAM_LIST \
501 ODBC_PARAM(Servername) \
502 ODBC_PARAM(Server) \
503 ODBC_PARAM(DSN) \
504 ODBC_PARAM(UID) \
505 ODBC_PARAM(PWD) \
506 ODBC_PARAM(Address) \
507 ODBC_PARAM(Port) \
508 ODBC_PARAM(TDS_Version) \
509 ODBC_PARAM(Language) \
510 ODBC_PARAM(Database) \
511 ODBC_PARAM(TextSize) \
512 ODBC_PARAM(PacketSize) \
513 ODBC_PARAM(ClientCharset) \
514 ODBC_PARAM(DumpFile) \
515 ODBC_PARAM(DumpFileAppend) \
516 ODBC_PARAM(DebugFlags) \
517 ODBC_PARAM(Encryption) \
518 ODBC_PARAM(Trusted_Connection) \
519 ODBC_PARAM(APP) \
520 ODBC_PARAM(WSID) \
521 ODBC_PARAM(UseNTLMv2) \
522 ODBC_PARAM(MARS_Connection) \
523 ODBC_PARAM(REALM) \
524 ODBC_PARAM(ServerSPN) \
525 ODBC_PARAM(AttachDbFilename) \
526 ODBC_PARAM(ApplicationIntent) \
527 ODBC_PARAM(Timeout)
528
529#define ODBC_PARAM(p) ODBC_PARAM_##p,
530enum {
531 ODBC_PARAM_LIST
532 ODBC_PARAM_SIZE
533};
534#undef ODBC_PARAM
535
536
537/*
538 * connectparams.h
539 */
540
541typedef struct {
542 const char *p;
543 size_t len;
545
553bool odbc_parse_connect_string(TDS_ERRS *errs, const char *connect_string, const char *connect_string_end, TDSLOGIN * login, TDS_PARSED_PARAM *parsed_params);
554int odbc_get_dsn_info(TDS_ERRS *errs, const char *DSN, TDSLOGIN * login);
555#ifdef _WIN32
556int odbc_build_connect_string(TDS_ERRS *errs, TDS_PARSED_PARAM *params, char **out);
557#endif
558
559/*
560 * convert_tds2sql.c
561 */
562SQLLEN odbc_tds2sql_col(TDS_STMT * stmt, TDSCOLUMN *curcol, int desttype, TDS_CHAR * dest, SQLULEN destlen, const struct _drecord *drec_ixd);
563SQLLEN odbc_tds2sql_int4(TDS_STMT * stmt, TDS_INT *src, int desttype, TDS_CHAR * dest, SQLULEN destlen);
564
565
566
567/*
568 * descriptor.c
569 */
570typedef struct {
571 DSTR type_name;
572 TDS_DESC *apd;
573 TDS_DESC *ipd;
574} SQLTVP;
575
576TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, SQLSMALLINT alloc_type);
577SQLRETURN desc_free(TDS_DESC * desc);
578SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
579SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
580SQLRETURN desc_free_records(TDS_DESC * desc);
581TDS_DBC *desc_get_dbc(TDS_DESC *desc);
582SQLTVP *tvp_alloc(TDS_STMT *stmt);
583void tvp_free(SQLTVP *tvp);
584
585/*
586 * odbc.c
587 */
588
589SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLLEN FAR * pcrow);
590
591/*
592 * odbc_checks.h
593 */
594#if ENABLE_EXTRA_CHECKS
595/* macro */
596#define CHECK_ENV_EXTRA(env) odbc_check_env_extra(env)
597#define CHECK_DBC_EXTRA(dbc) odbc_check_dbc_extra(dbc)
598#define CHECK_STMT_EXTRA(stmt) odbc_check_stmt_extra(stmt)
599#define CHECK_DESC_EXTRA(desc) odbc_check_desc_extra(desc)
600/* declarations*/
601void odbc_check_env_extra(TDS_ENV * env);
602void odbc_check_dbc_extra(TDS_DBC * dbc);
603void odbc_check_stmt_extra(TDS_STMT * stmt);
604void odbc_check_desc_extra(TDS_DESC * desc);
605#else
606/* macro */
607#define CHECK_ENV_EXTRA(env)
608#define CHECK_DBC_EXTRA(dbc)
609#define CHECK_STMT_EXTRA(stmt)
610#define CHECK_DESC_EXTRA(desc)
611#endif
612
613/*
614 * odbc_util.h
615 */
616
617/* helpers for ODBC wide string support */
618#undef _wide
619#undef _WIDE
620#ifdef ENABLE_ODBC_WIDE
621typedef union {
622 char mb[1];
623 SQLWCHAR wide[1];
624} ODBC_CHAR;
625# define _wide ,wide
626# define _wide0 ,0
627# define _WIDE ,int wide
628#else
629# define _wide
630# define _wide0
631# define _WIDE
632# define ODBC_CHAR SQLCHAR
633#endif
634int odbc_set_stmt_query(struct _hstmt *stmt, const ODBC_CHAR *sql, int sql_len _WIDE);
635void odbc_set_return_status(struct _hstmt *stmt, unsigned int n_row);
636void odbc_set_return_params(struct _hstmt *stmt, unsigned int n_row);
637
638void odbc_set_sql_type_info(TDSCOLUMN * col, struct _drecord *drec, SQLINTEGER odbc_ver);
639
640int odbc_sql_to_c_type_default(int sql_type);
641TDS_SERVER_TYPE odbc_sql_to_server_type(TDSCONNECTION * conn, int sql_type, int sql_unsigned);
642TDS_SERVER_TYPE odbc_c_to_server_type(int c_type);
643
644unsigned int odbc_get_string_size(int size, const ODBC_CHAR * str _WIDE);
645void odbc_rdbms_version(TDSSOCKET * tds_socket, char *pversion_string);
646SQLINTEGER odbc_get_param_len(const struct _drecord *drec_axd, const struct _drecord *drec_ixd, const TDS_DESC* axd, unsigned int n_row);
647
648#ifdef ENABLE_ODBC_WIDE
649DSTR* odbc_dstr_copy_flag(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str, int flag);
650#define odbc_dstr_copy(dbc, s, len, out) \
651 odbc_dstr_copy_flag(dbc, s, len, sizeof((out)->mb) ? (out) : (out), wide)
652#define odbc_dstr_copy_oct(dbc, s, len, out) \
653 odbc_dstr_copy_flag(dbc, s, len, out, wide|0x20)
654#else
655DSTR* odbc_dstr_copy(TDS_DBC *dbc, DSTR *s, int size, const ODBC_CHAR * str);
656#define odbc_dstr_copy_oct odbc_dstr_copy
657#endif
658
659
660SQLRETURN odbc_set_string_flag(TDS_DBC *dbc, SQLPOINTER buffer, SQLINTEGER cbBuffer, void FAR * pcbBuffer, const char *s, int len, int flag);
661#ifdef ENABLE_ODBC_WIDE
662#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
663 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))
664#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
665 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (wide) | (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
666#else
667#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len) \
668 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0:0x10))
669#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len) \
670 odbc_set_string_flag(dbc, buf, buf_len, out_len, s, s_len, (sizeof(*(out_len)) == sizeof(SQLSMALLINT)?0x20:0x30))
671#endif
672
673#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))
674#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))
675
676SQLSMALLINT odbc_get_concise_sql_type(SQLSMALLINT type, SQLSMALLINT interval);
677SQLRETURN odbc_set_concise_sql_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
678SQLSMALLINT odbc_get_concise_c_type(SQLSMALLINT type, SQLSMALLINT interval);
679SQLRETURN odbc_set_concise_c_type(SQLSMALLINT concise_type, struct _drecord *drec, int check_only);
680
681SQLLEN odbc_get_octet_len(int c_type, const struct _drecord *drec);
682void odbc_convert_err_set(struct _sql_errors *errs, TDS_INT err);
683
684/*
685 * prepare_query.c
686 */
687SQLRETURN prepare_call(struct _hstmt *stmt);
688SQLRETURN native_sql(struct _hdbc *dbc, DSTR *s);
689int parse_prepared_query(struct _hstmt *stmt, bool compute_row);
690int start_parse_prepared_query(struct _hstmt *stmt, bool compute_row);
691int continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or_Ind);
692const char *parse_const_param(const char * s, TDS_SERVER_TYPE *type);
693const char *odbc_skip_rpc_name(const char *s);
694
695/*
696 * sql2tds.c
697 */
698SQLRETURN 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);
699TDS_INT convert_datetime2server(int bindtype, const void *src, TDS_DATETIMEALL * dta);
700
701/*
702 * bcp.c
703 */
704void odbc_bcp_free_storage(TDS_DBC *dbc);
705void odbc_bcp_init(TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE);
706void odbc_bcp_control(TDS_DBC *dbc, int field, void *value);
707void odbc_bcp_colptr(TDS_DBC *dbc, const void * colptr, int table_column);
708void odbc_bcp_sendrow(TDS_DBC *dbc);
709int odbc_bcp_batch(TDS_DBC *dbc);
710int odbc_bcp_done(TDS_DBC *dbc);
711void odbc_bcp_bind(TDS_DBC *dbc, const void * varaddr, int prefixlen, int varlen, const void * terminator, int termlen, int vartype, int table_column);
712
713/*
714 * sqlwchar.c
715 */
716#if SIZEOF_SQLWCHAR != SIZEOF_WCHAR_T
717size_t sqlwcslen(const SQLWCHAR * s);
718
719typedef struct sqlwstr_buf {
720 struct sqlwstr_buf *next;
721 wchar_t buf[256];
722} SQLWSTRBUF;
723const wchar_t *sqlwstr(const SQLWCHAR * s, SQLWSTRBUF **bufs);
724void sqlwstr_free(SQLWSTRBUF *bufs);
725#define SQLWSTR_BUFS(n) SQLWSTRBUF *bufs = NULL
726#define SQLWSTR(s) sqlwstr(s, &bufs)
727#define SQLWSTR_FREE() sqlwstr_free(bufs)
728#else
729#define sqlwcslen(s) wcslen(s)
730
731#define SQLWSTR_BUFS(n) do {} while(0)
732#define SQLWSTR(s) ((const wchar_t*)(s))
733#define SQLWSTR_FREE() do {} while(0)
734#endif
735
736int odbc_get_wide_canonic(TDSCONNECTION *conn);
737
738#include <freetds/popvis.h>
739
740#ifdef __cplusplus
741#if 0
742{
743#endif
744}
745#endif
746
747#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:1111
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:866
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:857
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
int focus
Nested descriptor to use.
Definition odbc.h:217
Definition odbc.h:231
Definition odbc.h:239
Definition odbc.h:246
Definition odbc.h:255
Definition odbc.h:284
struct _hstmt * stmt_list
list of all statements allocated from this connection
Definition odbc.h:304
TDS_DESC * uad[TDS_MAX_APP_DESC]
descriptors associated to connection
Definition odbc.h:307
struct _hstmt * current_statement
Statement executing.
Definition odbc.h:302
unsigned int cursor_support
<>0 if server handle cursors
Definition odbc.h:309
Definition odbc.h:317
Definition odbc.h:390
unsigned int param_count
number of parameter in current query
Definition odbc.h:427
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:432
size_t prepared_pos
position in prepared query to check parameters, used only in RPC
Definition odbc.h:422
TDS_INT8 row_count
row count to return
Definition odbc.h:430
int param_num
last valid parameter in params, it's a ODBC index (from 1 relative to descriptor)
Definition odbc.h:420
DSTR query
query to execute
Definition odbc.h:396
unsigned need_reprepare
Prepared statement needs to be prepared again.
Definition odbc.h:413
struct _hstmt * next
next in list
Definition odbc.h:401
TDSSOCKET * tds
socket (only if active)
Definition odbc.h:398
struct _hstmt * prev
previous in list
Definition odbc.h:403
TDSPARAMINFO * params
parameters saved
Definition odbc.h:418
Definition odbc.h:450
Definition odbc.h:541
Definition odbc.h:570
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:647
Metadata about columns in regular and compute rows.
Definition tds.h:693
Hold information for any results.
Definition tds.h:773
Holds informations about a cursor.
Definition tds.h:941
Holds information for a dynamic (also called prepared) query.
Definition tds.h:981
Definition tds.h:1033
Definition tds.h:1095
Information for a server connection.
Definition tds.h:1180
Definition tds.h:1700
Structure to hold a string.
Definition string.h:36