FreeTDS API

Loading...
Searching...
No Matches
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
59 struct cs_diag_msg_client
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;
79} CS_SERVERMSG_SMALL;
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;
95} CS_SERVERMSG_LARGE;
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;
103} CS_SERVERMSG_COMMON1;
104
105 typedef struct {
106 CS_INT line;
107 CS_INT status;
108 CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
109 CS_INT sqlstatelen;
110} CS_SERVERMSG_COMMON2;
111
112 typedef union
113{
114 CS_SERVERMSG_SMALL small;
115 CS_SERVERMSG_LARGE large;
116 CS_SERVERMSG_COMMON1 common;
117 CS_SERVERMSG user;
118} CS_SERVERMSG_INTERNAL;
119
120 struct cs_diag_msg_svr
121{
122 struct cs_diag_msg_svr *next;
123 CS_SERVERMSG_INTERNAL servermsg;
124};
125
126/* Code changes ends here - CT_DIAG - 01 */
127
128 struct cs_diag_msg
129{
130 CS_CLIENTMSG *msg;
131 struct cs_diag_msg *next;
132};
133
134 struct _cs_context
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;
162 int login_timeout;
163 int query_timeout;
166 bool use_large_identifiers;
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
187 struct _cs_connection
188{
189 CS_CONTEXT *ctx;
190 TDSLOGIN *tds_login;
191 TDSSOCKET *tds_socket;
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
231 typedef CS_PARAM CSREMOTE_PROC_PARAM;
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
247 struct _cs_dynamic
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
283 struct _cs_command
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
310 struct _cs_blkdesc
311{
312 TDSBCPINFO bcpinfo;
313};
314
315
316#define _CS_ERRHAND_INLINE 1
317#define _CS_ERRHAND_CB 2
318
319 struct _cs_locale
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 0
330#define _CS_CURS_TYPE_REQUESTED 1
331#define _CS_CURS_TYPE_SENT 2
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;
345} CS_DATAFMT_SMALL;
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;
359} CS_DATAFMT_LARGE;
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;
371} CS_DATAFMT_COMMON;
372
373 typedef union
374{
375 CS_DATAFMT_SMALL small;
376 CS_DATAFMT_LARGE large;
377 CS_DATAFMT user;
378} CS_DATAFMT_INTERNAL;
379
380/*
381 * internal prototypes
382 */
383TDSRET _ct_handle_server_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
384 int _ct_handle_client_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
385 int _ct_handle_interrupt(void * ptr);
386TDS_SERVER_TYPE _ct_get_server_type(TDSSOCKET *tds, int datatype);
387 int _ct_bind_data(CS_CONTEXT *ctx, TDSRESULTINFO * resinfo, TDSRESULTINFO *bindinfo, CS_INT offset);
388 int _ct_get_client_type(const TDSCOLUMN *col, bool describe);
389 void _ctclient_msg(CS_CONTEXT *ctx, CS_CONNECTION * con, const char *funcname,
390 int layer, int origin, int severity, int number,
391 const char *fmt, ...);
392CS_INT _ct_diag_clearmsg(CS_CONTEXT * context, CS_INT type);
393 void _cs_locale_free(CS_LOCALE *locale);
394 CS_LOCALE *_cs_locale_copy(CS_LOCALE *orig);
395 int _cs_locale_copy_inplace(CS_LOCALE *new_locale, CS_LOCALE *orig);
396CS_INT _ct_get_string_length(const char *buf, CS_INT buflen);
397
398 int _cs_convert_not_client(CS_CONTEXT *ctx, const TDSCOLUMN *curcol, CONV_RESULT *convert_buffer, unsigned char **p_src);
399
400CS_RETCODE _cs_convert(CS_CONTEXT * ctx, const CS_DATAFMT_COMMON * srcfmt, CS_VOID * srcdata,
401 const CS_DATAFMT_COMMON * destfmt, CS_VOID * destdata, CS_INT * resultlen, TDS_SERVER_TYPE desttype);
402 bool _ct_is_large_identifiers_version(CS_INT version);
403 const CS_DATAFMT_COMMON * _ct_datafmt_common(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt);
404 const CS_DATAFMT_LARGE *_ct_datafmt_conv_in(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
405 CS_DATAFMT_LARGE *_ct_datafmt_conv_prepare(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
406 void _ct_datafmt_conv_back(CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
407
408CS_RETCODE _ct_props_dstr(CS_CONNECTION * con, DSTR *s, CS_INT action, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
409
410#ifdef __cplusplus
411#if 0
412{
413#endif
414}
415#endif
416
417#include <freetds/popvis.h>
418
419#endif
tds.h
Main include file for libtds.
_cs_iodesc
Definition cstypes.h:102
_cs_datafmt
Definition cstypes.h:119
_cs_clientmsg
Definition cstypes.h:186
_cs_servermsg
Definition cstypes.h:200
_cs_config
Definition ctlib.h:49
cs_diag_msg_client
Definition ctlib.h:60
CS_SERVERMSG_SMALL
Definition ctlib.h:65
CS_SERVERMSG_LARGE
Definition ctlib.h:81
CS_SERVERMSG_COMMON1
Definition ctlib.h:97
CS_SERVERMSG_COMMON2
Definition ctlib.h:105
CS_SERVERMSG_INTERNAL
Definition ctlib.h:113
cs_diag_msg_svr
Definition ctlib.h:121
cs_diag_msg
Definition ctlib.h:129
_cs_context
Definition ctlib.h:135
_cs_context::login_timeout
int login_timeout
not used unless positive
Definition ctlib.h:162
_cs_context::use_large_identifiers
bool use_large_identifiers
structures uses large identifiers
Definition ctlib.h:166
_cs_context::query_timeout
int query_timeout
not used unless positive
Definition ctlib.h:163
_ct_colinfo
Definition ctlib.h:180
_cs_connection
Definition ctlib.h:188
_cs_param
Definition ctlib.h:210
_csremote_proc
Definition ctlib.h:234
_cs_dynamic
Definition ctlib.h:248
_cs_command
Definition ctlib.h:284
_cs_blkdesc
Definition ctlib.h:311
_cs_locale
Definition ctlib.h:320
CS_DATAFMT_SMALL
Definition ctlib.h:333
CS_DATAFMT_LARGE
Definition ctlib.h:347
CS_DATAFMT_COMMON
Definition ctlib.h:361
CS_DATAFMT_INTERNAL
Definition ctlib.h:374
conv_result
Definition convert.h:34
tds_login
Definition tds.h:498
tds_column
Metadata about columns in regular and compute rows.
Definition tds.h:674
tds_result_info
Hold information for any results.
Definition tds.h:754
tds_message
Definition tds.h:861
tds_cursor
Holds information about a cursor.
Definition tds.h:922
tds_dynamic
Holds information for a dynamic (also called prepared) query.
Definition tds.h:962
tds_context
Definition tds.h:1015
tds_socket
Information for a server connection.
Definition tds.h:1163
tds_bcpinfo
Definition tds.h:1684
tds_dstr
Structure to hold a string.
Definition string.h:36