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: SQLProcedureColumns.c,v 1.7 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLProcedureColumns.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 2004/01/12 09:54:39 lurcher
37 *
38 * Fix problem where STATE_S5 stops metadata calls
39 *
40 * Revision 1.5 2003/10/30 18:20:46 lurcher
41 *
42 * Fix broken thread protection
43 * Remove SQLNumResultCols after execute, lease S4/S% to driver
44 * Fix string overrun in SQLDriverConnect
45 * Add initial support for Interix
46 *
47 * Revision 1.4 2003/02/27 12:19:39 lurcher
48 *
49 * Add the A functions as well as the W
50 *
51 * Revision 1.3 2002/12/05 17:44:31 lurcher
52 *
53 * Display unknown return values in return logging
54 *
55 * Revision 1.2 2002/07/24 08:49:52 lurcher
56 *
57 * Alter UNICODE support to use iconv for UNICODE-ANSI conversion
58 *
59 * Revision 1.1.1.1 2001/10/17 16:40:06 lurcher
60 *
61 * First upload to SourceForge
62 *
63 * Revision 1.4 2001/07/03 09:30:41 nick
64 *
65 * Add ability to alter size of displayed message in the log
66 *
67 * Revision 1.3 2001/04/12 17:43:36 nick
68 *
69 * Change logging and added autotest to odbctest
70 *
71 * Revision 1.2 2000/12/31 20:30:54 nick
72 *
73 * Add UNICODE support
74 *
75 * Revision 1.1.1.1 2000/09/04 16:42:52 nick
76 * Imported Sources
77 *
78 * Revision 1.7 1999/11/13 23:41:00 ngorham
79 *
80 * Alter the way DM logging works
81 * Upgrade the Postgres driver to 6.4.6
82 *
83 * Revision 1.6 1999/10/24 23:54:18 ngorham
84 *
85 * First part of the changes to the error reporting
86 *
87 * Revision 1.5 1999/09/21 22:34:25 ngorham
88 *
89 * Improve performance by removing unneeded logging calls when logging is
90 * disabled
91 *
92 * Revision 1.4 1999/07/10 21:10:17 ngorham
93 *
94 * Adjust error sqlstate from driver manager, depending on requested
95 * version (ODBC2/3)
96 *
97 * Revision 1.3 1999/07/04 21:05:08 ngorham
98 *
99 * Add LGPL Headers to code
100 *
101 * Revision 1.2 1999/06/30 23:56:55 ngorham
102 *
103 * Add initial thread safety code
104 *
105 * Revision 1.1.1.1 1999/05/29 13:41:08 sShandyb
106 * first go at it
107 *
108 * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey
109 * Imported sources
110 *
111 * Revision 1.3 1999/05/03 19:50:43 nick
112 * Another check point
113 *
114 * Revision 1.2 1999/04/30 16:22:47 nick
115 * Another checkpoint
116 *
117 * Revision 1.1 1999/04/25 23:06:11 nick
118 * Initial revision
119 *
120 *
121 **********************************************************************/
122
123#include <config.h>
124#include "drivermanager.h"
125
126static char const rcsid[]= "$RCSfile: SQLProcedureColumns.c,v $ $Revision: 1.7 $";
127
128SQLRETURN SQLProcedureColumnsA(
129 SQLHSTMT statement_handle,
130 SQLCHAR *sz_catalog_name,
131 SQLSMALLINT cb_catalog_name,
132 SQLCHAR *sz_schema_name,
133 SQLSMALLINT cb_schema_name,
134 SQLCHAR *sz_proc_name,
135 SQLSMALLINT cb_proc_name,
136 SQLCHAR *sz_column_name,
137 SQLSMALLINT cb_column_name )
138{
139 return SQLProcedureColumns( statement_handle,
140 sz_catalog_name,
141 cb_catalog_name,
142 sz_schema_name,
143 cb_schema_name,
144 sz_proc_name,
145 cb_proc_name,
146 sz_column_name,
147 cb_column_name );
148}
149
150SQLRETURN SQLProcedureColumns(
151 SQLHSTMT statement_handle,
152 SQLCHAR *sz_catalog_name,
153 SQLSMALLINT cb_catalog_name,
154 SQLCHAR *sz_schema_name,
155 SQLSMALLINT cb_schema_name,
156 SQLCHAR *sz_proc_name,
157 SQLSMALLINT cb_proc_name,
158 SQLCHAR *sz_column_name,
159 SQLSMALLINT cb_column_name )
160{
161 DMHSTMT statement = (DMHSTMT) statement_handle;
162 SQLRETURN ret;
163 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ], s2[ 100 + LOG_MESSAGE_LEN ], s3[ 100 + LOG_MESSAGE_LEN ], s4[ 100 + LOG_MESSAGE_LEN ];
164
165 /*
166 * check statement
167 */
168
169 if ( !__validate_stmt( statement ))
170 {
171 dm_log_write( __FILE__,
172 __LINE__,
173 LOG_INFO,
174 LOG_INFO,
175 "Error: SQL_INVALID_HANDLE" );
176
177 return SQL_INVALID_HANDLE;
178 }
179
180 function_entry( statement );
181
182 if ( log_info.log_flag )
183 {
184 sprintf( statement -> msg, "\n\t\tEntry:\
185\n\t\t\tStatement = %p\
186\n\t\t\tCatalog Name = %s\
187\n\t\t\tSchema Name = %s\
188\n\t\t\tProc Name = %s\
189\n\t\t\tColumn Type = %s",
190 statement,
191 __string_with_length( s1, sz_catalog_name, cb_catalog_name ),
192 __string_with_length( s2, sz_schema_name, cb_schema_name ),
193 __string_with_length( s3, sz_proc_name, cb_proc_name ),
194 __string_with_length( s4, sz_column_name, cb_column_name ));
195
196 dm_log_write( __FILE__,
197 __LINE__,
198 LOG_INFO,
199 LOG_INFO,
200 statement -> msg );
201 }
202
203 thread_protect( SQL_HANDLE_STMT, statement );
204
205 if (( sz_catalog_name && cb_catalog_name < 0 && cb_catalog_name != SQL_NTS ) ||
206 ( sz_schema_name && cb_schema_name < 0 && cb_schema_name != SQL_NTS ) ||
207 ( sz_proc_name && cb_proc_name < 0 && cb_proc_name != SQL_NTS ) ||
208 ( sz_column_name && cb_column_name < 0 && cb_column_name != SQL_NTS ))
209 {
210 dm_log_write( __FILE__,
211 __LINE__,
212 LOG_INFO,
213 LOG_INFO,
214 "Error: HY090" );
215
216 __post_internal_error( &statement -> error,
217 ERROR_HY090, NULL,
218 statement -> connection -> environment -> requested_version );
219
220 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
221 }
222
223 /*
224 * check states
225 */
226
227#ifdef NR_PROBE
228 if ( statement -> state == STATE_S5 ||
229 statement -> state == STATE_S6 ||
230 statement -> state == STATE_S7 )
231#else
232 if (( statement -> state == STATE_S6 && statement -> eod == 0 ) ||
233 statement -> state == STATE_S7 )
234#endif
235 {
236 dm_log_write( __FILE__,
237 __LINE__,
238 LOG_INFO,
239 LOG_INFO,
240 "Error: 24000" );
241
242 __post_internal_error( &statement -> error,
243 ERROR_24000, NULL,
244 statement -> connection -> environment -> requested_version );
245
246 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
247 }
248 else if ( statement -> state == STATE_S8 ||
249 statement -> state == STATE_S9 ||
250 statement -> state == STATE_S10 ||
251 statement -> state == STATE_S13 ||
252 statement -> state == STATE_S14 ||
253 statement -> state == STATE_S15 )
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
268 if ( statement -> state == STATE_S11 ||
269 statement -> state == STATE_S12 )
270 {
271 if ( statement -> interupted_func != SQL_API_SQLPROCEDURECOLUMNS )
272 {
273 dm_log_write( __FILE__,
274 __LINE__,
275 LOG_INFO,
276 LOG_INFO,
277 "Error: HY010" );
278
279 __post_internal_error( &statement -> error,
280 ERROR_HY010, NULL,
281 statement -> connection -> environment -> requested_version );
282
283 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
284 }
285 }
286
287 /*
288 * TO_DO Check the SQL_ATTR_METADATA_ID settings
289 */
290
291 if ( statement -> connection -> unicode_driver )
292 {
293 SQLWCHAR *s1, *s2, *s3, *s4;
294 int wlen;
295
296 if ( !CHECK_SQLPROCEDURECOLUMNSW( statement -> connection ))
297 {
298 dm_log_write( __FILE__,
299 __LINE__,
300 LOG_INFO,
301 LOG_INFO,
302 "Error: IM001" );
303
304 __post_internal_error( &statement -> error,
305 ERROR_IM001, NULL,
306 statement -> connection -> environment -> requested_version );
307
308 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
309 }
310
311 s1 = ansi_to_unicode_alloc( sz_catalog_name, cb_catalog_name, statement -> connection, &wlen );
312 cb_catalog_name = wlen;
313 s2 = ansi_to_unicode_alloc( sz_schema_name, cb_schema_name, statement -> connection, &wlen );
314 cb_schema_name = wlen;
315 s3 = ansi_to_unicode_alloc( sz_proc_name, cb_proc_name, statement -> connection, &wlen );
316 cb_proc_name = wlen;
317 s4 = ansi_to_unicode_alloc( sz_column_name, cb_column_name, statement -> connection, &wlen );
318 cb_column_name = wlen;
319
320 ret = SQLPROCEDURECOLUMNSW( statement -> connection ,
321 statement -> driver_stmt,
322 s1,
323 cb_catalog_name,
324 s2,
325 cb_schema_name,
326 s3,
327 cb_proc_name,
328 s4,
329 cb_column_name );
330
331 if ( s1 )
332 free( s1 );
333 if ( s2 )
334 free( s2 );
335 if ( s3 )
336 free( s3 );
337 if ( s4 )
338 free( s4 );
339 }
340 else
341 {
342 if ( !CHECK_SQLPROCEDURECOLUMNS( statement -> connection ))
343 {
344 dm_log_write( __FILE__,
345 __LINE__,
346 LOG_INFO,
347 LOG_INFO,
348 "Error: IM001" );
349
350 __post_internal_error( &statement -> error,
351 ERROR_IM001, NULL,
352 statement -> connection -> environment -> requested_version );
353
354 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
355 }
356
357 ret = SQLPROCEDURECOLUMNS( statement -> connection ,
358 statement -> driver_stmt,
359 sz_catalog_name,
360 cb_catalog_name,
361 sz_schema_name,
362 cb_schema_name,
363 sz_proc_name,
364 cb_proc_name,
365 sz_column_name,
366 cb_column_name );
367 }
368
369
370 if ( SQL_SUCCEEDED( ret ))
371 {
372 statement -> state = STATE_S5;
373 statement -> prepared = 0;
374 }
375 else if ( ret == SQL_STILL_EXECUTING )
376 {
377 statement -> interupted_func = SQL_API_SQLPROCEDURECOLUMNS;
378 if ( statement -> state != STATE_S11 &&
379 statement -> state != STATE_S12 )
380 statement -> state = STATE_S11;
381 }
382 else
383 {
384 statement -> state = STATE_S1;
385 }
386
387 if ( log_info.log_flag )
388 {
389 sprintf( statement -> msg,
390 "\n\t\tExit:[%s]",
391 __get_return_status( ret, s1 ));
392
393 dm_log_write( __FILE__,
394 __LINE__,
395 LOG_INFO,
396 LOG_INFO,
397 statement -> msg );
398 }
399
400 return function_return( SQL_HANDLE_STMT, statement, ret );
401}
402