FreeTDS API
ctlib.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Brian Bruns
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _tdsguard_gH4tOYBTzynx4DgqFzOEbB_
21 #define _tdsguard_gH4tOYBTzynx4DgqFzOEbB_
22 
23 #include <freetds/tds.h>
24 #include <freetds/convert.h>
25 #include <freetds/utils/string.h>
26 #include <freetds/bool.h>
27 
28 /*
29  * Internal (not part of the exposed API) prototypes and such.
30  */
31 
32 #include <freetds/pushvis.h>
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0
38 }
39 #endif
40 #endif
41 
42 /* Fix a problem with Windows headers */
43 #undef small
44 
45 /*
46  * internal types
47  */
48 struct _cs_config
49 {
50  bool cs_expose_formats;
51  bool cs_note_empty_data;
52 };
53 
54 /* Code changed for error handling */
55 /* Code changes starts here - CT_DIAG - 01 */
56 
57 /* This structure is used in CT_DIAG */
58 
60 {
61  struct cs_diag_msg_client *next;
62  CS_CLIENTMSG clientmsg;
63 };
64 
65 typedef struct {
66  CS_MSGNUM msgnumber;
67  CS_INT state;
68  CS_INT severity;
69  CS_CHAR text[CS_MAX_MSG];
70  CS_INT textlen;
71  CS_CHAR svrname[132];
72  CS_INT svrnlen;
73  CS_CHAR proc[132];
74  CS_INT proclen;
75  CS_INT line;
76  CS_INT status;
77  CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
78  CS_INT sqlstatelen;
80 
81 typedef struct {
82  CS_MSGNUM msgnumber;
83  CS_INT state;
84  CS_INT severity;
85  CS_CHAR text[CS_MAX_MSG];
86  CS_INT textlen;
87  CS_CHAR svrname[256];
88  CS_INT svrnlen;
89  CS_CHAR proc[256];
90  CS_INT proclen;
91  CS_INT line;
92  CS_INT status;
93  CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
94  CS_INT sqlstatelen;
96 
97 typedef struct {
98  CS_MSGNUM msgnumber;
99  CS_INT state;
100  CS_INT severity;
101  CS_CHAR text[CS_MAX_MSG];
102  CS_INT textlen;
104 
105 typedef struct {
106  CS_INT line;
107  CS_INT status;
108  CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
109  CS_INT sqlstatelen;
111 
112 typedef union
113 {
114  CS_SERVERMSG_SMALL small;
115  CS_SERVERMSG_LARGE large;
116  CS_SERVERMSG_COMMON1 common;
117  CS_SERVERMSG user;
119 
121 {
122  struct cs_diag_msg_svr *next;
123  CS_SERVERMSG_INTERNAL servermsg;
124 };
125 
126 /* Code changes ends here - CT_DIAG - 01 */
127 
129 {
130  CS_CLIENTMSG *msg;
131  struct cs_diag_msg *next;
132 };
133 
135 {
136  CS_INT date_convert_fmt;
137  CS_INT cs_errhandletype;
138  CS_INT cs_diag_msglimit;
139 
140  /* added for storing the maximum messages limit CT_DIAG */
141  /* code changes starts here - CT_DIAG - 02 */
142 
143  CS_INT cs_diag_msglimit_client;
144  CS_INT cs_diag_msglimit_server;
145  CS_INT cs_diag_msglimit_total;
146  struct cs_diag_msg_client *clientstore;
147  struct cs_diag_msg_svr *svrstore;
148 
149  /* code changes ends here - CT_DIAG - 02 */
150 
151  struct cs_diag_msg *msgstore;
152  CS_CSLIBMSG_FUNC cslibmsg_cb;
153  CS_CLIENTMSG_FUNC clientmsg_cb;
154  CS_SERVERMSG_FUNC servermsg_cb;
155  CS_INTERRUPT_FUNC interrupt_cb;
156  /* code changes start here - CS_CONFIG - 01*/
157  void *userdata;
158  int userdata_len;
159  /* code changes end here - CS_CONFIG - 01*/
160  TDSCONTEXT *tds_ctx;
161  CS_CONFIG config;
167 };
168 
169 static inline size_t cs_servermsg_len(CS_CONTEXT *ctx)
170 {
171  if (ctx->use_large_identifiers)
172  return sizeof(CS_SERVERMSG_LARGE);
173  return sizeof(CS_SERVERMSG_SMALL);
174 }
175 
176 /*
177  * internal typedefs
178  */
179 typedef struct _ct_colinfo
180 {
181  TDS_SMALLINT *indicator;
182 }
183 CT_COLINFO;
184 
185 typedef struct _cs_dynamic CS_DYNAMIC;
186 
188 {
189  CS_CONTEXT *ctx;
192  CS_CLIENTMSG_FUNC clientmsg_cb;
193  CS_SERVERMSG_FUNC servermsg_cb;
194  CS_INTERRUPT_FUNC interrupt_cb;
195  void *userdata;
196  int userdata_len;
197  CS_LOCALE *locale;
198  CS_COMMAND *cmds;
199  CS_DYNAMIC *dynlist;
200  char *server_addr;
201  bool network_auth;
202 };
203 
204 /*
205  * Formerly CSREMOTE_PROC_PARAM, this structure can be used in other
206  * places, too.
207  */
208 
209 typedef struct _cs_param
210 {
211  struct _cs_param *next;
212  char *name;
213  int status;
214  int datatype;
215  CS_INT maxlen;
216  CS_INT scale;
217  CS_INT precision;
218  CS_INT *datalen;
219  CS_SMALLINT *ind;
220  CS_BYTE *value;
221  int param_by_value;
222  CS_INT datalen_value;
223  CS_SMALLINT indicator_value;
224 } CS_PARAM;
225 
226 /*
227  * Code added for RPC functionality - SUHA
228  * RPC Code changes starts here
229  */
230 
232 
233 typedef struct _csremote_proc
234 {
235  char *name;
236  CS_SMALLINT options;
237  CSREMOTE_PROC_PARAM *param_list;
238 } CSREMOTE_PROC;
239 
240 /*
241  * Structure CS_COMMAND changed for RPC functionality -SUHA
242  * Added CSREMOTE_PROC *rpc to CS_COMMAND structure
243  */
244 
245 typedef CS_PARAM CS_DYNAMIC_PARAM;
246 
248 {
249  struct _cs_dynamic *next;
250  char *id;
251  char *stmt;
252  CS_DYNAMIC_PARAM *param_list;
253  TDSDYNAMIC *tdsdyn;
254 };
255 
256 /* specific FreeTDS commands */
257 #define CS_DYNAMIC_CMD 160
258 #define CS_CUR_CMD 161
259 
260 /* values for cs_command.results_state */
261 
262 #define _CS_RES_NONE -1
263 #define _CS_RES_INIT 0
264 #define _CS_RES_RESULTSET_EMPTY 1
265 #define _CS_RES_RESULTSET_ROWS 2
266 #define _CS_RES_STATUS 3
267 #define _CS_RES_CMD_DONE 4
268 #define _CS_RES_CMD_SUCCEED 5
269 #define _CS_RES_END_RESULTS 6
270 #define _CS_RES_DESCRIBE_RESULT 7
271 
272 /* values for cs_command.command_state */
273 
274 #define _CS_COMMAND_IDLE 0
275 #define _CS_COMMAND_BUILDING 1
276 #define _CS_COMMAND_READY 2
277 #define _CS_COMMAND_SENT 3
278 
279 /* values for cs_command.cancel_state */
280 #define _CS_CANCEL_NOCANCEL 0
281 #define _CS_CANCEL_PENDING 1
282 
284 {
285  struct _cs_command *next;
286  CS_INT command_state;
287  CS_INT results_state;
288  CS_INT cancel_state;
289  CS_INT cursor_state;
290  CS_CONNECTION *con;
291  CS_INT command_type;
292  CS_CHAR *query;
293  short dynamic_cmd;
294  CS_DYNAMIC *dyn;
295  int row_prefetched;
296  int curr_result_type;
297  int bind_count;
298  int get_data_item;
299  int get_data_bytes_returned;
300  CS_IODESC *iodesc;
301  CS_INT send_data_started;
302  CSREMOTE_PROC *rpc;
303  CS_PARAM *input_params;
304  CS_INT client_cursor_id;
305  TDSCURSOR *cursor;
306  void *userdata;
307  int userdata_len;
308 };
309 
311 {
312  TDSBCPINFO bcpinfo;
313 };
314 
315 
316 #define _CS_ERRHAND_INLINE 1
317 #define _CS_ERRHAND_CB 2
318 
320 {
321  char *language;
322  char *charset;
323  char *time;
324  char *collate;
325 };
326 
327 /* internal defines for cursor processing */
328 
329 #define _CS_CURS_TYPE_UNACTIONED TDS_CURSOR_STATE_UNACTIONED
330 #define _CS_CURS_TYPE_REQUESTED TDS_CURSOR_STATE_REQUESTED
331 #define _CS_CURS_TYPE_SENT TDS_CURSOR_STATE_SENT
332 
333 typedef struct {
334  CS_CHAR name[132];
335  CS_INT namelen;
336  CS_INT datatype;
337  CS_INT format;
338  CS_INT maxlength;
339  CS_INT scale;
340  CS_INT precision;
341  CS_INT status;
342  CS_INT count;
343  CS_INT usertype;
344  CS_LOCALE *locale;
346 
347 typedef struct {
348  CS_CHAR name[256];
349  CS_INT namelen;
350  CS_INT datatype;
351  CS_INT format;
352  CS_INT maxlength;
353  CS_INT scale;
354  CS_INT precision;
355  CS_INT status;
356  CS_INT count;
357  CS_INT usertype;
358  CS_LOCALE *locale;
360 
361 typedef struct {
362  CS_INT datatype;
363  CS_INT format;
364  CS_INT maxlength;
365  CS_INT scale;
366  CS_INT precision;
367  CS_INT status;
368  CS_INT count;
369  CS_INT usertype;
370  CS_LOCALE *locale;
372 
373 typedef union
374 {
375  CS_DATAFMT_SMALL small;
376  CS_DATAFMT_LARGE large;
377  CS_DATAFMT user;
379 
380 #if ENABLE_EXTRA_CHECKS
381 #define CS_QUERY_HAS_FOR_UPDATE 9500
382 #endif
383 
384 /*
385  * internal prototypes
386  */
387 TDSRET _ct_handle_server_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
388 int _ct_handle_client_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
389 int _ct_handle_interrupt(void * ptr);
390 TDS_SERVER_TYPE _ct_get_server_type(TDSSOCKET *tds, int datatype);
391 int _ct_bind_data(CS_CONTEXT *ctx, TDSRESULTINFO * resinfo, TDSRESULTINFO *bindinfo, CS_INT offset);
392 int _ct_get_client_type(const TDSCOLUMN *col, bool describe);
393 void _ctclient_msg(CS_CONTEXT *ctx, CS_CONNECTION * con, const char *funcname,
394  int layer, int origin, int severity, int number,
395  const char *fmt, ...);
396 CS_INT _ct_diag_clearmsg(CS_CONTEXT * context, CS_INT type);
397 void _cs_locale_free(CS_LOCALE *locale);
398 CS_LOCALE *_cs_locale_copy(CS_LOCALE *orig);
399 int _cs_locale_copy_inplace(CS_LOCALE *new_locale, CS_LOCALE *orig);
400 CS_INT _ct_get_string_length(const char *buf, CS_INT buflen);
401 
402 int _cs_convert_not_client(CS_CONTEXT *ctx, const TDSCOLUMN *curcol, CONV_RESULT *convert_buffer, unsigned char **p_src);
403 
404 CS_RETCODE _cs_convert(CS_CONTEXT * ctx, const CS_DATAFMT_COMMON * srcfmt, CS_VOID * srcdata,
405  const CS_DATAFMT_COMMON * destfmt, CS_VOID * destdata, CS_INT * resultlen, TDS_SERVER_TYPE desttype);
406 bool _ct_is_large_identifiers_version(CS_INT version);
407 const CS_DATAFMT_COMMON * _ct_datafmt_common(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt);
408 const CS_DATAFMT_LARGE *_ct_datafmt_conv_in(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
409 CS_DATAFMT_LARGE *_ct_datafmt_conv_prepare(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
410 void _ct_datafmt_conv_back(CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
411 
412 CS_RETCODE _ct_props_dstr(CS_CONNECTION * con, DSTR *s, CS_INT action, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
413 
414 #ifdef __cplusplus
415 #if 0
416 {
417 #endif
418 }
419 #endif
420 
421 #include <freetds/popvis.h>
422 
423 #endif
Definition: ctlib.h:134
Definition: ctlib.h:112
Definition: tds.h:1022
Definition: cstypes.h:118
Definition: ctlib.h:319
Definition: tds.h:1697
Definition: ctlib.h:247
Definition: convert.h:33
Definition: ctlib.h:187
Information for a server connection.
Definition: tds.h:1170
Definition: ctlib.h:347
Definition: cstypes.h:101
Definition: ctlib.h:310
int login_timeout
not used unless positive
Definition: ctlib.h:162
Definition: cstypes.h:199
Structure to hold a string.
Definition: string.h:37
Holds information about a cursor.
Definition: tds.h:928
bool use_large_identifiers
structures uses large identifiers
Definition: ctlib.h:166
Definition: tds.h:867
Definition: ctlib.h:373
Metadata about columns in regular and compute rows.
Definition: tds.h:680
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:969
Definition: ctlib.h:81
Definition: ctlib.h:48
Definition: ctlib.h:128
Definition: ctlib.h:105
int query_timeout
not used unless positive
Definition: ctlib.h:163
Definition: ctlib.h:233
Definition: tds.h:501
Definition: ctlib.h:179
Definition: ctlib.h:333
Definition: ctlib.h:65
Definition: ctlib.h:283
Definition: cstypes.h:185
Definition: ctlib.h:120
Hold information for any results.
Definition: tds.h:760
Definition: ctlib.h:361
Definition: ctlib.h:97
Definition: ctlib.h:59
Main include file for libtds.
Definition: ctlib.h:209