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: SQLGetStmtOption.c,v 1.4 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLGetStmtOption.c,v $ |
33 | * Revision 1.4 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.3 2003/10/30 18:20:46 lurcher |
37 | * |
38 | * Fix broken thread protection |
39 | * Remove SQLNumResultCols after execute, lease S4/S% to driver |
40 | * Fix string overrun in SQLDriverConnect |
41 | * Add initial support for Interix |
42 | * |
43 | * Revision 1.2 2002/12/05 17:44:31 lurcher |
44 | * |
45 | * Display unknown return values in return logging |
46 | * |
47 | * Revision 1.1.1.1 2001/10/17 16:40:06 lurcher |
48 | * |
49 | * First upload to SourceForge |
50 | * |
51 | * Revision 1.3 2001/07/03 09:30:41 nick |
52 | * |
53 | * Add ability to alter size of displayed message in the log |
54 | * |
55 | * Revision 1.2 2001/04/12 17:43:36 nick |
56 | * |
57 | * Change logging and added autotest to odbctest |
58 | * |
59 | * Revision 1.1.1.1 2000/09/04 16:42:52 nick |
60 | * Imported Sources |
61 | * |
62 | * Revision 1.7 1999/11/13 23:41:00 ngorham |
63 | * |
64 | * Alter the way DM logging works |
65 | * Upgrade the Postgres driver to 6.4.6 |
66 | * |
67 | * Revision 1.6 1999/10/24 23:54:18 ngorham |
68 | * |
69 | * First part of the changes to the error reporting |
70 | * |
71 | * Revision 1.5 1999/09/21 22:34:25 ngorham |
72 | * |
73 | * Improve performance by removing unneeded logging calls when logging is |
74 | * disabled |
75 | * |
76 | * Revision 1.4 1999/07/10 21:10:16 ngorham |
77 | * |
78 | * Adjust error sqlstate from driver manager, depending on requested |
79 | * version (ODBC2/3) |
80 | * |
81 | * Revision 1.3 1999/07/04 21:05:07 ngorham |
82 | * |
83 | * Add LGPL Headers to code |
84 | * |
85 | * Revision 1.2 1999/06/30 23:56:55 ngorham |
86 | * |
87 | * Add initial thread safety code |
88 | * |
89 | * Revision 1.1.1.1 1999/05/29 13:41:07 sShandyb |
90 | * first go at it |
91 | * |
92 | * Revision 1.4 1999/06/03 22:20:25 ngorham |
93 | * |
94 | * Finished off the ODBC3-2 mapping |
95 | * |
96 | * Revision 1.3 1999/06/02 20:12:10 ngorham |
97 | * |
98 | * Fixed botched log entry, and removed the dos \r from the sql header files. |
99 | * |
100 | * Revision 1.2 1999/06/02 19:57:20 ngorham |
101 | * |
102 | * Added code to check if a attempt is being made to compile with a C++ |
103 | * Compiler, and issue a message. |
104 | * Start work on the ODBC2-3 conversions. |
105 | * |
106 | * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey |
107 | * Imported sources |
108 | * |
109 | * Revision 1.2 1999/05/04 22:41:12 nick |
110 | * and another night ends |
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: SQLGetStmtOption.c,v $ $Revision: 1.4 $" ; |
122 | |
123 | SQLRETURN SQLGetStmtOption( SQLHSTMT statement_handle, |
124 | SQLUSMALLINT option, |
125 | SQLPOINTER value ) |
126 | { |
127 | DMHSTMT statement = (DMHSTMT) statement_handle; |
128 | SQLRETURN ret; |
129 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
130 | |
131 | /* |
132 | * check statement |
133 | */ |
134 | |
135 | if ( !__validate_stmt( statement )) |
136 | { |
137 | dm_log_write( __FILE__, |
138 | __LINE__, |
139 | LOG_INFO, |
140 | LOG_INFO, |
141 | "Error: SQL_INVALID_HANDLE" ); |
142 | |
143 | return SQL_INVALID_HANDLE; |
144 | } |
145 | |
146 | function_entry( statement ); |
147 | |
148 | if ( log_info.log_flag ) |
149 | { |
150 | sprintf( statement -> msg, "\n\t\tEntry:\ |
151 | \n\t\t\tStatement = %p\ |
152 | \n\t\t\tOption = %s\ |
153 | \n\t\t\tValue = %p" , |
154 | statement, |
155 | __stmt_attr_as_string( s1, option ), |
156 | value ); |
157 | |
158 | dm_log_write( __FILE__, |
159 | __LINE__, |
160 | LOG_INFO, |
161 | LOG_INFO, |
162 | statement -> msg ); |
163 | } |
164 | |
165 | thread_protect( SQL_HANDLE_STMT, statement ); |
166 | |
167 | /* |
168 | * check states |
169 | */ |
170 | |
171 | if ( option == SQL_ROW_NUMBER || option == SQL_GET_BOOKMARK ) |
172 | { |
173 | if ( statement -> state >= STATE_S1 && statement -> state <= STATE_S5 || |
174 | ( statement -> state == STATE_S6 || |
175 | statement -> state == STATE_S7 ) && statement -> eod ) |
176 | { |
177 | dm_log_write( __FILE__, |
178 | __LINE__, |
179 | LOG_INFO, |
180 | LOG_INFO, |
181 | "Error: 24000" ); |
182 | |
183 | __post_internal_error( &statement -> error, |
184 | ERROR_24000, NULL, |
185 | statement -> connection -> environment -> requested_version ); |
186 | |
187 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
188 | } |
189 | } |
190 | |
191 | if ( statement -> state == STATE_S8 || |
192 | statement -> state == STATE_S9 || |
193 | statement -> state == STATE_S10 || |
194 | statement -> state == STATE_S11 || |
195 | statement -> state == STATE_S12 || |
196 | statement -> state == STATE_S13 || |
197 | statement -> state == STATE_S14 || |
198 | statement -> state == STATE_S15 ) |
199 | { |
200 | dm_log_write( __FILE__, |
201 | __LINE__, |
202 | LOG_INFO, |
203 | LOG_INFO, |
204 | "Error: HY010" ); |
205 | |
206 | __post_internal_error( &statement -> error, |
207 | ERROR_HY010, NULL, |
208 | statement -> connection -> environment -> requested_version ); |
209 | |
210 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
211 | } |
212 | |
213 | /* |
214 | * states S5 - S7 are handled by the driver |
215 | */ |
216 | |
217 | if ( CHECK_SQLGETSTMTOPTION( statement -> connection )) |
218 | { |
219 | ret = SQLGETSTMTOPTION( statement -> connection, |
220 | statement -> driver_stmt, |
221 | option, |
222 | value ); |
223 | } |
224 | else if ( CHECK_SQLGETSTMTATTR( statement -> connection )) |
225 | { |
226 | switch ( option ) |
227 | { |
228 | case SQL_ATTR_APP_PARAM_DESC: |
229 | if ( value ) |
230 | memcpy( value, &statement -> apd, sizeof( statement -> apd )); |
231 | |
232 | ret = SQL_SUCCESS; |
233 | break; |
234 | |
235 | case SQL_ATTR_APP_ROW_DESC: |
236 | if ( value ) |
237 | memcpy( value, &statement -> ard, sizeof( statement -> ard )); |
238 | |
239 | ret = SQL_SUCCESS; |
240 | break; |
241 | |
242 | case SQL_ATTR_IMP_PARAM_DESC: |
243 | if ( value ) |
244 | memcpy( value, &statement -> ipd, sizeof( statement -> ipd )); |
245 | |
246 | ret = SQL_SUCCESS; |
247 | break; |
248 | |
249 | case SQL_ATTR_IMP_ROW_DESC: |
250 | if ( value ) |
251 | memcpy( value, &statement -> ird, sizeof( statement -> ird )); |
252 | |
253 | ret = SQL_SUCCESS; |
254 | break; |
255 | |
256 | default: |
257 | ret = SQLGETSTMTATTR( statement -> connection, |
258 | statement -> driver_stmt, |
259 | option, |
260 | value, |
261 | SQL_MAX_OPTION_STRING_LENGTH, |
262 | NULL ); |
263 | break; |
264 | } |
265 | } |
266 | else if ( CHECK_SQLGETSTMTATTRW( statement -> connection )) { |
267 | switch ( option ) |
268 | { |
269 | case SQL_ATTR_APP_PARAM_DESC: |
270 | if ( value ) |
271 | memcpy( value, &statement -> apd, sizeof( statement -> apd )); |
272 | |
273 | ret = SQL_SUCCESS; |
274 | break; |
275 | |
276 | case SQL_ATTR_APP_ROW_DESC: |
277 | if ( value ) |
278 | memcpy( value, &statement -> ard, sizeof( statement -> ard )); |
279 | |
280 | ret = SQL_SUCCESS; |
281 | break; |
282 | |
283 | case SQL_ATTR_IMP_PARAM_DESC: |
284 | if ( value ) |
285 | memcpy( value, &statement -> ipd, sizeof( statement -> ipd )); |
286 | |
287 | ret = SQL_SUCCESS; |
288 | break; |
289 | |
290 | case SQL_ATTR_IMP_ROW_DESC: |
291 | if ( value ) |
292 | memcpy( value, &statement -> ird, sizeof( statement -> ird )); |
293 | |
294 | ret = SQL_SUCCESS; |
295 | break; |
296 | |
297 | default: |
298 | ret = SQLGETSTMTATTRW( statement -> connection, |
299 | statement -> driver_stmt, |
300 | option, |
301 | value, |
302 | SQL_MAX_OPTION_STRING_LENGTH, |
303 | NULL ); |
304 | break; |
305 | } |
306 | } |
307 | else |
308 | { |
309 | dm_log_write( __FILE__, |
310 | __LINE__, |
311 | LOG_INFO, |
312 | LOG_INFO, |
313 | "Error: IM001" ); |
314 | |
315 | __post_internal_error( &statement -> error, |
316 | ERROR_IM001, NULL, |
317 | statement -> connection -> environment -> requested_version ); |
318 | |
319 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
320 | } |
321 | |
322 | if ( log_info.log_flag ) |
323 | { |
324 | sprintf( statement -> msg, |
325 | "\n\t\tExit:[%s]" , |
326 | __get_return_status( ret, s1 )); |
327 | |
328 | dm_log_write( __FILE__, |
329 | __LINE__, |
330 | LOG_INFO, |
331 | LOG_INFO, |
332 | statement -> msg ); |
333 | } |
334 | |
335 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
336 | } |
337 | |