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