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 _ctlib_h_
21#define _ctlib_h_
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 short cs_expose_formats;
51};
52
53/* Code changed for error handling */
54/* Code changes starts here - CT_DIAG - 01 */
55
56/* This structure is used in CT_DIAG */
57
58 struct cs_diag_msg_client
59{
60 struct cs_diag_msg_client *next;
61 CS_CLIENTMSG clientmsg;
62};
63
64 typedef struct {
65 CS_MSGNUM msgnumber;
66 CS_INT state;
67 CS_INT severity;
68 CS_CHAR text[CS_MAX_MSG];
69 CS_INT textlen;
70 CS_CHAR svrname[132];
71 CS_INT svrnlen;
72 CS_CHAR proc[132];
73 CS_INT proclen;
74 CS_INT line;
75 CS_INT status;
76 CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
77 CS_INT sqlstatelen;
78} CS_SERVERMSG_SMALL;
79
80 typedef struct {
81 CS_MSGNUM msgnumber;
82 CS_INT state;
83 CS_INT severity;
84 CS_CHAR text[CS_MAX_MSG];
85 CS_INT textlen;
86 CS_CHAR svrname[256];
87 CS_INT svrnlen;
88 CS_CHAR proc[256];
89 CS_INT proclen;
90 CS_INT line;
91 CS_INT status;
92 CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
93 CS_INT sqlstatelen;
94} CS_SERVERMSG_LARGE;
95
96 typedef struct {
97 CS_MSGNUM msgnumber;
98 CS_INT state;
99 CS_INT severity;
100 CS_CHAR text[CS_MAX_MSG];
101 CS_INT textlen;
102} CS_SERVERMSG_COMMON1;
103
104 typedef struct {
105 CS_INT line;
106 CS_INT status;
107 CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
108 CS_INT sqlstatelen;
109} CS_SERVERMSG_COMMON2;
110
111 typedef union
112{
113 CS_SERVERMSG_SMALL small;
114 CS_SERVERMSG_LARGE large;
115 CS_SERVERMSG_COMMON1 common;
116 CS_SERVERMSG user;
117} CS_SERVERMSG_INTERNAL;
118
119 struct cs_diag_msg_svr
120{
121 struct cs_diag_msg_svr *next;
122 CS_SERVERMSG_INTERNAL servermsg;
123};
124
125/* Code changes ends here - CT_DIAG - 01 */
126
127 struct cs_diag_msg
128{
129 CS_CLIENTMSG *msg;
130 struct cs_diag_msg *next;
131};
132
133 struct _cs_context
134{
135 CS_INT date_convert_fmt;
136 CS_INT cs_errhandletype;
137 CS_INT cs_diag_msglimit;
138
139 /* added for storing the maximum messages limit CT_DIAG */
140 /* code changes starts here - CT_DIAG - 02 */
141
142 CS_INT cs_diag_msglimit_client;
143 CS_INT cs_diag_msglimit_server;
144 CS_INT cs_diag_msglimit_total;
145 struct cs_diag_msg_client *clientstore;
146 struct cs_diag_msg_svr *svrstore;
147
148 /* code changes ends here - CT_DIAG - 02 */
149
150 struct cs_diag_msg *msgstore;
151 CS_CSLIBMSG_FUNC _cslibmsg_cb;
152 CS_CLIENTMSG_FUNC _clientmsg_cb;
153 CS_SERVERMSG_FUNC _servermsg_cb;
154 /* code changes start here - CS_CONFIG - 01*/
155 void *userdata;
156 int userdata_len;
157 /* code changes end here - CS_CONFIG - 01*/
158 TDSCONTEXT *tds_ctx;
159 CS_CONFIG config;
160 int login_timeout;
161 int query_timeout;
164 bool use_large_identifiers;
165};
166
167 static inline size_t cs_servermsg_len(CS_CONTEXT *ctx)
168{
169 if (ctx->use_large_identifiers)
170 return sizeof(CS_SERVERMSG_LARGE);
171 return sizeof(CS_SERVERMSG_SMALL);
172}
173
174/*
175 * internal typedefs
176 */
177 typedef struct _ct_colinfo
178{
179 TDS_SMALLINT *indicator;
180}
181 CT_COLINFO;
182
183 typedef struct _cs_dynamic CS_DYNAMIC;
184
185 struct _cs_connection
186{
187 CS_CONTEXT *ctx;
188 TDSLOGIN *tds_login;
189 TDSSOCKET *tds_socket;
190 CS_CLIENTMSG_FUNC _clientmsg_cb;
191 CS_SERVERMSG_FUNC _servermsg_cb;
192 void *userdata;
193 int userdata_len;
194 CS_LOCALE *locale;
195 CS_COMMAND *cmds;
196 CS_DYNAMIC *dynlist;
197 char *server_addr;
198 bool network_auth;
199};
200
201/*
202 * Formerly CSREMOTE_PROC_PARAM, this structure can be used in other
203 * places, too.
204 */
205
206 typedef struct _cs_param
207{
208 struct _cs_param *next;
209 char *name;
210 int status;
211 int datatype;
212 CS_INT maxlen;
213 CS_INT scale;
214 CS_INT precision;
215 CS_INT *datalen;
216 CS_SMALLINT *ind;
217 CS_BYTE *value;
218 int param_by_value;
219 CS_INT datalen_value;
220 CS_SMALLINT indicator_value;
221} CS_PARAM;
222
223/*
224 * Code added for RPC functionality - SUHA
225 * RPC Code changes starts here
226 */
227
228 typedef CS_PARAM CSREMOTE_PROC_PARAM;
229
230 typedef struct _csremote_proc
231{
232 char *name;
233 CS_SMALLINT options;
234 CSREMOTE_PROC_PARAM *param_list;
235} CSREMOTE_PROC;
236
237/*
238 * Structure CS_COMMAND changed for RPC functionality -SUHA
239 * Added CSREMOTE_PROC *rpc to CS_COMMAND structure
240 */
241
242 typedef CS_PARAM CS_DYNAMIC_PARAM;
243
244 struct _cs_dynamic
245{
246 struct _cs_dynamic *next;
247 char *id;
248 char *stmt;
249 CS_DYNAMIC_PARAM *param_list;
250 TDSDYNAMIC *tdsdyn;
251};
252
253/* specific FreeTDS commands */
254#define CS_DYNAMIC_CMD 160
255#define CS_CUR_CMD 161
256
257/* values for cs_command.results_state */
258
259#define _CS_RES_NONE -1
260#define _CS_RES_INIT 0
261#define _CS_RES_RESULTSET_EMPTY 1
262#define _CS_RES_RESULTSET_ROWS 2
263#define _CS_RES_STATUS 3
264#define _CS_RES_CMD_DONE 4
265#define _CS_RES_CMD_SUCCEED 5
266#define _CS_RES_END_RESULTS 6
267#define _CS_RES_DESCRIBE_RESULT 7
268
269/* values for cs_command.command_state */
270
271#define _CS_COMMAND_IDLE 0
272#define _CS_COMMAND_BUILDING 1
273#define _CS_COMMAND_READY 2
274#define _CS_COMMAND_SENT 3
275
276/* values for cs_command.cancel_state */
277#define _CS_CANCEL_NOCANCEL 0
278#define _CS_CANCEL_PENDING 1
279
280 struct _cs_command
281{
282 struct _cs_command *next;
283 CS_INT command_state;
284 CS_INT results_state;
285 CS_INT cancel_state;
286 CS_INT cursor_state;
287 CS_CONNECTION *con;
288 CS_INT command_type;
289 CS_CHAR *query;
290 short dynamic_cmd;
291 CS_DYNAMIC *dyn;
292 int row_prefetched;
293 int curr_result_type;
294 int bind_count;
295 int get_data_item;
296 int get_data_bytes_returned;
297 CS_IODESC *iodesc;
298 CS_INT send_data_started;
299 CSREMOTE_PROC *rpc;
300 CS_PARAM *input_params;
301 CS_INT client_cursor_id;
302 TDSCURSOR *cursor;
303 void *userdata;
304 int userdata_len;
305};
306
307 struct _cs_blkdesc
308{
309 TDSBCPINFO bcpinfo;
310};
311
312
313#define _CS_ERRHAND_INLINE 1
314#define _CS_ERRHAND_CB 2
315
316 struct _cs_locale
317{
318 char *language;
319 char *charset;
320 char *time;
321 char *collate;
322};
323
324/* internal defines for cursor processing */
325
326#define _CS_CURS_TYPE_UNACTIONED 0
327#define _CS_CURS_TYPE_REQUESTED 1
328#define _CS_CURS_TYPE_SENT 2
329
330 typedef struct {
331 CS_CHAR name[132];
332 CS_INT namelen;
333 CS_INT datatype;
334 CS_INT format;
335 CS_INT maxlength;
336 CS_INT scale;
337 CS_INT precision;
338 CS_INT status;
339 CS_INT count;
340 CS_INT usertype;
341 CS_LOCALE *locale;
342} CS_DATAFMT_SMALL;
343
344 typedef struct {
345 CS_CHAR name[256];
346 CS_INT namelen;
347 CS_INT datatype;
348 CS_INT format;
349 CS_INT maxlength;
350 CS_INT scale;
351 CS_INT precision;
352 CS_INT status;
353 CS_INT count;
354 CS_INT usertype;
355 CS_LOCALE *locale;
356} CS_DATAFMT_LARGE;
357
358 typedef struct {
359 CS_INT datatype;
360 CS_INT format;
361 CS_INT maxlength;
362 CS_INT scale;
363 CS_INT precision;
364 CS_INT status;
365 CS_INT count;
366 CS_INT usertype;
367 CS_LOCALE *locale;
368} CS_DATAFMT_COMMON;
369
370 typedef union
371{
372 CS_DATAFMT_SMALL small;
373 CS_DATAFMT_LARGE large;
374 CS_DATAFMT user;
375} CS_DATAFMT_INTERNAL;
376
377/*
378 * internal prototypes
379 */
380TDSRET _ct_handle_server_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
381 int _ct_handle_client_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
382TDS_SERVER_TYPE _ct_get_server_type(TDSSOCKET *tds, int datatype);
383 int _ct_bind_data(CS_CONTEXT *ctx, TDSRESULTINFO * resinfo, TDSRESULTINFO *bindinfo, CS_INT offset);
384 int _ct_get_client_type(const TDSCOLUMN *col, bool describe);
385 void _ctclient_msg(CS_CONNECTION * con, const char *funcname, int layer, int origin, int severity, int number,
386 const char *fmt, ...);
387CS_INT _ct_diag_clearmsg(CS_CONTEXT * context, CS_INT type);
388 void _cs_locale_free(CS_LOCALE *locale);
389 CS_LOCALE *_cs_locale_copy(CS_LOCALE *orig);
390 int _cs_locale_copy_inplace(CS_LOCALE *new_locale, CS_LOCALE *orig);
391
392 int _cs_convert_not_client(CS_CONTEXT *ctx, const TDSCOLUMN *curcol, CONV_RESULT *convert_buffer, unsigned char **p_src);
393
394CS_RETCODE _cs_convert(CS_CONTEXT * ctx, const CS_DATAFMT_COMMON * srcfmt, CS_VOID * srcdata,
395 const CS_DATAFMT_COMMON * destfmt, CS_VOID * destdata, CS_INT * resultlen);
396 bool _ct_is_large_identifiers_version(CS_INT version);
397 const CS_DATAFMT_COMMON * _ct_datafmt_common(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt);
398 const CS_DATAFMT_LARGE *_ct_datafmt_conv_in(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
399 CS_DATAFMT_LARGE *_ct_datafmt_conv_prepare(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
400 void _ct_datafmt_conv_back(CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
401
402#ifdef __cplusplus
403#if 0
404{
405#endif
406}
407#endif
408
409#include <freetds/popvis.h>
410
411#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:59
CS_SERVERMSG_SMALL
Definition ctlib.h:64
CS_SERVERMSG_LARGE
Definition ctlib.h:80
CS_SERVERMSG_COMMON1
Definition ctlib.h:96
CS_SERVERMSG_COMMON2
Definition ctlib.h:104
CS_SERVERMSG_INTERNAL
Definition ctlib.h:112
cs_diag_msg_svr
Definition ctlib.h:120
cs_diag_msg
Definition ctlib.h:128
_cs_context
Definition ctlib.h:134
_cs_context::login_timeout
int login_timeout
not used unless positive
Definition ctlib.h:160
_cs_context::use_large_identifiers
bool use_large_identifiers
structures uses large identifiers
Definition ctlib.h:164
_cs_context::query_timeout
int query_timeout
not used unless positive
Definition ctlib.h:161
_ct_colinfo
Definition ctlib.h:178
_cs_connection
Definition ctlib.h:186
_cs_param
Definition ctlib.h:207
_csremote_proc
Definition ctlib.h:231
_cs_dynamic
Definition ctlib.h:245
_cs_command
Definition ctlib.h:281
_cs_blkdesc
Definition ctlib.h:308
_cs_locale
Definition ctlib.h:317
CS_DATAFMT_SMALL
Definition ctlib.h:330
CS_DATAFMT_LARGE
Definition ctlib.h:344
CS_DATAFMT_COMMON
Definition ctlib.h:358
CS_DATAFMT_INTERNAL
Definition ctlib.h:371
conv_result
Definition convert.h:34
tds_login
Definition tds.h:518
tds_column
Metadata about columns in regular and compute rows.
Definition tds.h:693
tds_result_info
Hold information for any results.
Definition tds.h:773
tds_message
Definition tds.h:880
tds_cursor
Holds informations about a cursor.
Definition tds.h:941
tds_dynamic
Holds information for a dynamic (also called prepared) query.
Definition tds.h:981
tds_context
Definition tds.h:1033
tds_socket
Information for a server connection.
Definition tds.h:1180
tds_bcpinfo
Definition tds.h:1700