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: SQLParamOptions.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLParamOptions.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 2005/11/23 08:29:16 lurcher
37 * Add cleanup in postgres driver
38 *
39 * Revision 1.4 2005/07/08 12:11:23 lurcher
40 *
41 * Fix a cursor lib problem (it was broken if you did metadata calls)
42 * Alter the params to SQLParamOptions to use SQLULEN
43 *
44 * Revision 1.3 2003/10/30 18:20:46 lurcher
45 *
46 * Fix broken thread protection
47 * Remove SQLNumResultCols after execute, lease S4/S% to driver
48 * Fix string overrun in SQLDriverConnect
49 * Add initial support for Interix
50 *
51 * Revision 1.2 2002/12/05 17:44:31 lurcher
52 *
53 * Display unknown return values in return logging
54 *
55 * Revision 1.1.1.1 2001/10/17 16:40:06 lurcher
56 *
57 * First upload to SourceForge
58 *
59 * Revision 1.2 2001/04/12 17:43:36 nick
60 *
61 * Change logging and added autotest to odbctest
62 *
63 * Revision 1.1.1.1 2000/09/04 16:42:52 nick
64 * Imported Sources
65 *
66 * Revision 1.7 1999/11/13 23:41:00 ngorham
67 *
68 * Alter the way DM logging works
69 * Upgrade the Postgres driver to 6.4.6
70 *
71 * Revision 1.6 1999/10/24 23:54:18 ngorham
72 *
73 * First part of the changes to the error reporting
74 *
75 * Revision 1.5 1999/09/21 22:34:25 ngorham
76 *
77 * Improve performance by removing unneeded logging calls when logging is
78 * disabled
79 *
80 * Revision 1.4 1999/07/10 21:10:16 ngorham
81 *
82 * Adjust error sqlstate from driver manager, depending on requested
83 * version (ODBC2/3)
84 *
85 * Revision 1.3 1999/07/04 21:05:08 ngorham
86 *
87 * Add LGPL Headers to code
88 *
89 * Revision 1.2 1999/06/30 23:56:55 ngorham
90 *
91 * Add initial thread safety code
92 *
93 * Revision 1.1.1.1 1999/05/29 13:41:08 sShandyb
94 * first go at it
95 *
96 * Revision 1.4 1999/06/03 22:20:25 ngorham
97 *
98 * Finished off the ODBC3-2 mapping
99 *
100 * Revision 1.3 1999/06/02 20:12:10 ngorham
101 *
102 * Fixed botched log entry, and removed the dos \r from the sql header files.
103 *
104 * Revision 1.2 1999/06/02 19:57:20 ngorham
105 *
106 * Added code to check if a attempt is being made to compile with a C++
107 * Compiler, and issue a message.
108 * Start work on the ODBC2-3 conversions.
109 *
110 * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey
111 * Imported sources
112 *
113 * Revision 1.2 1999/05/09 23:27:11 nick
114 * All the API done now
115 *
116 * Revision 1.1 1999/04/25 23:06:11 nick
117 * Initial revision
118 *
119 *
120 **********************************************************************/
121
122#include <config.h>
123#include "drivermanager.h"
124
125static char const rcsid[]= "$RCSfile: SQLParamOptions.c,v $ $Revision: 1.6 $";
126
127/*
128 * This one is strictly ODBC 2
129 */
130
131SQLRETURN SQLParamOptions(
132 SQLHSTMT statement_handle,
133 SQLULEN crow,
134 SQLULEN *pirow )
135{
136 DMHSTMT statement = (DMHSTMT) statement_handle;
137 SQLRETURN ret;
138 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
139
140 /*
141 * check statement
142 */
143
144 if ( !__validate_stmt( statement ))
145 {
146 dm_log_write( __FILE__,
147 __LINE__,
148 LOG_INFO,
149 LOG_INFO,
150 "Error: SQL_INVALID_HANDLE" );
151
152 return SQL_INVALID_HANDLE;
153 }
154
155 function_entry( statement );
156
157 if ( log_info.log_flag )
158 {
159 sprintf( statement -> msg, "\n\t\tEntry:\
160\n\t\t\tStatement = %p\
161\n\t\t\tCrow = %d\
162\n\t\t\tPirow = %p",
163 statement,
164 (int)crow,
165 (void*)pirow );
166
167 dm_log_write( __FILE__,
168 __LINE__,
169 LOG_INFO,
170 LOG_INFO,
171 statement -> msg );
172 }
173
174 thread_protect( SQL_HANDLE_STMT, statement );
175
176 if ( crow == 0 )
177 {
178 dm_log_write( __FILE__,
179 __LINE__,
180 LOG_INFO,
181 LOG_INFO,
182 "Error: S1107" );
183
184 __post_internal_error( &statement -> error,
185 ERROR_S1107, NULL,
186 statement -> connection -> environment -> requested_version );
187
188 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
189 }
190
191 /*
192 * check states
193 */
194
195 if ( statement -> state == STATE_S8 ||
196 statement -> state == STATE_S9 ||
197 statement -> state == STATE_S10 ||
198 statement -> state == STATE_S11 ||
199 statement -> state == STATE_S12 ||
200 statement -> state == STATE_S13 ||
201 statement -> state == STATE_S14 ||
202 statement -> state == STATE_S15 )
203 {
204 dm_log_write( __FILE__,
205 __LINE__,
206 LOG_INFO,
207 LOG_INFO,
208 "Error: S1010" );
209
210 __post_internal_error( &statement -> error,
211 ERROR_S1010, NULL,
212 statement -> connection -> environment -> requested_version );
213
214 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
215 }
216
217 if ( CHECK_SQLPARAMOPTIONS( statement -> connection ))
218 {
219 ret = SQLPARAMOPTIONS( statement -> connection,
220 statement -> driver_stmt,
221 crow,
222 pirow );
223 }
224 else if ( CHECK_SQLSETSTMTATTR( statement -> connection ))
225 {
226 ret = SQLSETSTMTATTR( statement -> connection,
227 statement -> driver_stmt,
228 SQL_ATTR_PARAMSET_SIZE,
229 crow,
230 0 );
231 if ( SQL_SUCCEEDED( ret ))
232 {
233 ret = SQLSETSTMTATTR( statement -> connection,
234 statement -> driver_stmt,
235 SQL_ATTR_PARAMS_PROCESSED_PTR,
236 pirow,
237 0 );
238 }
239 }
240 else if ( CHECK_SQLSETSTMTATTRW( statement -> connection ))
241 {
242 ret = SQLSETSTMTATTRW( statement -> connection,
243 statement -> driver_stmt,
244 SQL_ATTR_PARAMSET_SIZE,
245 crow,
246 0 );
247 if ( SQL_SUCCEEDED( ret ))
248 {
249 ret = SQLSETSTMTATTRW( statement -> connection,
250 statement -> driver_stmt,
251 SQL_ATTR_PARAMS_PROCESSED_PTR,
252 pirow,
253 0 );
254 }
255 }
256 else
257 {
258 dm_log_write( __FILE__,
259 __LINE__,
260 LOG_INFO,
261 LOG_INFO,
262 "Error: IM001" );
263
264 __post_internal_error( &statement -> error,
265 ERROR_IM001, NULL,
266 statement -> connection -> environment -> requested_version );
267
268 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
269 }
270
271 if ( log_info.log_flag )
272 {
273 sprintf( statement -> msg,
274 "\n\t\tExit:[%s]",
275 __get_return_status( ret, s1 ));
276
277 dm_log_write( __FILE__,
278 __LINE__,
279 LOG_INFO,
280 LOG_INFO,
281 statement -> msg );
282 }
283
284 return function_return( SQL_HANDLE_STMT, statement, ret );
285}
286