Main Page Modules Compound List File List Compound Members File Members Related Pages

# tdsodbc.h

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004  Brian Bruns
    00003  *
    00004  * This library is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Library General Public
    00006  * License as published by the Free Software Foundation; either
    00007  * version 2 of the License, or (at your option) any later version.
    00008  *
    00009  * This library is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  * Library General Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Library General Public
    00015  * License along with this library; if not, write to the
    00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  * Boston, MA 02111-1307, USA.
    00018  */
    00019
    00020 #ifndef _sql_h_
    00021 #define _sql_h_
    00022
    00023 #include <tds.h>
    00024
    00025 #ifdef UNIXODBC
    00026 #include <sql.h>
    00027 #include <sqlext.h>
    00028 #include <odbcinst.h>
    00029 #elif defined(TDS_NO_DM)
    00030 #include <sql.h>
    00031 #include <sqlext.h>
    00032 #else /* IODBC */
    00033 #include <isql.h>
    00034 #include <isqlext.h>
    00035 #ifdef HAVE_IODBCINST_H
    00036 #include <iodbcinst.h>
    00037 #endif /* HAVE_IODBCINST_H */
    00038 #endif
    00039
    00040 #ifndef HAVE_SQLLEN
    00041 #ifndef SQLULEN
    00042 #define SQLULEN SQLUINTEGER
    00043 #endif
    00044 #ifndef SQLLEN
    00045 #define SQLLEN SQLINTEGER
    00046 #endif
    00047 #endif
    00048
    00049 #ifdef __cplusplus
    00050 extern "C"
    00051 {
    00052 #if 0
    00053 }
    00054 #endif
    00055 #endif
    00056
    00057 static const char rcsid_sql_h[] = "$Id: tdsodbc.h,v 1.74 2004/10/28 12:42:12 freddy77 Exp $";
    00058 static const void *const no_unused_sql_h_warn[] = { rcsid_sql_h, no_unused_sql_h_warn };
    00059
    00060 struct _sql_error
    00061 {
    00062         const char *msg;
    00063         char state2[6];
    00064         char state3[6];
    00065         TDS_UINT native;
    00066         char *server;
    00067         int linenum;
    00068         int msgstate;
    00069 };
    00070
    00071 struct _sql_errors
    00072 {
    00073         SQLRETURN lastrc;
    00074         int num_errors;
    00075         struct _sql_error *errs;
    00076 };
    00077
    00078 #if ENABLE_EXTRA_CHECKS
    00079 void odbc_check_struct_extra(void *p);
    00080
    00081 #define ODBC_RETURN(handle, rc) \
    00082         do { odbc_check_struct_extra(handle); return (handle->errs.lastrc = (rc)); } while(0)
    00083 #define ODBC_RETURN_(handle) \
    00084         do { odbc_check_struct_extra(handle); return handle->errs.lastrc; } while(0)
    00085 #else
    00086 #define ODBC_RETURN(handle, rc) \
    00087         do { return (handle->errs.lastrc = (rc)); } while(0)
    00088 #define ODBC_RETURN_(handle) \
    00089         do { return handle->errs.lastrc; } while(0)
    00090 #endif
    00091
    00093 void odbc_errs_reset(struct _sql_errors *errs);
    00094
    00096 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg, const char *server);
    00097
    00099 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
    00100                          int msgstate, const char *server);
    00101
    00102 struct _dheader
    00103 {
    00104         SQLSMALLINT sql_desc_alloc_type;
    00105         SQLINTEGER sql_desc_bind_type;
    00106         SQLULEN sql_desc_array_size;
    00107         /* TODO SQLLEN ?? see http://support.microsoft.com/default.aspx?scid=kb;en-us;298678 */
    00108         SQLSMALLINT sql_desc_count;
    00109         SQLUSMALLINT *sql_desc_array_status_ptr;
    00110         SQLULEN *sql_desc_rows_processed_ptr;
    00111         SQLLEN *sql_desc_bind_offset_ptr;
    00112 };
    00113
    00114 struct _drecord
    00115 {
    00116         SQLUINTEGER sql_desc_auto_unique_value;
    00117         DSTR sql_desc_base_column_name;
    00118         DSTR sql_desc_base_table_name;
    00119         SQLINTEGER sql_desc_case_sensitive;
    00120         DSTR sql_desc_catalog_name;
    00121         SQLSMALLINT sql_desc_concise_type;
    00122         SQLPOINTER sql_desc_data_ptr;
    00123         SQLSMALLINT sql_desc_datetime_interval_code;
    00124         SQLINTEGER sql_desc_datetime_interval_precision;
    00125         SQLLEN sql_desc_display_size;
    00126         SQLSMALLINT sql_desc_fixed_prec_scale;
    00127         SQLLEN *sql_desc_indicator_ptr;
    00128         DSTR sql_desc_label;
    00129         SQLULEN sql_desc_length;
    00130         /* this point to a constant buffer, do not free or modify */
    00131         const char *sql_desc_literal_prefix;
    00132         /* this point to a constant buffer, do not free or modify */
    00133         const char *sql_desc_literal_suffix;
    00134         DSTR sql_desc_local_type_name;
    00135         DSTR sql_desc_name;
    00136         SQLSMALLINT sql_desc_nullable;
    00137         SQLINTEGER sql_desc_num_prec_radix;
    00138         SQLLEN sql_desc_octet_length;
    00139         SQLLEN *sql_desc_octet_length_ptr;
    00140         SQLSMALLINT sql_desc_parameter_type;
    00141         SQLSMALLINT sql_desc_precision;
    00142         SQLSMALLINT sql_desc_rowver;
    00143         SQLSMALLINT sql_desc_scale;
    00144         DSTR sql_desc_schema_name;
    00145         SQLSMALLINT sql_desc_searchable;
    00146         DSTR sql_desc_table_name;
    00147         SQLSMALLINT sql_desc_type;
    00148         /* this point to a constant buffer, do not free or modify */
    00149         const char *sql_desc_type_name;
    00150         SQLSMALLINT sql_desc_unnamed;
    00151         SQLSMALLINT sql_desc_unsigned;
    00152         SQLSMALLINT sql_desc_updatable;
    00153 };
    00154
    00155 struct _hdesc
    00156 {
    00157         SQLSMALLINT htype;      /* do not reorder this field */
    00158         int type;
    00159         SQLHANDLE parent;
    00160         struct _dheader header;
    00161         struct _drecord *records;
    00162         struct _sql_errors errs;
    00163 };
    00164
    00165 typedef struct _hdesc TDS_DESC;
    00166
    00167 #define DESC_IRD        1
    00168 #define DESC_IPD        2
    00169 #define DESC_ARD        3
    00170 #define DESC_APD        4
    00171
    00172 struct _heattr
    00173 {
    00174         SQLUINTEGER connection_pooling;
    00175         SQLUINTEGER cp_match;
    00176         SQLINTEGER odbc_version;
    00177         SQLINTEGER output_nts;
    00178 };
    00179
    00180 struct _hchk
    00181 {
    00182         SQLSMALLINT htype;      /* do not reorder this field */
    00183 };
    00184
    00185 struct _henv
    00186 {
    00187         SQLSMALLINT htype;      /* do not reorder this field */
    00188         TDSCONTEXT *tds_ctx;
    00189         struct _sql_errors errs;
    00190         struct _heattr attr;
    00191 };
    00192
    00193 struct _hcattr
    00194 {
    00195         SQLUINTEGER access_mode;
    00196         SQLUINTEGER async_enable;
    00197         SQLUINTEGER auto_ipd;
    00198         SQLUINTEGER autocommit;
    00199         SQLUINTEGER connection_dead;
    00200         SQLUINTEGER connection_timeout;
    00201         DSTR current_catalog;
    00202         SQLUINTEGER login_timeout;
    00203         SQLUINTEGER metadata_id;
    00204         SQLUINTEGER odbc_cursors;
    00205         SQLUINTEGER packet_size;
    00206         SQLHWND quite_mode;
    00207         DSTR translate_lib;
    00208         SQLUINTEGER translate_option;
    00209         SQLUINTEGER txn_isolation;
    00210 #ifdef TDS_NO_DM
    00211         SQLUINTEGER trace;
    00212         DSTR tracefile;
    00213 #endif
    00214 };
    00215
    00216 #define TDS_MAX_APP_DESC        100
    00217
    00218 struct _hstmt;
    00219 struct _hdbc
    00220 {
    00221         SQLSMALLINT htype;      /* do not reorder this field */
    00222         struct _henv *env;
    00223         TDSSOCKET *tds_socket;
    00224         DSTR dsn;
    00225         DSTR server;            /* aka Instance */
    00227         struct _hstmt *current_statement;
    00229         struct _hstmt *stmt_list;
    00230         struct _sql_errors errs;
    00231         struct _hcattr attr;
    00233         TDS_DESC *uad[TDS_MAX_APP_DESC];
    00234 };
    00235
    00236 struct _hsattr
    00237 {
    00238         /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
    00239 /*      TDS_DESC *app_row_desc; */
    00240 /*      TDS_DESC *app_param_desc; */
    00241         SQLUINTEGER async_enable;
    00242         SQLUINTEGER concurrency;
    00243         SQLUINTEGER cursor_scrollable;
    00244         SQLUINTEGER cursor_sensitivity;
    00245         SQLUINTEGER cursor_type;
    00246         SQLUINTEGER enable_auto_ipd;
    00247         SQLPOINTER fetch_bookmark_ptr;
    00248         SQLULEN keyset_size;
    00249         SQLULEN max_length;
    00250         SQLULEN max_rows;
    00251         SQLUINTEGER metadata_id;
    00252         SQLUINTEGER noscan;
    00253         /* apd->sql_desc_bind_offset_ptr */
    00254         /* SQLUINTEGER *param_bind_offset_ptr; */
    00255         /* apd->sql_desc_bind_type */
    00256         /* SQLUINTEGER param_bind_type; */
    00257         /* apd->sql_desc_array_status_ptr */
    00258         /* SQLUSMALLINT *param_operation_ptr; */
    00259         /* ipd->sql_desc_array_status_ptr */
    00260         /* SQLUSMALLINT *param_status_ptr; */
    00261         /* ipd->sql_desc_rows_processed_ptr */
    00262         /* SQLUSMALLINT *params_processed_ptr; */
    00263         /* apd->sql_desc_array_size */
    00264         /* SQLUINTEGER paramset_size; */
    00265         SQLUINTEGER query_timeout;
    00266         SQLUINTEGER retrieve_data;
    00267         /* ard->sql_desc_bind_offset_ptr */
    00268         /* SQLUINTEGER *row_bind_offset_ptr; */
    00269         /* ard->sql_desc_array_size */
    00270         /* SQLUINTEGER row_array_size; */
    00271         /* ard->sql_desc_bind_type */
    00272         /* SQLUINTEGER row_bind_type; */
    00273         SQLULEN row_number;
    00274         /* ard->sql_desc_array_status_ptr */
    00275         /* SQLUINTEGER *row_operation_ptr; */
    00276         /* ird->sql_desc_array_status_ptr */
    00277         /* SQLUINTEGER *row_status_ptr; */
    00278         /* ird->sql_desc_rows_processed_ptr */
    00279         /* SQLUINTEGER *rows_fetched_ptr; */
    00280         SQLUINTEGER simulate_cursor;
    00281         SQLUINTEGER use_bookmarks;
    00282         /* SQLGetStmtAttr only */
    00283 /*      TDS_DESC *imp_row_desc; */
    00284 /*      TDS_DESC *imp_param_desc; */
    00285 };
    00286
    00287 struct _hstmt
    00288 {
    00289         SQLSMALLINT htype;      /* do not reorder this field */
    00290         struct _hdbc *dbc;
    00292         char *query;
    00293
    00295         struct _hstmt *next;
    00297         struct _hstmt *prev;
    00298
    00299         /* begin prepared query stuff */
    00300         char *prepared_query;
    00301         unsigned prepared_query_is_func:1;
    00302         unsigned prepared_query_is_rpc:1;
    00303         unsigned need_reprepare:1;
    00304         unsigned param_data_called:1;
    00305         /* end prepared query stuff */
    00306
    00308         TDSPARAMINFO *params;
    00310         int param_num;
    00311
    00313         unsigned int param_count;
    00314         int row;
    00316         int row_count;
    00317         /* do NOT free dynamic, free from socket or attach to connection */
    00318         TDSDYNAMIC *dyn;
    00319         struct _sql_errors errs;
    00320         TDS_DESC *ard, *ird, *apd, *ipd;
    00321         TDS_DESC *orig_ard, *orig_apd;
    00322         SQLULEN sql_rowset_size;
    00323         struct _hsattr attr;
    00324         DSTR cursor_name;       /* auto generated cursor name */
    00325 };
    00326
    00327 typedef struct _henv TDS_ENV;
    00328 typedef struct _hdbc TDS_DBC;
    00329 typedef struct _hstmt TDS_STMT;
    00330 typedef struct _hchk TDS_CHK;
    00331
    00332 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
    00333 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
    00334 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
    00335 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
    00336
    00337 TDS_DESC *desc_alloc(SQLHANDLE parent, int desc_type, int alloc_type);
    00338 SQLRETURN desc_free(TDS_DESC * desc);
    00339 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
    00340 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
    00341 SQLRETURN desc_free_records(TDS_DESC * desc);
    00342
    00343 /* fix a bug in MingW headers */
    00344 #ifdef __MINGW32__
    00345 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
    00346
    00347 #undef SQL_INTERVAL_YEAR
    00348 #undef SQL_INTERVAL_MONTH
    00349 #undef SQL_INTERVAL_DAY
    00350 #undef SQL_INTERVAL_HOUR
    00351 #undef SQL_INTERVAL_MINUTE
    00352 #undef SQL_INTERVAL_SECOND
    00353 #undef SQL_INTERVAL_YEAR_TO_MONTH
    00354 #undef SQL_INTERVAL_DAY_TO_HOUR
    00355 #undef SQL_INTERVAL_DAY_TO_MINUTE
    00356 #undef SQL_INTERVAL_DAY_TO_SECOND
    00357 #undef SQL_INTERVAL_HOUR_TO_MINUTE
    00358 #undef SQL_INTERVAL_HOUR_TO_SECOND
    00359 #undef SQL_INTERVAL_MINUTE_TO_SECOND
    00360
    00361 #define SQL_INTERVAL_YEAR                                       (100 + SQL_CODE_YEAR)
    00362 #define SQL_INTERVAL_MONTH                                      (100 + SQL_CODE_MONTH)
    00363 #define SQL_INTERVAL_DAY                                        (100 + SQL_CODE_DAY)
    00364 #define SQL_INTERVAL_HOUR                                       (100 + SQL_CODE_HOUR)
    00365 #define SQL_INTERVAL_MINUTE                                     (100 + SQL_CODE_MINUTE)
    00366 #define SQL_INTERVAL_SECOND                     (100 + SQL_CODE_SECOND)
    00367 #define SQL_INTERVAL_YEAR_TO_MONTH                      (100 + SQL_CODE_YEAR_TO_MONTH)
    00368 #define SQL_INTERVAL_DAY_TO_HOUR                        (100 + SQL_CODE_DAY_TO_HOUR)
    00369 #define SQL_INTERVAL_DAY_TO_MINUTE                      (100 + SQL_CODE_DAY_TO_MINUTE)
    00370 #define SQL_INTERVAL_DAY_TO_SECOND                      (100 + SQL_CODE_DAY_TO_SECOND)
    00371 #define SQL_INTERVAL_HOUR_TO_MINUTE                     (100 + SQL_CODE_HOUR_TO_MINUTE)
    00372 #define SQL_INTERVAL_HOUR_TO_SECOND                     (100 + SQL_CODE_HOUR_TO_SECOND)
    00373 #define SQL_INTERVAL_MINUTE_TO_SECOND           (100 + SQL_CODE_MINUTE_TO_SECOND)
    00374
    00375 #endif
    00376 #endif
    00377
    00378 #ifdef __cplusplus
    00379 #if 0
    00380 {
    00381 #endif
    00382 }
    00383 #endif
    00384
    00385 #endif