# ctlib.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 _ctlib_h_
    00021 #define _ctlib_h_
    00022
    00023 /*
    00024  * Internal (not part of the exposed API) prototypes and such.
    00025  */
    00026
    00027 #if defined(__GNUC__) && __GNUC__ >= 4
    00028 #pragma GCC visibility push(hidden)
    00029 #endif
    00030
    00031 #ifdef __cplusplus
    00032 extern "C"
    00033 {
    00034 #if 0
    00035 }
    00036 #endif
    00037 #endif
    00038
    00039 static const char rcsid_ctlib_h[] = "$Id: ctlib.h,v 1.25 2007/06/25 09:48:20 freddy77 Exp $";
    00040 static const void *const no_unused_ctlib_h_warn[] = { rcsid_ctlib_h, no_unused_ctlib_h_warn };
    00041
    00042 #include <tds.h>
    00043 /*
    00044  * internal types
    00045  */
    00046 struct _cs_config
    00047 {
    00048         short cs_expose_formats;
    00049 };
    00050
    00051 /* Code changed for error handling */
    00052 /* Code changes starts here - CT_DIAG - 01 */
    00053
    00054 /* This structure is used in CT_DIAG */
    00055
    00056 struct cs_diag_msg_client
    00057 {
    00058         CS_CLIENTMSG *clientmsg;
    00059         struct cs_diag_msg_client *next;
    00060 };
    00061
    00062 struct cs_diag_msg_svr
    00063 {
    00064         CS_SERVERMSG *servermsg;
    00065         struct cs_diag_msg_svr *next;
    00066 };
    00067
    00068 /* Code changes ends here - CT_DIAG - 01 */
    00069
    00070 struct cs_diag_msg
    00071 {
    00072         CS_CLIENTMSG *msg;
    00073         struct cs_diag_msg *next;
    00074 };
    00075
    00076 struct _cs_context
    00077 {
    00078         CS_INT date_convert_fmt;
    00079         CS_INT cs_errhandletype;
    00080         CS_INT cs_diag_msglimit;
    00081
    00082         /* added for storing the maximum messages limit CT_DIAG */
    00083         /* code changes starts here - CT_DIAG - 02 */
    00084
    00085         CS_INT cs_diag_msglimit_client;
    00086         CS_INT cs_diag_msglimit_server;
    00087         CS_INT cs_diag_msglimit_total;
    00088         struct cs_diag_msg_client *clientstore;
    00089         struct cs_diag_msg_svr *svrstore;
    00090
    00091         /* code changes ends here - CT_DIAG - 02 */
    00092
    00093         struct cs_diag_msg *msgstore;
    00094         CS_CSLIBMSG_FUNC _cslibmsg_cb;
    00095         CS_CLIENTMSG_FUNC _clientmsg_cb;
    00096         CS_SERVERMSG_FUNC _servermsg_cb;
    00097         /* code changes start here - CS_CONFIG - 01*/
    00098         void *userdata;
    00099         int userdata_len;
    00100         /* code changes end here - CS_CONFIG - 01*/
    00101         TDSCONTEXT *tds_ctx;
    00102         CS_CONFIG config;
    00103 };
    00104
    00105 /*
    00106  * internal typedefs
    00107  */
    00108 typedef struct _ct_colinfo
    00109 {
    00110         TDS_SMALLINT *indicator;
    00111 }
    00112 CT_COLINFO;
    00113
    00114 typedef struct _cs_command_list CS_COMMAND_LIST;
    00115 typedef struct _cs_dynamic CS_DYNAMIC_LIST;
    00116 typedef struct _cs_dynamic CS_DYNAMIC;
    00117
    00118 struct _cs_connection
    00119 {
    00120         CS_CONTEXT *ctx;
    00121         TDSLOGIN *tds_login;
    00122         TDSSOCKET *tds_socket;
    00123         CS_CLIENTMSG_FUNC _clientmsg_cb;
    00124         CS_SERVERMSG_FUNC _servermsg_cb;
    00125         void *userdata;
    00126         int userdata_len;
    00127         CS_LOCALE *locale;
    00128         CS_COMMAND_LIST *cmds;
    00129         CS_DYNAMIC_LIST *dynlist;
    00130 };
    00131
    00132 /*
    00133  * Formerly CSREMOTE_PROC_PARAM, this structure can be used in other
    00134  * places, too.
    00135  */
    00136
    00137 typedef struct _cs_param
    00138 {
    00139         struct _cs_param *next;
    00140         char *name;
    00141         int status;
    00142         int type;
    00143         CS_INT maxlen;
    00144         CS_INT scale;
    00145         CS_INT precision;
    00146         CS_INT *datalen;
    00147         CS_SMALLINT *ind;
    00148         CS_BYTE *value;
    00149         int param_by_value;
    00150         CS_INT datalen_value;
    00151         CS_SMALLINT indicator_value;
    00152 } CS_PARAM;
    00153
    00154 /*
    00155  * Code added for RPC functionality - SUHA
    00156  * RPC Code changes starts here
    00157  */
    00158
    00159 typedef CS_PARAM CSREMOTE_PROC_PARAM;
    00160
    00161 typedef struct _csremote_proc
    00162 {
    00163         char *name;
    00164         CS_SMALLINT options;
    00165         CSREMOTE_PROC_PARAM *param_list;
    00166 } CSREMOTE_PROC;
    00167
    00168 /*
    00169  * Structure CS_COMMAND changed for RPC functionality -SUHA
    00170  * Added CSREMOTE_PROC *rpc to CS_COMMAND structure
    00171  */
    00172
    00173 typedef CS_PARAM CS_DYNAMIC_PARAM;
    00174
    00175 struct _cs_dynamic
    00176 {
    00177         char *id;
    00178         char *stmt;
    00179         CS_DYNAMIC_PARAM *param_list;
    00180         struct _cs_dynamic *next;
    00181 };
    00182
    00183 /* specific FreeTDS commands */
    00184 #define CS_DYNAMIC_CMD   160
    00185 #define CS_CUR_CMD       161
    00186
    00187 /* values for cs_command.results_state */
    00188
    00189 #define _CS_RES_NONE            -1
    00190 #define _CS_RES_INIT            0
    00191 #define _CS_RES_RESULTSET_EMPTY 1
    00192 #define _CS_RES_RESULTSET_ROWS  2
    00193 #define _CS_RES_STATUS          3
    00194 #define _CS_RES_CMD_DONE        4
    00195 #define _CS_RES_CMD_SUCCEED     5
    00196 #define _CS_RES_END_RESULTS     6
    00197 #define _CS_RES_DESCRIBE_RESULT 7
    00198
    00199 /* values for cs_command.command_state */
    00200
    00201 #define _CS_COMMAND_IDLE        0
    00202 #define _CS_COMMAND_BUILDING    1
    00203 #define _CS_COMMAND_READY       2
    00204 #define _CS_COMMAND_SENT        3
    00205
    00206 /* values for cs_command.cancel_state */
    00207 #define _CS_CANCEL_NOCANCEL     0
    00208 #define _CS_CANCEL_PENDING      1
    00209
    00210 struct _cs_command
    00211 {
    00212         CS_INT command_state;
    00213         CS_INT results_state;
    00214         CS_INT cancel_state;
    00215         CS_INT cursor_state;
    00216         CS_CONNECTION *con;
    00217         CS_INT command_type;
    00218         CS_CHAR *query;
    00219         short dynamic_cmd;
    00220         CS_DYNAMIC *dyn;
    00221         int row_prefetched;
    00222         int curr_result_type;
    00223         int bind_count;
    00224         int get_data_item;
    00225         int get_data_bytes_returned;
    00226         CS_IODESC *iodesc;
    00227         CS_INT send_data_started;
    00228         CSREMOTE_PROC *rpc;
    00229         CS_PARAM *input_params;
    00230         CS_INT client_cursor_id;
    00231         TDSCURSOR *cursor;
    00232         void *userdata;
    00233         int userdata_len;
    00234 };
    00235
    00236 struct _cs_command_list
    00237 {
    00238         struct _cs_command *cmd;
    00239         struct _cs_command_list *next;
    00240 };
    00241
    00242 struct _cs_blkdesc
    00243 {
    00244         CS_CONNECTION *con;
    00245         CS_CHAR *tablename;
    00246         CS_CHAR *insert_stmt;
    00247         CS_INT direction;
    00248         CS_INT identity_insert_on;
    00249         CS_INT bind_count;
    00250         CS_INT xfer_init;
    00251         CS_INT var_cols;
    00252         TDSRESULTINFO *bindinfo;
    00253 };
    00254
    00255
    00256 #define _CS_ERRHAND_INLINE 1
    00257 #define _CS_ERRHAND_CB     2
    00258
    00259 struct _cs_locale
    00260 {
    00261         char *language;
    00262         char *charset;
    00263         char *time;
    00264         char *collate;
    00265 };
    00266
    00267 /* internal defines for cursor processing */
    00268
    00269 #define _CS_CURS_TYPE_UNACTIONED 0
    00270 #define _CS_CURS_TYPE_REQUESTED  1
    00271 #define _CS_CURS_TYPE_SENT       2
    00272
    00273 /*
    00274  * internal prototypes
    00275  */
    00276 int _ct_handle_server_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
    00277 int _ct_handle_client_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
    00278 int _ct_get_server_type(int datatype);
    00279 int _ct_bind_data(CS_CONTEXT *ctx, TDSRESULTINFO * resinfo, TDSRESULTINFO *bindinfo, CS_INT offset);
    00280 int _ct_get_client_type(int datatype, int usertype, int size);
    00281 void _ctclient_msg(CS_CONNECTION * con, const char *funcname, int layer, int origin, int severity, int number,
    00282                    const char *fmt, ...);
    00283 CS_INT _ct_diag_clearmsg(CS_CONTEXT * context, CS_INT type);
    00284 void _cs_locale_free(CS_LOCALE *locale);
    00285 CS_LOCALE *_cs_locale_copy(CS_LOCALE *orig);
    00286 int _cs_locale_copy_inplace(CS_LOCALE *new_locale, CS_LOCALE *orig);
    00287
    00288 #ifdef __cplusplus
    00289 #if 0
    00290 {
    00291 #endif
    00292 }
    00293 #endif
    00294
    00295 #if defined(__GNUC__) && __GNUC__ >= 4
    00296 #pragma GCC visibility pop
    00297 #endif
    00298
    00299 #endif