FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 #if defined(__GNUC__) && __GNUC__ >= 4
24 #pragma GCC visibility push(hidden)
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #if 0
31 }
32 #endif
33 #endif
34 
35 /* $Id: dblib.h,v 1.43 2007/12/05 03:04:11 jklowden Exp $ */
36 
37 enum {
38  _DB_RES_INIT = 0
39  , _DB_RES_RESULTSET_EMPTY = 1
40  , _DB_RES_RESULTSET_ROWS = 2
41  , _DB_RES_NEXT_RESULT = 3
42  , _DB_RES_NO_MORE_RESULTS = 4
43  , _DB_RES_SUCCEED = 5
44 };
45 
47 {
49 };
50 
51 struct dblib_buffer_row;
52 
53 typedef struct tag_DBPROC_ROWBUF
54 {
55  int received; /* how many rows have been received for this result set */
56  int head; /* queue insertion point */
57  int tail; /* oldest item in queue */
58  int current; /* dbnextrow() reads this row */
59  int capacity; /* how many elements the queue can hold */
60  struct dblib_buffer_row *rows; /* pointer to the row storage */
62 
63 typedef struct
64 {
65  int host_column;
66  int datatype;
67  int prefix_len;
68  DBINT column_len;
69  BYTE *terminator;
70  int term_len;
71  int tab_colnum;
72  int column_error;
73  BCPCOLDATA *bcp_column_data;
75 
76 typedef struct
77 {
78  TDS_CHAR *hostfile;
79  TDS_CHAR *errorfile;
80  FILE *bcp_errfileptr;
81  TDS_INT host_colcount;
82  BCP_HOSTCOLINFO **host_columns;
83  TDS_INT firstrow;
84  TDS_INT lastrow;
85  TDS_INT maxerrs;
86  TDS_INT batch;
88 
89 typedef struct
90 {
91  const char *hint;
92  TDS_CHAR *tablename;
93  TDS_CHAR *insert_stmt;
94  TDS_INT direction;
95  TDS_INT queryout;
96  TDS_INT identity_insert_on;
97  TDS_INT xfer_init;
98  TDS_INT var_cols;
99  TDS_INT bind_count;
100  TDSRESULTINFO *bindinfo;
101 } DB_BCPINFO;
102 /* linked list of rpc parameters */
103 
104 typedef struct _DBREMOTE_PROC_PARAM
105 {
106  struct _DBREMOTE_PROC_PARAM *next;
107 
108  char *name;
109  BYTE status;
110  int type;
111  DBINT maxlen;
112  DBINT datalen;
113  BYTE *value;
115 
116 typedef struct _DBREMOTE_PROC
117 {
118  struct _DBREMOTE_PROC *next;
119 
120  char *name;
121  DBSMALLINT options;
122  DBREMOTE_PROC_PARAM *param_list;
123 } DBREMOTE_PROC;
124 
125 #define MAXOPTTEXT 32
126 
127 struct dboption
128 {
129  char text[MAXOPTTEXT];
130  DBSTRING *param;
131  DBBOOL factive;
132 };
133 typedef struct dboption DBOPTION;
134 
135 typedef struct _null_representation
136 {
137  const BYTE *bindval;
138  size_t len;
139 } NULLREP;
140 
142 {
144 
145  TDS_INT row_type;
146  DBPROC_ROWBUF row_buf;
147 
148  int noautofree;
149  int more_results; /* boolean. Are we expecting results? */
150  int dbresults_state;
151  int dbresults_retcode;
152  BYTE *user_data; /* see dbsetuserdata() and dbgetuserdata() */
153  unsigned char *dbbuf; /* is dynamic! */
154  int dbbufsz;
155  int command_state;
156  TDS_INT text_size;
157  TDS_INT text_sent;
158  DBTYPEINFO typeinfo;
159  unsigned char avail_flag;
160  DBOPTION *dbopts;
161  DBSTRING *dboptcmd;
162  BCP_HOSTFILEINFO *hostfileinfo;
163  DB_BCPINFO *bcpinfo;
164  DBREMOTE_PROC *rpc;
165  DBUSMALLINT envchange_rcv;
166  char dbcurdb[DBMAXNAME + 1];
167  char servcharset[DBMAXNAME + 1];
168  FILE *ftos;
169  DB_DBCHKINTR_FUNC chkintr;
170  DB_DBHNDLINTR_FUNC hndlintr;
171 
173  int msdblib;
174 
175  int ntimeouts;
176 
178  NULLREP nullreps[MAXBINDTYPES];
179 };
180 
181 /*
182  * internal prototypes
183  */
184 int dbperror (DBPROCESS *dbproc, DBINT msgno, long errnum, ...);
185 int _dblib_handle_info_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
186 int _dblib_handle_err_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE* msgptr);
187 int _dblib_check_and_handle_interrupt(void * vdbproc);
188 
189 void _dblib_setTDS_version(TDSLOGIN * tds_login, DBINT version);
190 
191 DBINT _convert_char(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
192 DBINT _convert_intn(int srctype, BYTE * src, int destype, BYTE * dest, DBINT destlen);
193 
194 RETCODE _bcp_clear_storage(DBPROCESS * dbproc);
195 RETCODE _bcp_get_prog_data(DBPROCESS * dbproc);
196 
197 extern MHANDLEFUNC _dblib_msg_handler;
198 extern EHANDLEFUNC _dblib_err_handler;
199 
200 #define CHECK_PARAMETER(x, msg, ret) if (!(x)) { dbperror(dbproc, (msg), 0); return ret; }
201 #define CHECK_DBPROC() CHECK_PARAMETER(dbproc, SYBENULL, FAIL)
202 #define CHECK_NULP(x, func, param_num, ret) if (!(x)) { dbperror(dbproc, SYBENULP, 0, func, (int) param_num); return ret; }
203 #define CHECK_PARAMETER_NOPROC(x, msg) if (!(x)) { dbperror(NULL, (msg), 0); return FAIL; }
204 #define DBPERROR_RETURN(x, msg) if (x) { dbperror(dbproc, (msg), 0); return FAIL; }
205 #define DBPERROR_RETURN3(x, msg, a, b, c) if (x) { dbperror(dbproc, (msg), 0, a, b, c); return FAIL; }
206 
207 
208 #ifdef __cplusplus
209 #if 0
210 {
211 #endif
212 }
213 #endif
214 
215 #if defined(__GNUC__) && __GNUC__ >= 4
216 #pragma GCC visibility pop
217 #endif
218 
219 #endif
Definition: dblib.h:53
Definition: dblib.h:46
NULLREP nullreps[MAXBINDTYPES]
default null values
Definition: dblib.h:178
Definition: dblib.h:89
int msdblib
boolean use ms behaviour
Definition: dblib.h:173
Definition: buffering.h:1
Definition: tds.h:1245
Definition: tds.h:1102
Definition: dblib.h:141
Definition: dblib.h:104
Definition: tds.h:934
Hold information for a server connection.
Definition: tds.h:1276
Definition: tds.h:821
int dbperror(DBPROCESS *dbproc, DBINT msgno, long errnum,...)
Call client-installed error handler.
Definition: dblib.c:7769
Definition: dblib.h:76
Hold information for any results.
Definition: tds.h:1026
Definition: dblib.h:135
Definition: sybdb.h:277
Definition: dblib.h:127
Definition: dblib.h:63
Definition: dblib.h:116
int _dblib_check_and_handle_interrupt(void *vdbproc)
check interrupts for libtds.
Definition: dbutil.c:203
Definition: sybdb.h:283