# 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 #ifdef __cplusplus
    00024 extern "C"
    00025 {
    00026 #if 0
    00027 }
    00028 #endif
    00029 #endif
    00030
    00031 /* $Id: dblib.h,v 1.31 2005/09/22 14:18:35 freddy77 Exp $ */
    00032
    00033 enum {
    00034           _DB_RES_INIT            = 0
    00035         , _DB_RES_RESULTSET_EMPTY = 1
    00036         , _DB_RES_RESULTSET_ROWS  = 2
    00037         , _DB_RES_NEXT_RESULT     = 3
    00038         , _DB_RES_NO_MORE_RESULTS = 4
    00039         , _DB_RES_SUCCEED         = 5
    00040 };
    00041
    00042 struct tds_dblib_loginrec
    00043 {
    00044         TDSLOGIN *tds_login;
    00045 };
    00046
    00047 struct dblib_buffer_row;
    00048
    00049 typedef struct tag_DBPROC_ROWBUF
    00050 {
    00051         int received;           /* how many rows have been received for this result set */
    00052         int head;               /* queue insertion point */
    00053         int tail;               /* oldest item in queue */
    00054         int current;            /* dbnextrow() reads this row */
    00055         int capacity;           /* how many elements the queue can hold  */
    00056         struct dblib_buffer_row *rows;          /* pointer to the row storage */
    00057 } DBPROC_ROWBUF;
    00058
    00059 typedef struct
    00060 {
    00061         int host_column;
    00062         int datatype;
    00063         int prefix_len;
    00064         DBINT column_len;
    00065         BYTE *terminator;
    00066         int term_len;
    00067         int tab_colnum;
    00068         int column_error;
    00069         BCPCOLDATA *bcp_column_data;
    00070 } BCP_HOSTCOLINFO;
    00071
    00072 typedef struct
    00073 {
    00074         TDS_CHAR *hostfile;
    00075         TDS_CHAR *errorfile;
    00076         FILE *bcp_errfileptr;
    00077         TDS_INT host_colcount;
    00078         BCP_HOSTCOLINFO **host_columns;
    00079         TDS_INT firstrow;
    00080         TDS_INT lastrow;
    00081         TDS_INT maxerrs;
    00082         TDS_INT batch;
    00083 } BCP_HOSTFILEINFO;
    00084
    00085 typedef struct
    00086 {
    00087         char *hint;
    00088         TDS_CHAR *tablename;
    00089         TDS_CHAR *insert_stmt;
    00090         TDS_INT direction;
    00091         TDS_INT queryout;
    00092         TDS_INT identity_insert_on;
    00093         TDS_INT xfer_init;
    00094         TDS_INT var_cols;
    00095         TDS_INT bind_count;
    00096         TDSRESULTINFO *bindinfo;
    00097 } DB_BCPINFO;
    00098 /* linked list of rpc parameters */
    00099
    00100 typedef struct _DBREMOTE_PROC_PARAM
    00101 {
    00102         struct _DBREMOTE_PROC_PARAM *next;
    00103
    00104         char *name;
    00105         BYTE status;
    00106         int type;
    00107         DBINT maxlen;
    00108         DBINT datalen;
    00109         BYTE *value;
    00110 } DBREMOTE_PROC_PARAM;
    00111
    00112 typedef struct _DBREMOTE_PROC
    00113 {
    00114         struct _DBREMOTE_PROC *next;
    00115
    00116         char *name;
    00117         DBSMALLINT options;
    00118         DBREMOTE_PROC_PARAM *param_list;
    00119 } DBREMOTE_PROC;
    00120
    00121 struct tds_dblib_dbprocess
    00122 {
    00123         TDSSOCKET *tds_socket;
    00124
    00125         TDS_INT row_type;
    00126         DBPROC_ROWBUF row_buf;
    00127
    00128         int noautofree;
    00129         int more_results;       /* boolean.  Are we expecting results? */
    00130         int dbresults_state;
    00131         int dbresults_retcode;
    00132         BYTE *user_data;        /* see dbsetuserdata() and dbgetuserdata() */
    00133         unsigned char *dbbuf;   /* is dynamic!                   */
    00134         int dbbufsz;
    00135         int command_state;
    00136         TDS_INT text_size;
    00137         TDS_INT text_sent;
    00138         DBTYPEINFO typeinfo;
    00139         unsigned char avail_flag;
    00140         DBOPTION *dbopts;
    00141         DBSTRING *dboptcmd;
    00142         BCP_HOSTFILEINFO *hostfileinfo;
    00143         DB_BCPINFO *bcpinfo;
    00144         DBREMOTE_PROC *rpc;
    00145         DBUSMALLINT envchange_rcv;
    00146         char dbcurdb[DBMAXNAME + 1];
    00147         char servcharset[DBMAXNAME + 1];
    00148         FILE *ftos;
    00149         DB_DBCHKINTR_FUNC dbchkintr;
    00150         DB_DBHNDLINTR_FUNC dbhndlintr;
    00151
    00153         int msdblib;
    00154
    00155         int ntimeouts;
    00156 };
    00157
    00158 #define DBLIB_INFO_MSG_TYPE 0
    00159 #define DBLIB_ERROR_MSG_TYPE 1
    00160
    00161 /*
    00162  * internal prototypes
    00163  */
    00164 int dbperror (DBPROCESS *dbproc, DBINT msgno, int errnum);
    00165 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
    00166 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
    00167 int _dblib_client_msg(DBPROCESS * dbproc, int dberr, int severity, const char *dberrstr);
    00168 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
    00169
    00170 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
    00171 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
    00172
    00173 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
    00174 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
    00175
    00176 extern MHANDLEFUNC _dblib_msg_handler;
    00177 extern EHANDLEFUNC _dblib_err_handler;
    00178
    00179 #ifdef __cplusplus
    00180 #if 0
    00181 {
    00182 #endif
    00183 }
    00184 #endif
    00185
    00186 #endif