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