# dblib.h

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  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 _dblib_h_
    00021 #define _dblib_h_
    00022
    00023 #if defined(__GNUC__) && __GNUC__ >= 4
    00024 #pragma GCC visibility push(hidden)
    00025 #endif
    00026
    00027 #ifdef __cplusplus
    00028 extern "C"
    00029 {
    00030 #if 0
    00031 }
    00032 #endif
    00033 #endif
    00034
    00035 /* $Id: dblib.h,v 1.43 2007/12/05 03:04:11 jklowden Exp $ */
    00036
    00037 enum {
    00038           _DB_RES_INIT            = 0
    00039         , _DB_RES_RESULTSET_EMPTY = 1
    00040         , _DB_RES_RESULTSET_ROWS  = 2
    00041         , _DB_RES_NEXT_RESULT     = 3
    00042         , _DB_RES_NO_MORE_RESULTS = 4
    00043         , _DB_RES_SUCCEED         = 5
    00044 };
    00045
    00046 struct tds_dblib_loginrec
    00047 {
    00048         TDSLOGIN *tds_login;
    00049 };
    00050
    00051 struct dblib_buffer_row;
    00052
    00053 typedef struct tag_DBPROC_ROWBUF
    00054 {
    00055         int received;           /* how many rows have been received for this result set */
    00056         int head;               /* queue insertion point */
    00057         int tail;               /* oldest item in queue */
    00058         int current;            /* dbnextrow() reads this row */
    00059         int capacity;           /* how many elements the queue can hold  */
    00060         struct dblib_buffer_row *rows;          /* pointer to the row storage */
    00061 } DBPROC_ROWBUF;
    00062
    00063 typedef struct
    00064 {
    00065         int host_column;
    00066         int datatype;
    00067         int prefix_len;
    00068         DBINT column_len;
    00069         BYTE *terminator;
    00070         int term_len;
    00071         int tab_colnum;
    00072         int column_error;
    00073         BCPCOLDATA *bcp_column_data;
    00074 } BCP_HOSTCOLINFO;
    00075
    00076 typedef struct
    00077 {
    00078         TDS_CHAR *hostfile;
    00079         TDS_CHAR *errorfile;
    00080         FILE *bcp_errfileptr;
    00081         TDS_INT host_colcount;
    00082         BCP_HOSTCOLINFO **host_columns;
    00083         TDS_INT firstrow;
    00084         TDS_INT lastrow;
    00085         TDS_INT maxerrs;
    00086         TDS_INT batch;
    00087 } BCP_HOSTFILEINFO;
    00088
    00089 typedef struct
    00090 {
    00091         const char *hint;
    00092         TDS_CHAR *tablename;
    00093         TDS_CHAR *insert_stmt;
    00094         TDS_INT direction;
    00095         TDS_INT queryout;
    00096         TDS_INT identity_insert_on;
    00097         TDS_INT xfer_init;
    00098         TDS_INT var_cols;
    00099         TDS_INT bind_count;
    00100         TDSRESULTINFO *bindinfo;
    00101 } DB_BCPINFO;
    00102 /* linked list of rpc parameters */
    00103
    00104 typedef struct _DBREMOTE_PROC_PARAM
    00105 {
    00106         struct _DBREMOTE_PROC_PARAM *next;
    00107
    00108         char *name;
    00109         BYTE status;
    00110         int type;
    00111         DBINT maxlen;
    00112         DBINT datalen;
    00113         BYTE *value;
    00114 } DBREMOTE_PROC_PARAM;
    00115
    00116 typedef struct _DBREMOTE_PROC
    00117 {
    00118         struct _DBREMOTE_PROC *next;
    00119
    00120         char *name;
    00121         DBSMALLINT options;
    00122         DBREMOTE_PROC_PARAM *param_list;
    00123 } DBREMOTE_PROC;
    00124
    00125 #define MAXOPTTEXT    32
    00126
    00127 struct dboption
    00128 {
    00129         char text[MAXOPTTEXT];
    00130         DBSTRING *param;
    00131         DBBOOL factive;
    00132 };
    00133 typedef struct dboption DBOPTION;
    00134
    00135 typedef struct _null_representation
    00136 {
    00137         const BYTE *bindval;
    00138         size_t len;
    00139 } NULLREP;
    00140
    00141 struct tds_dblib_dbprocess
    00142 {
    00143         TDSSOCKET *tds_socket;
    00144
    00145         TDS_INT row_type;
    00146         DBPROC_ROWBUF row_buf;
    00147
    00148         int noautofree;
    00149         int more_results;       /* boolean.  Are we expecting results? */
    00150         int dbresults_state;
    00151         int dbresults_retcode;
    00152         BYTE *user_data;        /* see dbsetuserdata() and dbgetuserdata() */
    00153         unsigned char *dbbuf;   /* is dynamic!                   */
    00154         int dbbufsz;
    00155         int command_state;
    00156         TDS_INT text_size;
    00157         TDS_INT text_sent;
    00158         DBTYPEINFO typeinfo;
    00159         unsigned char avail_flag;
    00160         DBOPTION *dbopts;
    00161         DBSTRING *dboptcmd;
    00162         BCP_HOSTFILEINFO *hostfileinfo;
    00163         DB_BCPINFO *bcpinfo;
    00164         DBREMOTE_PROC *rpc;
    00165         DBUSMALLINT envchange_rcv;
    00166         char dbcurdb[DBMAXNAME + 1];
    00167         char servcharset[DBMAXNAME + 1];
    00168         FILE *ftos;
    00169         DB_DBCHKINTR_FUNC chkintr;
    00170         DB_DBHNDLINTR_FUNC hndlintr;
    00171
    00173         int msdblib;
    00174
    00175         int ntimeouts;
    00176
    00178         NULLREP         nullreps[MAXBINDTYPES];
    00179 };
    00180
    00181 /*
    00182  * internal prototypes
    00183  */
    00184 int dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum, ...);
    00185 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
    00186 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
    00187 int _dblib_check_and_handle_interrupt(void * vdbproc);
    00188
    00189 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
    00190
    00191 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
    00192 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
    00193
    00194 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
    00195 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
    00196
    00197 extern MHANDLEFUNC _dblib_msg_handler;
    00198 extern EHANDLEFUNC _dblib_err_handler;
    00199
    00200 #define CHECK_PARAMETER(x, msg, ret)    if (!(x)) { dbperror(dbproc, (msg), 0); return ret; }
    00201 #define CHECK_DBPROC() CHECK_PARAMETER(dbproc, SYBENULL, FAIL)
    00202 #define CHECK_NULP(x, func, param_num, ret)     if (!(x)) { dbperror(dbproc, SYBENULP, 0, func, (int) param_num); return ret; }
    00203 #define CHECK_PARAMETER_NOPROC(x, msg)  if (!(x)) { dbperror(NULL, (msg), 0); return FAIL; }
    00204 #define DBPERROR_RETURN(x, msg) if (x) { dbperror(dbproc, (msg), 0); return FAIL; }
    00205 #define DBPERROR_RETURN3(x, msg, a, b, c)       if (x) { dbperror(dbproc, (msg), 0, a, b, c); return FAIL; }
    00206
    00207
    00208 #ifdef __cplusplus
    00209 #if 0
    00210 {
    00211 #endif
    00212 }
    00213 #endif
    00214
    00215 #if defined(__GNUC__) && __GNUC__ >= 4
    00216 #pragma GCC visibility pop
    00217 #endif
    00218
    00219 #endif