FreeTDS API

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 #include <freetds/pushvis.h>
24
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #if 0
29 }
30 #endif
31 #endif
32
33 typedef enum tag_DB_RESULT_STATE {
34 _DB_RES_INIT
35 , _DB_RES_RESULTSET_EMPTY
36 , _DB_RES_RESULTSET_ROWS
37 , _DB_RES_NEXT_RESULT
38 , _DB_RES_NO_MORE_RESULTS
39 , _DB_RES_SUCCEED
40 } DB_RESULT_STATE;
41
42 struct tds_dblib_loginrec
43 {
44 TDSLOGIN *tds_login;
45 };
46
47 struct dblib_buffer_row;
48
49 typedef struct tag_DBPROC_ROWBUF
50 {
51 int received; /* how many rows have been received for this result set */
52 int head; /* queue insertion point */
53 int tail; /* oldest item in queue */
54 int current; /* dbnextrow() reads this row */
55 int capacity; /* how many elements the queue can hold */
56 struct dblib_buffer_row *rows; /* pointer to the row storage */
57 } DBPROC_ROWBUF;
58
59 typedef struct
60 {
61 int host_column;
62 TDS_SERVER_TYPE datatype;
63 int prefix_len;
64 DBINT column_len;
65 BYTE *terminator;
66 int term_len;
67 int tab_colnum;
68 int column_error;
69 } BCP_HOSTCOLINFO;
70
71 typedef struct
72 {
73 TDS_CHAR *hostfile;
74 TDS_CHAR *errorfile;
75 FILE *bcp_errfileptr;
76 TDS_INT host_colcount;
77 BCP_HOSTCOLINFO **host_columns;
78 TDS_INT firstrow;
79 TDS_INT lastrow;
80 TDS_INT maxerrs;
81 TDS_INT batch;
82 } BCP_HOSTFILEINFO;
83
84 /* linked list of rpc parameters */
85
86 typedef struct _DBREMOTE_PROC_PARAM
87 {
88 struct _DBREMOTE_PROC_PARAM *next;
89
90 char *name;
91 BYTE status;
92 TDS_SERVER_TYPE type;
93 DBINT maxlen;
94 DBINT datalen;
95 BYTE *value;
96 } DBREMOTE_PROC_PARAM;
97
98 typedef struct _DBREMOTE_PROC
99 {
100 struct _DBREMOTE_PROC *next;
101
102 char *name;
103 DBSMALLINT options;
104 DBREMOTE_PROC_PARAM *param_list;
105 } DBREMOTE_PROC;
106
107 typedef struct dboption
108 {
109 const char *text;
110 DBSTRING *param;
111 DBBOOL factive;
112 } DBOPTION;
113
114 typedef struct _null_representation
115 {
116 const BYTE *bindval;
117 size_t len;
118 } NULLREP;
119
120 struct tds_dblib_dbprocess
121 {
122 TDSSOCKET *tds_socket;
123
124 STATUS row_type;
125 DBPROC_ROWBUF row_buf;
126
127 int noautofree;
128 int more_results; /* boolean. Are we expecting results? */
129 DB_RESULT_STATE dbresults_state;
130 int dbresults_retcode;
131 BYTE *user_data; /* see dbsetuserdata() and dbgetuserdata() */
132 unsigned char *dbbuf; /* is dynamic! */
133 int dbbufsz;
134 int command_state;
135 TDS_INT text_size;
136 TDS_INT text_sent;
137 DBTYPEINFO typeinfo;
138 unsigned char avail_flag;
139 DBOPTION *dbopts;
140 DBSTRING *dboptcmd;
141 BCP_HOSTFILEINFO *hostfileinfo;
142 TDSBCPINFO *bcpinfo;
143 DBREMOTE_PROC *rpc;
144 DBUSMALLINT envchange_rcv;
145 char dbcurdb[DBMAXNAME + 1];
146 char servcharset[DBMAXNAME + 1];
147 FILE *ftos;
148 DB_DBCHKINTR_FUNC chkintr;
149 DB_DBHNDLINTR_FUNC hndlintr;
150
152 int msdblib;
153
154 int ntimeouts;
155
157 NULLREP nullreps[MAXBINDTYPES];
158 };
159
160 enum {
161 #if MSDBLIB
162 dblib_msdblib = 1
163 #else
164 dblib_msdblib = 0
165 #endif
166 };
167
168 /*
169 * internal prototypes
170 */
171 RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE* varaddr);
172 void copy_data_to_host_var(DBPROCESS * dbproc, TDS_SERVER_TYPE srctype, const BYTE * src, DBINT srclen,
173 BYTE * dest, DBINT destlen,
174 int bindtype, DBINT *indicator);
175
176 int dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum, ...);
177 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
178 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
179 int _dblib_check_and_handle_interrupt(void * vdbproc);
180
181 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
182 void _dblib_convert_err(DBPROCESS * dbproc, TDS_INT len);
183
184 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
185 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
186
187 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
188 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
189
190 extern MHANDLEFUNC _dblib_msg_handler;
191 extern EHANDLEFUNC _dblib_err_handler;
192
193 #define CHECK_PARAMETER(x, msg, ret) if (!(x)) { dbperror(dbproc, (msg), 0); return ret; }
194 #define CHECK_NULP(x, func, param_num, ret) if (!(x)) { dbperror(dbproc, SYBENULP, 0, func, (int) param_num); return ret; }
195 #define CHECK_PARAMETER_NOPROC(x, msg) if (!(x)) { dbperror(NULL, (msg), 0); return FAIL; }
196 #define DBPERROR_RETURN(x, msg) if (x) { dbperror(dbproc, (msg), 0); return FAIL; }
197 #define DBPERROR_RETURN3(x, msg, a, b, c) if (x) { dbperror(dbproc, (msg), 0, a, b, c); return FAIL; }
198 #define CHECK_CONN(ret) do { CHECK_PARAMETER(dbproc, SYBENULL, (ret)); \
199 if (IS_TDSDEAD(dbproc->tds_socket)) { dbperror(dbproc, SYBEDDNE, 0); return (ret); } } while(0)
200
201
202 #ifdef __cplusplus
203 #if 0
204 {
205 #endif
206 }
207 #endif
208
209 #include <freetds/popvis.h>
210
211 #endif
tds_bcpinfo
Definition: tds.h:1606
dboption
Definition: dblib.h:107
dbstring
Definition: sybdb.h:341
tds_context
Definition: tds.h:1063
tds_dblib_dbprocess
Definition: dblib.h:120
tds_socket
Information for a server connection.
Definition: tds.h:1175
_dblib_check_and_handle_interrupt
int _dblib_check_and_handle_interrupt(void *vdbproc)
check interrupts for libtds.
Definition: dbutil.c:191
tds_login
Definition: tds.h:549
dbgetnull
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:540
dbperror
int dbperror(DBPROCESS *dbproc, DBINT msgno, long errnum,...)
Call client-installed error handler.
Definition: dblib.c:7969
BCP_HOSTFILEINFO
Definition: dblib.h:71
dblib_buffer_row
Definition: buffering.h:1
tds_dblib_loginrec
Definition: dblib.h:42
tds_dblib_dbprocess::msdblib
int msdblib
boolean use ms behaviour
Definition: dblib.h:152
_DBREMOTE_PROC
Definition: dblib.h:98
BCP_HOSTCOLINFO
Definition: dblib.h:59
dbtypeinfo
Definition: sybdb.h:335
tds_message
Definition: tds.h:910
_null_representation
Definition: dblib.h:114
_DBREMOTE_PROC_PARAM
Definition: dblib.h:86
tag_DBPROC_ROWBUF
Definition: dblib.h:49