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