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: SQLNumParams.c,v 1.4 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLNumParams.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:08 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:08 sShandyb
90 * first go at it
91 *
92 * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey
93 * Imported sources
94 *
95 * Revision 1.2 1999/05/03 19:50:43 nick
96 * Another check point
97 *
98 * Revision 1.1 1999/04/25 23:06:11 nick
99 * Initial revision
100 *
101 *
102 **********************************************************************/
103
104#include <config.h>
105#include "drivermanager.h"
106
107static char const rcsid[]= "$RCSfile: SQLNumParams.c,v $ $Revision: 1.4 $";
108
109SQLRETURN SQLNumParams(
110 SQLHSTMT statement_handle,
111 SQLSMALLINT *pcpar )
112{
113 DMHSTMT statement = (DMHSTMT) statement_handle;
114 SQLRETURN ret;
115 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
116 SQLCHAR s2[ 100 + LOG_MESSAGE_LEN ];
117
118 /*
119 * check statement
120 */
121
122 if ( !__validate_stmt( statement ))
123 {
124 dm_log_write( __FILE__,
125 __LINE__,
126 LOG_INFO,
127 LOG_INFO,
128 "Error: SQL_INVALID_HANDLE" );
129
130 return SQL_INVALID_HANDLE;
131 }
132
133 function_entry( statement );
134
135 if ( log_info.log_flag )
136 {
137 sprintf( statement -> msg, "\n\t\tEntry:\
138\n\t\t\tStatement = %p\
139\n\t\t\tParam Count = %p",
140 statement,
141 pcpar );
142
143 dm_log_write( __FILE__,
144 __LINE__,
145 LOG_INFO,
146 LOG_INFO,
147 statement -> msg );
148 }
149
150 thread_protect( SQL_HANDLE_STMT, statement );
151
152 /*
153 * check states
154 */
155 if ( statement -> state == STATE_S1 ||
156 statement -> state == STATE_S8 ||
157 statement -> state == STATE_S9 ||
158 statement -> state == STATE_S10 ||
159 statement -> state == STATE_S13 ||
160 statement -> state == STATE_S14 ||
161 statement -> state == STATE_S15 )
162 {
163 dm_log_write( __FILE__,
164 __LINE__,
165 LOG_INFO,
166 LOG_INFO,
167 "Error: HY010" );
168
169 __post_internal_error( &statement -> error,
170 ERROR_HY010, NULL,
171 statement -> connection -> environment -> requested_version );
172
173 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
174 }
175
176 if ( statement -> state == STATE_S11 ||
177 statement -> state == STATE_S12 )
178 {
179 if ( statement -> interupted_func != SQL_API_SQLNUMPARAMS )
180 {
181 dm_log_write( __FILE__,
182 __LINE__,
183 LOG_INFO,
184 LOG_INFO,
185 "Error: HY010" );
186
187 __post_internal_error( &statement -> error,
188 ERROR_HY010, NULL,
189 statement -> connection -> environment -> requested_version );
190
191 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
192 }
193 }
194
195 if ( !CHECK_SQLNUMPARAMS( statement -> connection ))
196 {
197 dm_log_write( __FILE__,
198 __LINE__,
199 LOG_INFO,
200 LOG_INFO,
201 "Error: IM001" );
202
203 __post_internal_error( &statement -> error,
204 ERROR_IM001, NULL,
205 statement -> connection -> environment -> requested_version );
206
207 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
208 }
209
210 ret = SQLNUMPARAMS( statement -> connection,
211 statement -> driver_stmt,
212 pcpar );
213
214 if ( ret == SQL_STILL_EXECUTING )
215 {
216 statement -> interupted_func = SQL_API_SQLNUMPARAMS;
217 if ( statement -> state != STATE_S11 &&
218 statement -> state != STATE_S12 )
219 statement -> state = STATE_S11;
220 }
221
222 if ( log_info.log_flag )
223 {
224 sprintf( statement -> msg,
225 "\n\t\tExit:[%s]\
226\n\t\t\tCount = %s",
227 __get_return_status( ret, s2 ),
228 __sptr_as_string( s1, pcpar ));
229
230 dm_log_write( __FILE__,
231 __LINE__,
232 LOG_INFO,
233 LOG_INFO,
234 statement -> msg );
235 }
236
237 return function_return( SQL_HANDLE_STMT, statement, ret );
238}
239