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: SQLDescribeParam.c,v 1.7 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLDescribeParam.c,v $
33 * Revision 1.7 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.6 2008/05/20 13:43:47 lurcher
37 * Vms fixes
38 *
39 * Revision 1.5 2007/04/02 10:50:19 lurcher
40 * Fix some 64bit problems (only when sizeof(SQLLEN) == 8 )
41 *
42 * Revision 1.4 2003/10/30 18:20:45 lurcher
43 *
44 * Fix broken thread protection
45 * Remove SQLNumResultCols after execute, lease S4/S% to driver
46 * Fix string overrun in SQLDriverConnect
47 * Add initial support for Interix
48 *
49 * Revision 1.3 2002/12/05 17:44:30 lurcher
50 *
51 * Display unknown return values in return logging
52 *
53 * Revision 1.2 2001/12/13 13:00:32 lurcher
54 *
55 * Remove most if not all warnings on 64 bit platforms
56 * Add support for new MS 3.52 64 bit changes
57 * Add override to disable the stopping of tracing
58 * Add MAX_ROWS support in postgres driver
59 *
60 * Revision 1.1.1.1 2001/10/17 16:40:05 lurcher
61 *
62 * First upload to SourceForge
63 *
64 * Revision 1.3 2001/07/03 09:30:41 nick
65 *
66 * Add ability to alter size of displayed message in the log
67 *
68 * Revision 1.2 2001/04/12 17:43:36 nick
69 *
70 * Change logging and added autotest to odbctest
71 *
72 * Revision 1.1.1.1 2000/09/04 16:42:52 nick
73 * Imported Sources
74 *
75 * Revision 1.10 2000/07/28 16:34:52 ngorham
76 *
77 * Fix problems with SQLColAttributes, and SQLDescribeParam
78 *
79 * Revision 1.9 1999/11/13 23:40:59 ngorham
80 *
81 * Alter the way DM logging works
82 * Upgrade the Postgres driver to 6.4.6
83 *
84 * Revision 1.8 1999/11/10 03:51:33 ngorham
85 *
86 * Update the error reporting in the DM to enable ODBC 3 and 2 calls to
87 * work at the same time
88 *
89 * Revision 1.7 1999/10/24 23:54:17 ngorham
90 *
91 * First part of the changes to the error reporting
92 *
93 * Revision 1.6 1999/10/09 00:56:16 ngorham
94 *
95 * Added Manush's patch to map ODBC 3-2 datetime values
96 *
97 * Revision 1.5 1999/09/21 22:34:24 ngorham
98 *
99 * Improve performance by removing unneeded logging calls when logging is
100 * disabled
101 *
102 * Revision 1.4 1999/07/10 21:10:16 ngorham
103 *
104 * Adjust error sqlstate from driver manager, depending on requested
105 * version (ODBC2/3)
106 *
107 * Revision 1.3 1999/07/04 21:05:07 ngorham
108 *
109 * Add LGPL Headers to code
110 *
111 * Revision 1.2 1999/06/30 23:56:54 ngorham
112 *
113 * Add initial thread safety code
114 *
115 * Revision 1.1.1.1 1999/05/29 13:41:05 sShandyb
116 * first go at it
117 *
118 * Revision 1.1.1.1 1999/05/27 18:23:17 pharvey
119 * Imported sources
120 *
121 * Revision 1.3 1999/05/03 19:50:43 nick
122 * Another check point
123 *
124 * Revision 1.2 1999/04/30 16:22:47 nick
125 * Another checkpoint
126 *
127 * Revision 1.1 1999/04/25 23:06:11 nick
128 * Initial revision
129 *
130 *
131 **********************************************************************/
132
133#include <config.h>
134#include "drivermanager.h"
135
136static char const rcsid[]= "$RCSfile: SQLDescribeParam.c,v $ $Revision: 1.7 $";
137
138SQLRETURN SQLDescribeParam(
139 SQLHSTMT statement_handle,
140 SQLUSMALLINT ipar,
141 SQLSMALLINT *pf_sql_type,
142 SQLULEN *pcb_param_def,
143 SQLSMALLINT *pib_scale,
144 SQLSMALLINT *pf_nullable )
145{
146 DMHSTMT statement = (DMHSTMT) statement_handle;
147 SQLRETURN ret;
148 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ], s2[ 100 + LOG_MESSAGE_LEN ], s3[ 100 + LOG_MESSAGE_LEN ], s4[ 100 + LOG_MESSAGE_LEN ];
149 SQLCHAR s6[ 100 + LOG_MESSAGE_LEN ];
150
151 /*
152 * check statement
153 */
154
155 if ( !__validate_stmt( statement ))
156 {
157 dm_log_write( __FILE__,
158 __LINE__,
159 LOG_INFO,
160 LOG_INFO,
161 "Error: SQL_INVALID_HANDLE" );
162
163 return SQL_INVALID_HANDLE;
164 }
165
166 function_entry( statement );
167
168 if ( log_info.log_flag )
169 {
170 sprintf( statement -> msg, "\n\t\tEntry:\
171\n\t\t\tStatement = %p\
172\n\t\t\tParameter Number = %d\
173\n\t\t\tSQL Type = %p\
174\n\t\t\tParam Def = %p\
175\n\t\t\tScale = %p\
176\n\t\t\tNullable = %p",
177 statement,
178 ipar,
179 pf_sql_type,
180 pcb_param_def,
181 pib_scale,
182 pf_nullable );
183
184 dm_log_write( __FILE__,
185 __LINE__,
186 LOG_INFO,
187 LOG_INFO,
188 statement -> msg );
189 }
190
191 thread_protect( SQL_HANDLE_STMT, statement );
192
193 if ( ipar < 1 )
194 {
195 dm_log_write( __FILE__,
196 __LINE__,
197 LOG_INFO,
198 LOG_INFO,
199 "Error: 07009" );
200
201 __post_internal_error( &statement -> error,
202 ERROR_07009, NULL,
203 statement -> connection -> environment -> requested_version );
204
205 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
206 }
207
208 /*
209 * check states
210 */
211
212 if ( statement -> state == STATE_S1 )
213 {
214 dm_log_write( __FILE__,
215 __LINE__,
216 LOG_INFO,
217 LOG_INFO,
218 "Error: HY010" );
219
220 __post_internal_error( &statement -> error,
221 ERROR_HY010, NULL,
222 statement -> connection -> environment -> requested_version );
223
224 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
225 }
226 else if (( statement -> state == STATE_S4 ||
227 statement -> state == STATE_S8 ||
228 statement -> state == STATE_S9 ||
229 statement -> state == STATE_S10 ||
230 statement -> state == STATE_S13 ||
231 statement -> state == STATE_S14 ||
232 statement -> state == STATE_S15 ) &&
233 statement -> connection -> environment -> requested_version >= SQL_OV_ODBC3 )
234 {
235 dm_log_write( __FILE__,
236 __LINE__,
237 LOG_INFO,
238 LOG_INFO,
239 "Error: HY010" );
240
241 __post_internal_error( &statement -> error,
242 ERROR_HY010, NULL,
243 statement -> connection -> environment -> requested_version );
244
245 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
246 }
247 else if (( statement -> state == STATE_S8 ||
248 statement -> state == STATE_S9 ||
249 statement -> state == STATE_S10 ||
250 statement -> state == STATE_S13 ||
251 statement -> state == STATE_S14 ||
252 statement -> state == STATE_S15 ) &&
253 statement -> connection -> environment -> requested_version == SQL_OV_ODBC2 )
254 {
255 dm_log_write( __FILE__,
256 __LINE__,
257 LOG_INFO,
258 LOG_INFO,
259 "Error: HY010" );
260
261 __post_internal_error( &statement -> error,
262 ERROR_HY010, NULL,
263 statement -> connection -> environment -> requested_version );
264
265 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
266 }
267 else if ( statement -> state == STATE_S11 ||
268 statement -> state == STATE_S12 )
269 {
270 if ( statement -> interupted_func != SQL_API_SQLDESCRIBEPARAM )
271 {
272 dm_log_write( __FILE__,
273 __LINE__,
274 LOG_INFO,
275 LOG_INFO,
276 "Error: HY010" );
277
278 __post_internal_error( &statement -> error,
279 ERROR_HY010, NULL,
280 statement -> connection -> environment -> requested_version );
281
282 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
283 }
284 }
285
286 if ( !CHECK_SQLDESCRIBEPARAM( statement -> connection ))
287 {
288 dm_log_write( __FILE__,
289 __LINE__,
290 LOG_INFO,
291 LOG_INFO,
292 "Error: IM001" );
293
294 __post_internal_error( &statement -> error,
295 ERROR_IM001, NULL,
296 statement -> connection -> environment -> requested_version );
297
298 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
299 }
300
301 ret = SQLDESCRIBEPARAM( statement -> connection,
302 statement -> driver_stmt,
303 ipar,
304 pf_sql_type,
305 pcb_param_def,
306 pib_scale,
307 pf_nullable );
308
309 if ( ret == SQL_STILL_EXECUTING )
310 {
311 statement -> interupted_func = SQL_API_SQLDESCRIBEPARAM;
312 if ( statement -> state != STATE_S11 &&
313 statement -> state != STATE_S12 )
314 statement -> state = STATE_S11;
315 }
316
317 if ( (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
318 && pf_sql_type )
319 {
320 *pf_sql_type = __map_type(MAP_SQL_D2DM,statement->connection, *pf_sql_type);
321 }
322
323 if ( log_info.log_flag )
324 {
325 sprintf( statement -> msg,
326 "\n\t\tExit:[%s]\
327 \n\t\t\tSQL Type = %p\
328 \n\t\t\tParam Def = %p\
329 \n\t\t\tScale = %p\
330 \n\t\t\tNullable = %p",
331 __get_return_status( ret, s6 ),
332 __sptr_as_string( s1, pf_sql_type ),
333 __ptr_as_string( s2, (SQLLEN*)pcb_param_def ),
334 __sptr_as_string( s3, pib_scale ),
335 __sptr_as_string( s4, pf_nullable ));
336
337 dm_log_write( __FILE__,
338 __LINE__,
339 LOG_INFO,
340 LOG_INFO,
341 statement -> msg );
342 }
343
344 return function_return( SQL_HANDLE_STMT, statement, ret );
345}
346