FreeTDS API: include/dblib.h Source File

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