1/*********************************************************************
2 *
3 * This is based on code created by Peter Harvey,
4 * (pharvey@codebydesign.com).
5 *
6 * Modified and extended by Nick Gorham
7 * (nick@lurcher.org).
8 *
9 * Any bugs or problems should be considered the fault of Nick and not
10 * Peter.
11 *
12 * copyright (c) 1999 Nick Gorham
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 **********************************************************************
29 *
30 * $Id: SQLExtendedFetch.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLExtendedFetch.c,v $
33 * Revision 1.6 2009/02/18 17:59:08 lurcher
34 * Shift to using config.h, the compile lines were making it hard to spot warnings
35 *
36 * Revision 1.5 2007/11/29 12:00:30 lurcher
37 * Add 64 bit type changes to SQLExtendedFetch etc
38 *
39 * Revision 1.4 2003/10/30 18:20:45 lurcher
40 *
41 * Fix broken thread protection
42 * Remove SQLNumResultCols after execute, lease S4/S% to driver
43 * Fix string overrun in SQLDriverConnect
44 * Add initial support for Interix
45 *
46 * Revision 1.3 2002/12/05 17:44:30 lurcher
47 *
48 * Display unknown return values in return logging
49 *
50 * Revision 1.2 2001/12/13 13:00:32 lurcher
51 *
52 * Remove most if not all warnings on 64 bit platforms
53 * Add support for new MS 3.52 64 bit changes
54 * Add override to disable the stopping of tracing
55 * Add MAX_ROWS support in postgres driver
56 *
57 * Revision 1.1.1.1 2001/10/17 16:40:05 lurcher
58 *
59 * First upload to SourceForge
60 *
61 * Revision 1.4 2001/04/12 17:43:36 nick
62 *
63 * Change logging and added autotest to odbctest
64 *
65 * Revision 1.3 2001/01/14 09:13:21 nick
66 *
67 * Remove stray printf
68 *
69 * Revision 1.2 2000/12/05 16:49:21 nick
70 *
71 * Add missing identifier_type in SQLSpecialColumns log
72 *
73 * Revision 1.1.1.1 2000/09/04 16:42:52 nick
74 * Imported Sources
75 *
76 * Revision 1.7 1999/11/13 23:40:59 ngorham
77 *
78 * Alter the way DM logging works
79 * Upgrade the Postgres driver to 6.4.6
80 *
81 * Revision 1.6 1999/10/24 23:54:18 ngorham
82 *
83 * First part of the changes to the error reporting
84 *
85 * Revision 1.5 1999/09/21 22:34:24 ngorham
86 *
87 * Improve performance by removing unneeded logging calls when logging is
88 * disabled
89 *
90 * Revision 1.4 1999/07/10 21:10:16 ngorham
91 *
92 * Adjust error sqlstate from driver manager, depending on requested
93 * version (ODBC2/3)
94 *
95 * Revision 1.3 1999/07/04 21:05:07 ngorham
96 *
97 * Add LGPL Headers to code
98 *
99 * Revision 1.2 1999/06/30 23:56:54 ngorham
100 *
101 * Add initial thread safety code
102 *
103 * Revision 1.1.1.1 1999/05/29 13:41:06 sShandyb
104 * first go at it
105 *
106 * Revision 1.1.1.1 1999/05/27 18:23:17 pharvey
107 * Imported sources
108 *
109 * Revision 1.2 1999/05/03 19:50:43 nick
110 * Another check point
111 *
112 * Revision 1.1 1999/04/25 23:06:11 nick
113 * Initial revision
114 *
115 *
116 **********************************************************************/
117
118#include <config.h>
119#include "drivermanager.h"
120
121static char const rcsid[]= "$RCSfile: SQLExtendedFetch.c,v $ $Revision: 1.6 $";
122
123SQLRETURN SQLExtendedFetch(
124 SQLHSTMT statement_handle,
125 SQLUSMALLINT f_fetch_type,
126 SQLLEN irow,
127 SQLULEN *pcrow,
128 SQLUSMALLINT *rgf_row_status )
129{
130 DMHSTMT statement = (DMHSTMT) statement_handle;
131 SQLRETURN ret;
132 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
133
134 /*
135 * check statement
136 */
137
138 if ( !__validate_stmt( statement ))
139 {
140 dm_log_write( __FILE__,
141 __LINE__,
142 LOG_INFO,
143 LOG_INFO,
144 "Error: SQL_INVALID_HANDLE" );
145
146 return SQL_INVALID_HANDLE;
147 }
148
149 function_entry( statement );
150
151 if ( log_info.log_flag )
152 {
153 sprintf( statement -> msg, "\n\t\tEntry:\
154\n\t\t\tStatement = %p\
155\n\t\t\tFetch Type = %d\
156\n\t\t\tRow = %d\
157\n\t\t\tPcRow = %p\
158\n\t\t\tRow Status = %p",
159 statement,
160 f_fetch_type,
161 (int)irow,
162 pcrow,
163 (void*)rgf_row_status );
164
165 dm_log_write( __FILE__,
166 __LINE__,
167 LOG_INFO,
168 LOG_INFO,
169 statement -> msg );
170 }
171
172 thread_protect( SQL_HANDLE_STMT, statement );
173
174 if ( f_fetch_type != SQL_FETCH_NEXT &&
175 f_fetch_type != SQL_FETCH_PRIOR &&
176 f_fetch_type != SQL_FETCH_FIRST &&
177 f_fetch_type != SQL_FETCH_LAST &&
178 f_fetch_type != SQL_FETCH_ABSOLUTE &&
179 f_fetch_type != SQL_FETCH_RELATIVE &&
180 f_fetch_type != SQL_FETCH_BOOKMARK )
181 {
182 dm_log_write( __FILE__,
183 __LINE__,
184 LOG_INFO,
185 LOG_INFO,
186 "Error: HY106" );
187
188 __post_internal_error( &statement -> error,
189 ERROR_HY106, NULL,
190 statement -> connection -> environment -> requested_version );
191
192 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
193 }
194
195 /*
196 * check states
197 */
198
199 if ( statement -> state == STATE_S1 ||
200 statement -> state == STATE_S2 ||
201 statement -> state == STATE_S3 )
202 {
203 dm_log_write( __FILE__,
204 __LINE__,
205 LOG_INFO,
206 LOG_INFO,
207 "Error: HY010" );
208
209 __post_internal_error( &statement -> error,
210 ERROR_HY010, NULL,
211 statement -> connection -> environment -> requested_version );
212
213 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
214 }
215
216 if ( statement -> state == STATE_S4 )
217 {
218 dm_log_write( __FILE__,
219 __LINE__,
220 LOG_INFO,
221 LOG_INFO,
222 "Error: 24000" );
223
224 __post_internal_error( &statement -> error,
225 ERROR_24000, NULL,
226 statement -> connection -> environment -> requested_version );
227
228 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
229 }
230
231 if ( statement -> state == STATE_S6 )
232 {
233 dm_log_write( __FILE__,
234 __LINE__,
235 LOG_INFO,
236 LOG_INFO,
237 "Error: HY010" );
238
239 __post_internal_error( &statement -> error,
240 ERROR_HY010, NULL,
241 statement -> connection -> environment -> requested_version );
242
243 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
244 }
245
246 if ( statement -> state == STATE_S8 ||
247 statement -> state == STATE_S9 ||
248 statement -> state == STATE_S10 ||
249 statement -> state == STATE_S13 ||
250 statement -> state == STATE_S14 ||
251 statement -> state == STATE_S15 )
252 {
253 dm_log_write( __FILE__,
254 __LINE__,
255 LOG_INFO,
256 LOG_INFO,
257 "Error: HY010" );
258
259 __post_internal_error( &statement -> error,
260 ERROR_HY010, NULL,
261 statement -> connection -> environment -> requested_version );
262
263 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
264 }
265
266 if ( statement -> state == STATE_S11 ||
267 statement -> state == STATE_S12 )
268 {
269 if ( statement -> interupted_func != SQL_API_SQLEXTENDEDFETCH )
270 {
271 dm_log_write( __FILE__,
272 __LINE__,
273 LOG_INFO,
274 LOG_INFO,
275 "Error: HY010" );
276
277 __post_internal_error( &statement -> error,
278 ERROR_HY010, NULL,
279 statement -> connection -> environment -> requested_version );
280
281 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
282 }
283 }
284
285 if ( !CHECK_SQLEXTENDEDFETCH( statement -> connection ))
286 {
287 dm_log_write( __FILE__,
288 __LINE__,
289 LOG_INFO,
290 LOG_INFO,
291 "Error: IM001" );
292
293 __post_internal_error( &statement -> error,
294 ERROR_IM001, NULL,
295 statement -> connection -> environment -> requested_version );
296
297 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
298 }
299
300 ret = SQLEXTENDEDFETCH( statement -> connection,
301 statement -> driver_stmt,
302 f_fetch_type,
303 irow,
304 pcrow,
305 rgf_row_status );
306
307 if ( ret == SQL_STILL_EXECUTING )
308 {
309 statement -> interupted_func = SQL_API_SQLEXTENDEDFETCH;
310 if ( statement -> state != STATE_S11 &&
311 statement -> state != STATE_S12 )
312 {
313 statement -> interupted_state = statement -> state;
314 statement -> state = STATE_S11;
315 }
316 }
317 else if ( SQL_SUCCEEDED( ret ))
318 {
319 statement -> eod = 0;
320 statement -> state = STATE_S7;
321 }
322 else if ( ret == SQL_NO_DATA )
323 {
324 statement -> eod = 1;
325 statement -> state = STATE_S7;
326 }
327 else if (statement -> state == STATE_S11 || statement -> state == STATE_S12 )
328 {
329 statement -> state = statement -> interupted_state;
330 }
331
332 if ( log_info.log_flag )
333 {
334 sprintf( statement -> msg,
335 "\n\t\tExit:[%s]",
336 __get_return_status( ret, s1 ));
337
338 dm_log_write( __FILE__,
339 __LINE__,
340 LOG_INFO,
341 LOG_INFO,
342 statement -> msg );
343 }
344
345 return function_return( SQL_HANDLE_STMT, statement, ret );
346}
347