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  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 SQLULEN
00041 #define SQLULEN SQLUINTEGER
00042 #endif
00043 #ifndef SQLLEN
00044 #define SQLLEN SQLINTEGER
00045 #endif
00046 
00047 #ifdef __cplusplus
00048 extern "C"
00049 {
00050 #if 0
00051 }
00052 #endif
00053 #endif
00054 
00055 static char rcsid_sql_h[] = "$Id: tdsodbc.h,v 1.63.2.1 2004/03/06 13:51:28 freddy77 Exp $";
00056 static void *no_unused_sql_h_warn[] = { rcsid_sql_h, no_unused_sql_h_warn };
00057 
00058 struct _sql_error
00059 {
00060         const char *msg;
00061         char state2[6];
00062         char state3[6];
00063         TDS_UINT native;
00064         char *server;
00065         int linenum;
00066         int msgstate;
00067 };
00068 
00069 struct _sql_errors
00070 {
00071         SQLRETURN lastrc;
00072         int num_errors;
00073         struct _sql_error *errs;
00074 };
00075 
00076 #if ENABLE_EXTRA_CHECKS
00077 void odbc_check_struct_extra(void *p);
00078 
00079 #define ODBC_RETURN(handle, rc) \
00080         do { odbc_check_struct_extra(handle); return (handle->errs.lastrc = (rc)); } while(0)
00081 #else
00082 #define ODBC_RETURN(handle, rc) \
00083         do { return (handle->errs.lastrc = (rc)); } while(0)
00084 #endif
00085 
00087 void odbc_errs_reset(struct _sql_errors *errs);
00088 
00090 void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg, const char *server);
00091 
00093 void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum,
00094                          int msgstate, const char *server);
00095 
00096 struct _dheader
00097 {
00098         SQLSMALLINT sql_desc_alloc_type;
00099         SQLINTEGER sql_desc_bind_type;
00100         SQLUINTEGER sql_desc_array_size;
00101         SQLSMALLINT sql_desc_count;
00102         SQLUSMALLINT *sql_desc_array_status_ptr;
00103         SQLUINTEGER *sql_desc_rows_processed_ptr;
00104         SQLINTEGER *sql_desc_bind_offset_ptr;
00105 };
00106 
00107 struct _drecord
00108 {
00109         SQLUINTEGER sql_desc_auto_unique_value;
00110         SQLCHAR *sql_desc_base_column_name;
00111         SQLCHAR *sql_desc_base_table_name;
00112         SQLINTEGER sql_desc_case_sensitive;
00113         SQLCHAR *sql_desc_catalog_name;
00114         SQLSMALLINT sql_desc_concise_type;
00115         SQLPOINTER sql_desc_data_ptr;
00116         SQLSMALLINT sql_desc_datetime_interval_code;
00117         SQLINTEGER sql_desc_datetime_interval_precision;
00118         SQLINTEGER sql_desc_display_size;
00119         SQLSMALLINT sql_desc_fixed_prec_scale;
00120         SQLINTEGER *sql_desc_indicator_ptr;
00121         SQLCHAR *sql_desc_label;
00122         SQLUINTEGER sql_desc_length;
00123         SQLCHAR *sql_desc_literal_prefix;
00124         SQLCHAR *sql_desc_literal_suffix;
00125         SQLCHAR *sql_desc_local_type_name;
00126         SQLCHAR *sql_desc_name;
00127         SQLSMALLINT sql_desc_nullable;
00128         SQLINTEGER sql_desc_num_prec_radix;
00129         SQLINTEGER sql_desc_octet_length;
00130         SQLINTEGER *sql_desc_octet_length_ptr;
00131         SQLSMALLINT sql_desc_parameter_type;
00132         SQLSMALLINT sql_desc_precision;
00133         SQLSMALLINT sql_desc_rowver;
00134         SQLSMALLINT sql_desc_scale;
00135         SQLCHAR *sql_desc_schema_name;
00136         SQLSMALLINT sql_desc_searchable;
00137         SQLCHAR *sql_desc_table_name;
00138         SQLSMALLINT sql_desc_type;
00139         SQLCHAR *sql_desc_type_name;
00140         SQLSMALLINT sql_desc_unnamed;
00141         SQLSMALLINT sql_desc_unsigned;
00142         SQLSMALLINT sql_desc_updatable;
00143 };
00144 
00145 struct _hdesc
00146 {
00147         SQLSMALLINT htype;      /* do not reorder this field */
00148         int type;
00149         SQLHDESC parent;
00150         struct _dheader header;
00151         struct _drecord *records;
00152         struct _sql_errors errs;
00153 };
00154 
00155 typedef struct _hdesc TDS_DESC;
00156 
00157 #define DESC_IRD        1
00158 #define DESC_IPD        2
00159 #define DESC_ARD        3
00160 #define DESC_APD        4
00161 
00162 struct _heattr
00163 {
00164         SQLUINTEGER connection_pooling;
00165         SQLUINTEGER cp_match;
00166         SQLINTEGER odbc_version;
00167         SQLINTEGER output_nts;
00168 };
00169 
00170 struct _hchk
00171 {
00172         SQLSMALLINT htype;      /* do not reorder this field */
00173 };
00174 
00175 struct _henv
00176 {
00177         SQLSMALLINT htype;      /* do not reorder this field */
00178         TDSCONTEXT *tds_ctx;
00179         struct _sql_errors errs;
00180         struct _heattr attr;
00181 };
00182 
00183 struct _hcattr
00184 {
00185         SQLUINTEGER access_mode;
00186         SQLUINTEGER async_enable;
00187         SQLUINTEGER auto_ipd;
00188         SQLUINTEGER autocommit;
00189         SQLUINTEGER connection_dead;
00190         SQLUINTEGER connection_timeout;
00191         DSTR current_catalog;
00192         SQLUINTEGER login_timeout;
00193         SQLUINTEGER metadata_id;
00194         SQLUINTEGER odbc_cursors;
00195         SQLUINTEGER packet_size;
00196         SQLHWND quite_mode;
00197         DSTR translate_lib;
00198         SQLUINTEGER translate_option;
00199         SQLUINTEGER txn_isolation;
00200 #ifdef TDS_NO_DM
00201         SQLUINTEGER trace;
00202         DSTR tracefile;
00203 #endif
00204 };
00205 
00206 #define TDS_MAX_APP_DESC        100
00207 
00208 struct _hstmt;
00209 struct _hdbc
00210 {
00211         SQLSMALLINT htype;      /* do not reorder this field */
00212         struct _henv *env;
00213         TDSSOCKET *tds_socket;
00214         DSTR dsn;
00215         DSTR server;            /* aka Instance */
00217         struct _hstmt *current_statement;
00218         struct _sql_errors errs;
00219         struct _hcattr attr;
00220         TDS_DESC *uad[TDS_MAX_APP_DESC];
00221 };
00222 
00223 struct _hsattr
00224 {
00225         /* TODO remove IRD, ARD, IPD, APD from statement, do not duplicate */
00226 /*      TDS_DESC *app_row_desc; */
00227 /*      TDS_DESC *app_param_desc; */
00228         SQLUINTEGER async_enable;
00229         SQLUINTEGER concurrency;
00230         SQLUINTEGER cursor_scrollable;
00231         SQLUINTEGER cursor_sensitivity;
00232         SQLUINTEGER cursor_type;
00233         SQLUINTEGER enable_auto_ipd;
00234         SQLPOINTER fetch_bookmark_ptr;
00235         SQLUINTEGER keyset_size;
00236         SQLUINTEGER max_length;
00237         SQLUINTEGER max_rows;
00238         SQLUINTEGER metadata_id;
00239         SQLUINTEGER noscan;
00240         /* apd->sql_desc_bind_offset_ptr */
00241         /* SQLUINTEGER *param_bind_offset_ptr; */
00242         /* apd->sql_desc_bind_type */
00243         /* SQLUINTEGER param_bind_type; */
00244         /* apd->sql_desc_array_status_ptr */
00245         /* SQLUSMALLINT *param_operation_ptr; */
00246         /* ipd->sql_desc_array_status_ptr */
00247         /* SQLUSMALLINT *param_status_ptr; */
00248         /* ipd->sql_desc_rows_processed_ptr */
00249         /* SQLUSMALLINT *params_processed_ptr; */
00250         /* apd->sql_desc_array_size */
00251         /* SQLUINTEGER paramset_size; */
00252         SQLUINTEGER query_timeout;
00253         SQLUINTEGER retrieve_data;
00254         /* ard->sql_desc_bind_offset_ptr */
00255         /* SQLUINTEGER *row_bind_offset_ptr; */
00256         /* ard->sql_desc_array_size */
00257         /* SQLUINTEGER row_array_size; */
00258         /* ard->sql_desc_bind_type */
00259         /* SQLUINTEGER row_bind_type; */
00260         SQLUINTEGER row_number;
00261         /* ard->sql_desc_array_status_ptr */
00262         /* SQLUINTEGER *row_operation_ptr; */
00263         /* ird->sql_desc_array_status_ptr */
00264         /* SQLUINTEGER *row_status_ptr; */
00265         /* ird->sql_desc_rows_processed_ptr */
00266         /* SQLUINTEGER *rows_fetched_ptr; */
00267         SQLUINTEGER simulate_cursor;
00268         SQLUINTEGER use_bookmarks;
00269         /* SQLGetStmtAttr only */
00270 /*      TDS_DESC *imp_row_desc; */
00271 /*      TDS_DESC *imp_param_desc; */
00272 };
00273 
00274 struct _hstmt
00275 {
00276         SQLSMALLINT htype;      /* do not reorder this field */
00277         struct _hdbc *dbc;
00278         char *query;
00279         /* begin prepared query stuff */
00280         char *prepared_query;
00282 /*      char *prepared_query_s; */
00284 /*      char *prepared_query_d; */
00285 /*      int prepared_query_need_bytes; */
00286 /*      int prepared_query_param_num; */
00287         int prepared_query_is_func;
00288         int prepared_query_is_rpc;
00289         /* end prepared query stuff */
00290 
00292         TDSPARAMINFO *params;
00294         int param_num;
00295 
00297         unsigned int param_count;
00298         int row;
00300         int row_count;
00301         /* do NOT free dynamic, free from socket or attach to connection */
00302         TDSDYNAMIC *dyn;
00303         struct _sql_errors errs;
00304         TDS_DESC *ard, *ird, *apd, *ipd;
00305         TDS_DESC *orig_ard, *orig_apd;
00306         SQLUINTEGER sql_rowset_size;
00307         struct _hsattr attr;
00308         DSTR cursor_name;       /* auto generated cursor name */
00309 #ifdef TDS_NO_DM
00310         SQLINTEGER cursor_state;        /* 1 if cursor is open, 0 if cursor is closed */
00311 #define TDS_CURSOR_CLOSED     0
00312 #define TDS_CURSOR_OPEN               1
00313 #endif
00314 };
00315 
00316 typedef struct _henv TDS_ENV;
00317 typedef struct _hdbc TDS_DBC;
00318 typedef struct _hstmt TDS_STMT;
00319 typedef struct _hchk TDS_CHK;
00320 
00321 #define IS_HENV(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_ENV)
00322 #define IS_HDBC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DBC)
00323 #define IS_HSTMT(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_STMT)
00324 #define IS_HDESC(x) (((TDS_CHK *)x)->htype == SQL_HANDLE_DESC)
00325 
00326 TDS_DESC *desc_alloc(SQLHDESC parent, int desc_type, int alloc_type);
00327 SQLRETURN desc_free(TDS_DESC * desc);
00328 SQLRETURN desc_alloc_records(TDS_DESC * desc, unsigned count);
00329 SQLRETURN desc_copy(TDS_DESC * dest, TDS_DESC * src);
00330 SQLRETURN desc_free_records(TDS_DESC * desc);
00331 
00332 /* fix a buf in MingW headers */
00333 #ifdef __MINGW32__
00334 #if SQL_INTERVAL_YEAR == (100 + SQL_CODE_SECOND)
00335 
00336 #undef SQL_INTERVAL_YEAR
00337 #undef SQL_INTERVAL_MONTH
00338 #undef SQL_INTERVAL_DAY
00339 #undef SQL_INTERVAL_HOUR
00340 #undef SQL_INTERVAL_MINUTE
00341 #undef SQL_INTERVAL_SECOND
00342 #undef SQL_INTERVAL_YEAR_TO_MONTH
00343 #undef SQL_INTERVAL_DAY_TO_HOUR
00344 #undef SQL_INTERVAL_DAY_TO_MINUTE
00345 #undef SQL_INTERVAL_DAY_TO_SECOND
00346 #undef SQL_INTERVAL_HOUR_TO_MINUTE
00347 #undef SQL_INTERVAL_HOUR_TO_SECOND
00348 #undef SQL_INTERVAL_MINUTE_TO_SECOND
00349 
00350 #define SQL_INTERVAL_YEAR                                       (100 + SQL_CODE_YEAR)
00351 #define SQL_INTERVAL_MONTH                                      (100 + SQL_CODE_MONTH)
00352 #define SQL_INTERVAL_DAY                                        (100 + SQL_CODE_DAY)
00353 #define SQL_INTERVAL_HOUR                                       (100 + SQL_CODE_HOUR)
00354 #define SQL_INTERVAL_MINUTE                                     (100 + SQL_CODE_MINUTE)
00355 #define SQL_INTERVAL_SECOND                     (100 + SQL_CODE_SECOND)
00356 #define SQL_INTERVAL_YEAR_TO_MONTH                      (100 + SQL_CODE_YEAR_TO_MONTH)
00357 #define SQL_INTERVAL_DAY_TO_HOUR                        (100 + SQL_CODE_DAY_TO_HOUR)
00358 #define SQL_INTERVAL_DAY_TO_MINUTE                      (100 + SQL_CODE_DAY_TO_MINUTE)
00359 #define SQL_INTERVAL_DAY_TO_SECOND                      (100 + SQL_CODE_DAY_TO_SECOND)
00360 #define SQL_INTERVAL_HOUR_TO_MINUTE                     (100 + SQL_CODE_HOUR_TO_MINUTE)
00361 #define SQL_INTERVAL_HOUR_TO_SECOND                     (100 + SQL_CODE_HOUR_TO_SECOND)
00362 #define SQL_INTERVAL_MINUTE_TO_SECOND           (100 + SQL_CODE_MINUTE_TO_SECOND)
00363 
00364 #endif
00365 #endif
00366 
00367 #ifdef __cplusplus
00368 #if 0
00369 {
00370 #endif
00371 }
00372 #endif
00373 
00374 #endif

Generated on Sun Jun 13 18:55:26 2004 for FreeTDS API by doxygen1.3