FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dblib.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 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 _dblib_h_
21 #define _dblib_h_
22
23 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
24 #pragma GCC visibility push(hidden)
25 #endif
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #if 0
31 }
32 #endif
33 #endif
34
35 /* $Id: dblib.h,v 1.46 2010-01-25 23:05:58 freddy77 Exp $ */
36
37 typedef enum tag_DB_RESULT_STATE {
38 _DB_RES_INIT
39 , _DB_RES_RESULTSET_EMPTY
40 , _DB_RES_RESULTSET_ROWS
41 , _DB_RES_NEXT_RESULT
42 , _DB_RES_NO_MORE_RESULTS
43 , _DB_RES_SUCCEED
44 } DB_RESULT_STATE;
45
46 struct tds_dblib_loginrec
47 {
48 TDSLOGIN *tds_login;
49 };
50
51 struct dblib_buffer_row;
52
53 typedef struct tag_DBPROC_ROWBUF
54 {
55 int received; /* how many rows have been received for this result set */
56 int head; /* queue insertion point */
57 int tail; /* oldest item in queue */
58 int current; /* dbnextrow() reads this row */
59 int capacity; /* how many elements the queue can hold */
60 struct dblib_buffer_row *rows; /* pointer to the row storage */
61 } DBPROC_ROWBUF;
62
63 typedef struct
64 {
65 int host_column;
66 int datatype;
67 int prefix_len;
68 DBINT column_len;
69 BYTE *terminator;
70 int term_len;
71 int tab_colnum;
72 int column_error;
73 BCPCOLDATA *bcp_column_data;
74 } BCP_HOSTCOLINFO;
75
76 typedef struct
77 {
78 TDS_CHAR *hostfile;
79 TDS_CHAR *errorfile;
80 FILE *bcp_errfileptr;
81 TDS_INT host_colcount;
82 BCP_HOSTCOLINFO **host_columns;
83 TDS_INT firstrow;
84 TDS_INT lastrow;
85 TDS_INT maxerrs;
86 TDS_INT batch;
87 } BCP_HOSTFILEINFO;
88
89 /* linked list of rpc parameters */
90
91 typedef struct _DBREMOTE_PROC_PARAM
92 {
93 struct _DBREMOTE_PROC_PARAM *next;
94
95 char *name;
96 BYTE status;
97 int type;
98 DBINT maxlen;
99 DBINT datalen;
100 BYTE *value;
101 } DBREMOTE_PROC_PARAM;
102
103 typedef struct _DBREMOTE_PROC
104 {
105 struct _DBREMOTE_PROC *next;
106
107 char *name;
108 DBSMALLINT options;
109 DBREMOTE_PROC_PARAM *param_list;
110 } DBREMOTE_PROC;
111
112 #define MAXOPTTEXT 32
113
114 struct dboption
115 {
116 char text[MAXOPTTEXT];
117 DBSTRING *param;
118 DBBOOL factive;
119 };
120 typedef struct dboption DBOPTION;
121
122 typedef struct _null_representation
123 {
124 const BYTE *bindval;
125 size_t len;
126 } NULLREP;
127
128 struct tds_dblib_dbprocess
129 {
130 TDSSOCKET *tds_socket;
131
132 TDS_INT row_type;
133 DBPROC_ROWBUF row_buf;
134
135 int noautofree;
136 int more_results; /* boolean. Are we expecting results? */
137 DB_RESULT_STATE dbresults_state;
138 int dbresults_retcode;
139 BYTE *user_data; /* see dbsetuserdata() and dbgetuserdata() */
140 unsigned char *dbbuf; /* is dynamic! */
141 int dbbufsz;
142 int command_state;
143 TDS_INT text_size;
144 TDS_INT text_sent;
145 DBTYPEINFO typeinfo;
146 unsigned char avail_flag;
147 DBOPTION *dbopts;
148 DBSTRING *dboptcmd;
149 BCP_HOSTFILEINFO *hostfileinfo;
150 TDSBCPINFO *bcpinfo;
151 DBREMOTE_PROC *rpc;
152 DBUSMALLINT envchange_rcv;
153 char dbcurdb[DBMAXNAME + 1];
154 char servcharset[DBMAXNAME + 1];
155 FILE *ftos;
156 DB_DBCHKINTR_FUNC chkintr;
157 DB_DBHNDLINTR_FUNC hndlintr;
158
160 int msdblib;
161
162 int ntimeouts;
163
165 NULLREP nullreps[MAXBINDTYPES];
166 };
167
168 /*
169 * internal prototypes
170 */
171 int dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum, ...);
172 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
173 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
174 int _dblib_check_and_handle_interrupt(void * vdbproc);
175
176 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
177
178 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
179 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
180
181 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
182 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
183
184 extern MHANDLEFUNC _dblib_msg_handler;
185 extern EHANDLEFUNC _dblib_err_handler;
186
187 #define CHECK_PARAMETER(x, msg, ret) if (!(x)) { dbperror(dbproc, (msg), 0); return ret; }
188 #define CHECK_DBPROC() CHECK_PARAMETER(dbproc, SYBENULL, FAIL)
189 #define CHECK_NULP(x, func, param_num, ret) if (!(x)) { dbperror(dbproc, SYBENULP, 0, func, (int) param_num); return ret; }
190 #define CHECK_PARAMETER_NOPROC(x, msg) if (!(x)) { dbperror(NULL, (msg), 0); return FAIL; }
191 #define DBPERROR_RETURN(x, msg) if (x) { dbperror(dbproc, (msg), 0); return FAIL; }
192 #define DBPERROR_RETURN3(x, msg, a, b, c) if (x) { dbperror(dbproc, (msg), 0, a, b, c); return FAIL; }
193
194
195 #ifdef __cplusplus
196 #if 0
197 {
198 #endif
199 }
200 #endif
201
202 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
203 #pragma GCC visibility pop
204 #endif
205
206 #endif