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: SQLSetPos.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLSetPos.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 2009/02/17 09:47:44 lurcher |
37 | * Clear up a number of bugs |
38 | * |
39 | * Revision 1.4 2003/10/30 18:20:46 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:31 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:07 lurcher |
58 | * |
59 | * First upload to SourceForge |
60 | * |
61 | * Revision 1.2 2001/04/12 17:43:36 nick |
62 | * |
63 | * Change logging and added autotest to odbctest |
64 | * |
65 | * Revision 1.1.1.1 2000/09/04 16:42:52 nick |
66 | * Imported Sources |
67 | * |
68 | * Revision 1.8 1999/11/13 23:41:01 ngorham |
69 | * |
70 | * Alter the way DM logging works |
71 | * Upgrade the Postgres driver to 6.4.6 |
72 | * |
73 | * Revision 1.7 1999/10/29 21:07:40 ngorham |
74 | * |
75 | * Fix some stupid bugs in the DM |
76 | * Make the postgres driver work via unix sockets |
77 | * |
78 | * Revision 1.6 1999/10/24 23:54:19 ngorham |
79 | * |
80 | * First part of the changes to the error reporting |
81 | * |
82 | * Revision 1.5 1999/09/21 22:34:26 ngorham |
83 | * |
84 | * Improve performance by removing unneeded logging calls when logging is |
85 | * disabled |
86 | * |
87 | * Revision 1.4 1999/07/10 21:10:17 ngorham |
88 | * |
89 | * Adjust error sqlstate from driver manager, depending on requested |
90 | * version (ODBC2/3) |
91 | * |
92 | * Revision 1.3 1999/07/04 21:05:08 ngorham |
93 | * |
94 | * Add LGPL Headers to code |
95 | * |
96 | * Revision 1.2 1999/06/30 23:56:55 ngorham |
97 | * |
98 | * Add initial thread safety code |
99 | * |
100 | * Revision 1.1.1.1 1999/05/29 13:41:08 sShandyb |
101 | * first go at it |
102 | * |
103 | * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey |
104 | * Imported sources |
105 | * |
106 | * Revision 1.3 1999/05/04 22:41:12 nick |
107 | * and another night ends |
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 | |
121 | static char const rcsid[]= "$RCSfile: SQLSetPos.c,v $ $Revision: 1.6 $" ; |
122 | |
123 | SQLRETURN SQLSetPos( |
124 | SQLHSTMT statement_handle, |
125 | SQLSETPOSIROW irow, |
126 | SQLUSMALLINT foption, |
127 | SQLUSMALLINT flock ) |
128 | { |
129 | DMHSTMT statement = (DMHSTMT) statement_handle; |
130 | SQLRETURN ret; |
131 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
132 | |
133 | /* |
134 | * check statement |
135 | */ |
136 | |
137 | if ( !__validate_stmt( statement )) |
138 | { |
139 | dm_log_write( __FILE__, |
140 | __LINE__, |
141 | LOG_INFO, |
142 | LOG_INFO, |
143 | "Error: SQL_INVALID_HANDLE" ); |
144 | |
145 | return SQL_INVALID_HANDLE; |
146 | } |
147 | |
148 | function_entry( statement ); |
149 | |
150 | if ( log_info.log_flag ) |
151 | { |
152 | sprintf( statement -> msg, "\n\t\tEntry:\ |
153 | \n\t\t\tStatement = %p\ |
154 | \n\t\t\tIrow = %ld\ |
155 | \n\t\t\tFoption = %d\ |
156 | \n\t\t\tFlock = %d" , |
157 | statement, |
158 | (long int)irow, |
159 | foption, |
160 | flock ); |
161 | |
162 | dm_log_write( __FILE__, |
163 | __LINE__, |
164 | LOG_INFO, |
165 | LOG_INFO, |
166 | statement -> msg ); |
167 | } |
168 | |
169 | thread_protect( SQL_HANDLE_STMT, statement ); |
170 | |
171 | if ( foption != SQL_POSITION && |
172 | foption != SQL_REFRESH && |
173 | foption != SQL_UPDATE && |
174 | foption != SQL_DELETE && |
175 | foption != SQL_ADD ) |
176 | { |
177 | dm_log_write( __FILE__, |
178 | __LINE__, |
179 | LOG_INFO, |
180 | LOG_INFO, |
181 | "Error: HY092" ); |
182 | |
183 | __post_internal_error( &statement -> error, |
184 | ERROR_HY092, NULL, |
185 | statement -> connection -> environment -> requested_version ); |
186 | |
187 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
188 | } |
189 | |
190 | if ( flock != SQL_LOCK_NO_CHANGE && |
191 | flock != SQL_LOCK_EXCLUSIVE && |
192 | flock != SQL_LOCK_UNLOCK ) |
193 | { |
194 | dm_log_write( __FILE__, |
195 | __LINE__, |
196 | LOG_INFO, |
197 | LOG_INFO, |
198 | "Error: HY092" ); |
199 | |
200 | __post_internal_error( &statement -> error, |
201 | ERROR_HY092, NULL, |
202 | statement -> connection -> environment -> requested_version ); |
203 | |
204 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
205 | } |
206 | |
207 | /* |
208 | * check states |
209 | */ |
210 | |
211 | if ( statement -> state == STATE_S1 || |
212 | statement -> state == STATE_S2 || |
213 | statement -> state == STATE_S3 ) |
214 | { |
215 | dm_log_write( __FILE__, |
216 | __LINE__, |
217 | LOG_INFO, |
218 | LOG_INFO, |
219 | "Error: HY010" ); |
220 | |
221 | __post_internal_error( &statement -> error, |
222 | ERROR_HY010, NULL, |
223 | statement -> connection -> environment -> requested_version ); |
224 | |
225 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
226 | } |
227 | |
228 | if ( statement -> state == STATE_S4 || statement -> state == STATE_S5 || |
229 | (foption != SQL_ADD && statement -> state == STATE_S7 && statement -> eod )) |
230 | { |
231 | dm_log_write( __FILE__, |
232 | __LINE__, |
233 | LOG_INFO, |
234 | LOG_INFO, |
235 | "Error: 24000" ); |
236 | |
237 | __post_internal_error( &statement -> error, |
238 | ERROR_24000, NULL, |
239 | statement -> connection -> environment -> requested_version ); |
240 | |
241 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
242 | } |
243 | |
244 | if ( statement -> state == STATE_S8 || |
245 | statement -> state == STATE_S9 || |
246 | statement -> state == STATE_S10 || |
247 | statement -> state == STATE_S13 || |
248 | statement -> state == STATE_S14 || |
249 | statement -> state == STATE_S15 ) |
250 | { |
251 | dm_log_write( __FILE__, |
252 | __LINE__, |
253 | LOG_INFO, |
254 | LOG_INFO, |
255 | "Error: HY010" ); |
256 | |
257 | __post_internal_error( &statement -> error, |
258 | ERROR_HY010, NULL, |
259 | statement -> connection -> environment -> requested_version ); |
260 | |
261 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
262 | } |
263 | |
264 | if ( statement -> state == STATE_S11 || |
265 | statement -> state == STATE_S12 ) |
266 | { |
267 | if ( statement -> interupted_func == SQL_API_SQLEXTENDEDFETCH ) |
268 | { |
269 | __post_internal_error( &statement -> error, |
270 | ERROR_24000, NULL, |
271 | statement -> connection -> environment -> requested_version ); |
272 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
273 | } |
274 | |
275 | if ( statement -> interupted_func != SQL_API_SQLSETPOS ) |
276 | { |
277 | dm_log_write( __FILE__, |
278 | __LINE__, |
279 | LOG_INFO, |
280 | LOG_INFO, |
281 | "Error: HY010" ); |
282 | |
283 | __post_internal_error( &statement -> error, |
284 | ERROR_HY010, NULL, |
285 | statement -> connection -> environment -> requested_version ); |
286 | |
287 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
288 | } |
289 | } |
290 | |
291 | if ( !CHECK_SQLSETPOS( statement -> connection )) |
292 | { |
293 | dm_log_write( __FILE__, |
294 | __LINE__, |
295 | LOG_INFO, |
296 | LOG_INFO, |
297 | "Error: IM001" ); |
298 | |
299 | __post_internal_error( &statement -> error, |
300 | ERROR_IM001, NULL, |
301 | statement -> connection -> environment -> requested_version ); |
302 | |
303 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
304 | } |
305 | |
306 | ret = SQLSETPOS( statement -> connection, |
307 | statement -> driver_stmt, |
308 | irow, |
309 | foption, |
310 | flock ); |
311 | |
312 | if ( ret == SQL_STILL_EXECUTING ) |
313 | { |
314 | statement -> interupted_func = SQL_API_SQLSETPOS; |
315 | if ( statement -> state != STATE_S11 && |
316 | statement -> state != STATE_S12 ) |
317 | { |
318 | statement -> interupted_state = statement -> state; |
319 | statement -> state = STATE_S11; |
320 | } |
321 | } |
322 | else if ( SQL_SUCCEEDED( ret ) && (statement -> state == STATE_S11 || statement -> state == STATE_S12)) |
323 | { |
324 | statement -> state = statement -> interupted_state; |
325 | } |
326 | else if ( ret == SQL_NEED_DATA ) |
327 | { |
328 | statement -> interupted_func = SQL_API_SQLSETPOS; |
329 | statement -> interupted_state = statement -> state; |
330 | statement -> state = STATE_S8; |
331 | } |
332 | else if (statement -> state == STATE_S11 || statement -> state == STATE_S12 ) |
333 | { |
334 | statement -> state = statement -> interupted_state; |
335 | } |
336 | |
337 | if ( log_info.log_flag ) |
338 | { |
339 | sprintf( statement -> msg, |
340 | "\n\t\tExit:[%s]" , |
341 | __get_return_status( ret, s1 )); |
342 | |
343 | dm_log_write( __FILE__, |
344 | __LINE__, |
345 | LOG_INFO, |
346 | LOG_INFO, |
347 | statement -> msg ); |
348 | } |
349 | |
350 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
351 | } |
352 | |