FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 #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 
43 {
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 */
58 
59 typedef struct
60 {
61  int host_column;
62  int datatype;
63  int prefix_len;
64  DBINT column_len;
65  BYTE *terminator;
66  int term_len;
67  int tab_colnum;
68  int column_error;
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;
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  int type;
93  DBINT maxlen;
94  DBINT datalen;
95  BYTE *value;
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 #define MAXOPTTEXT 32
108 
109 struct dboption
110 {
111  char text[MAXOPTTEXT];
112  DBSTRING *param;
113  DBBOOL factive;
114 };
115 typedef struct dboption DBOPTION;
116 
117 typedef struct _null_representation
118 {
119  const BYTE *bindval;
120  size_t len;
121 } NULLREP;
122 
124 {
126 
127  STATUS row_type;
128  DBPROC_ROWBUF row_buf;
129 
130  int noautofree;
131  int more_results; /* boolean. Are we expecting results? */
132  DB_RESULT_STATE dbresults_state;
133  int dbresults_retcode;
134  BYTE *user_data; /* see dbsetuserdata() and dbgetuserdata() */
135  unsigned char *dbbuf; /* is dynamic! */
136  int dbbufsz;
137  int command_state;
138  TDS_INT text_size;
139  TDS_INT text_sent;
140  DBTYPEINFO typeinfo;
141  unsigned char avail_flag;
142  DBOPTION *dbopts;
143  DBSTRING *dboptcmd;
144  BCP_HOSTFILEINFO *hostfileinfo;
145  TDSBCPINFO *bcpinfo;
146  DBREMOTE_PROC *rpc;
147  DBUSMALLINT envchange_rcv;
148  char dbcurdb[DBMAXNAME + 1];
149  char servcharset[DBMAXNAME + 1];
150  FILE *ftos;
151  DB_DBCHKINTR_FUNC chkintr;
152  DB_DBHNDLINTR_FUNC hndlintr;
153 
155  int msdblib;
156 
157  int ntimeouts;
158 
160  NULLREP nullreps[MAXBINDTYPES];
161 };
162 
163 enum {
164 #if MSDBLIB
165  dblib_msdblib = 1
166 #else
167  dblib_msdblib = 0
168 #endif
169 };
170 
171 /*
172  * internal prototypes
173  */
174 RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE* varaddr);
175 void copy_data_to_host_var(DBPROCESS * dbproc, int srctype, const BYTE * src, DBINT srclen,
176  BYTE * dest, DBINT destlen,
177  int bindtype, DBINT *indicator);
178 
179 int dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum, ...);
180 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
181 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
182 int _dblib_check_and_handle_interrupt(void * vdbproc);
183 
184 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
185 void _dblib_convert_err(DBPROCESS * dbproc, TDS_INT len);
186 
187 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
188 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
189 
190 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
191 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
192 
193 extern MHANDLEFUNC _dblib_msg_handler;
194 extern EHANDLEFUNC _dblib_err_handler;
195 
196 #define CHECK_PARAMETER(x, msg, ret) if (!(x)) { dbperror(dbproc, (msg), 0); return ret; }
197 #define CHECK_NULP(x, func, param_num, ret) if (!(x)) { dbperror(dbproc, SYBENULP, 0, func, (int) param_num); return ret; }
198 #define CHECK_PARAMETER_NOPROC(x, msg) if (!(x)) { dbperror(NULL, (msg), 0); return FAIL; }
199 #define DBPERROR_RETURN(x, msg) if (x) { dbperror(dbproc, (msg), 0); return FAIL; }
200 #define DBPERROR_RETURN3(x, msg, a, b, c) if (x) { dbperror(dbproc, (msg), 0, a, b, c); return FAIL; }
201 #define CHECK_CONN(ret) do { CHECK_PARAMETER(dbproc, SYBENULL, (ret)); \
202  if (IS_TDSDEAD(dbproc->tds_socket)) { dbperror(dbproc, SYBEDDNE, 0); return (ret); } } while(0)
203 
204 
205 #ifdef __cplusplus
206 #if 0
207 {
208 #endif
209 }
210 #endif
211 
212 #include <freetds/popvis.h>
213 
214 #endif
Definition: tds.h:1050
Definition: tds.h:897
Definition: tds.h:539
Definition: dblib.h:49
Definition: dblib.h:86
NULLREP nullreps[MAXBINDTYPES]
default null values
Definition: dblib.h:160
Definition: buffering.h:1
Information for a server connection.
Definition: tds.h:1155
Definition: sybdb.h:338
Definition: dblib.h:117
Definition: dblib.h:98
Definition: dblib.h:42
int dbperror(DBPROCESS *dbproc, DBINT msgno, long errnum,...)
Call client-installed error handler.
Definition: dblib.c:7889
Definition: dblib.h:71
int msdblib
boolean use ms behaviour
Definition: dblib.h:155
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:539
Definition: tds.h:1583
Definition: dblib.h:109
int _dblib_check_and_handle_interrupt(void *vdbproc)
check interrupts for libtds.
Definition: dbutil.c:191
Definition: dblib.h:123
Definition: dblib.h:59
Definition: sybdb.h:332