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: SQLSetCursorName.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLSetCursorName.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 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.4 2003/02/27 12:19:40 lurcher
44 *
45 * Add the A functions as well as the W
46 *
47 * Revision 1.3 2002/12/05 17:44:31 lurcher
48 *
49 * Display unknown return values in return logging
50 *
51 * Revision 1.2 2002/07/24 08:49:52 lurcher
52 *
53 * Alter UNICODE support to use iconv for UNICODE-ANSI conversion
54 *
55 * Revision 1.1.1.1 2001/10/17 16:40:07 lurcher
56 *
57 * First upload to SourceForge
58 *
59 * Revision 1.4 2001/07/03 09:30:41 nick
60 *
61 * Add ability to alter size of displayed message in the log
62 *
63 * Revision 1.3 2001/04/12 17:43:36 nick
64 *
65 * Change logging and added autotest to odbctest
66 *
67 * Revision 1.2 2000/12/31 20:30:54 nick
68 *
69 * Add UNICODE support
70 *
71 * Revision 1.1.1.1 2000/09/04 16:42:52 nick
72 * Imported Sources
73 *
74 * Revision 1.7 1999/11/13 23:41:00 ngorham
75 *
76 * Alter the way DM logging works
77 * Upgrade the Postgres driver to 6.4.6
78 *
79 * Revision 1.6 1999/10/24 23:54:18 ngorham
80 *
81 * First part of the changes to the error reporting
82 *
83 * Revision 1.5 1999/09/21 22:34:25 ngorham
84 *
85 * Improve performance by removing unneeded logging calls when logging is
86 * disabled
87 *
88 * Revision 1.4 1999/07/10 21:10:17 ngorham
89 *
90 * Adjust error sqlstate from driver manager, depending on requested
91 * version (ODBC2/3)
92 *
93 * Revision 1.3 1999/07/04 21:05:08 ngorham
94 *
95 * Add LGPL Headers to code
96 *
97 * Revision 1.2 1999/06/30 23:56:55 ngorham
98 *
99 * Add initial thread safety code
100 *
101 * Revision 1.1.1.1 1999/05/29 13:41:08 sShandyb
102 * first go at it
103 *
104 * Revision 1.1.1.1 1999/05/27 18:23:18 pharvey
105 * Imported sources
106 *
107 * Revision 1.2 1999/05/03 19:50:43 nick
108 * Another check point
109 *
110 * Revision 1.1 1999/04/25 23:06:11 nick
111 * Initial revision
112 *
113 *
114 **********************************************************************/
115
116#include <config.h>
117#include "drivermanager.h"
118
119static char const rcsid[]= "$RCSfile: SQLSetCursorName.c,v $ $Revision: 1.6 $";
120
121SQLRETURN SQLSetCursorNameA( SQLHSTMT statement_handle,
122 SQLCHAR *cursor_name,
123 SQLSMALLINT name_length )
124{
125 return SQLSetCursorName( statement_handle,
126 cursor_name,
127 name_length );
128}
129
130SQLRETURN SQLSetCursorName( SQLHSTMT statement_handle,
131 SQLCHAR *cursor_name,
132 SQLSMALLINT name_length )
133{
134 DMHSTMT statement = (DMHSTMT) statement_handle;
135 SQLRETURN ret;
136 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
137
138 /*
139 * check statement
140 */
141
142 if ( !__validate_stmt( statement ))
143 {
144 dm_log_write( __FILE__,
145 __LINE__,
146 LOG_INFO,
147 LOG_INFO,
148 "Error: SQL_INVALID_HANDLE" );
149
150 return SQL_INVALID_HANDLE;
151 }
152
153 function_entry( statement );
154
155 if ( log_info.log_flag )
156 {
157 sprintf( statement -> msg, "\n\t\tEntry:\
158\n\t\t\tStatement = %p\
159\n\t\t\tCursor name = %s",
160 statement,
161 __string_with_length( s1, cursor_name, name_length ));
162
163 dm_log_write( __FILE__,
164 __LINE__,
165 LOG_INFO,
166 LOG_INFO,
167 statement -> msg );
168 }
169
170 thread_protect( SQL_HANDLE_STMT, statement );
171
172 if ( !cursor_name ||
173 (name_length < 0 && name_length != SQL_NTS ) )
174 {
175 dm_log_write( __FILE__,
176 __LINE__,
177 LOG_INFO,
178 LOG_INFO,
179 "Error: HY009" );
180
181 __post_internal_error( &statement -> error,
182 ERROR_HY009, NULL,
183 statement -> connection -> environment -> requested_version );
184
185 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
186 }
187
188 /*
189 * check states
190 */
191
192 if ( statement -> state == STATE_S4 ||
193 statement -> state == STATE_S5 ||
194 statement -> state == STATE_S6 ||
195 statement -> state == STATE_S7 )
196 {
197 dm_log_write( __FILE__,
198 __LINE__,
199 LOG_INFO,
200 LOG_INFO,
201 "Error: 24000" );
202
203 __post_internal_error( &statement -> error,
204 ERROR_24000, NULL,
205 statement -> connection -> environment -> requested_version );
206
207 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
208 }
209
210 if ( statement -> state == STATE_S8 ||
211 statement -> state == STATE_S9 ||
212 statement -> state == STATE_S10 ||
213 statement -> state == STATE_S11 ||
214 statement -> state == STATE_S12 ||
215 statement -> state == STATE_S13 ||
216 statement -> state == STATE_S14 ||
217 statement -> state == STATE_S15 )
218 {
219 dm_log_write( __FILE__,
220 __LINE__,
221 LOG_INFO,
222 LOG_INFO,
223 "Error: HY010" );
224
225 __post_internal_error( &statement -> error,
226 ERROR_HY010, NULL,
227 statement -> connection -> environment -> requested_version );
228
229 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
230 }
231
232 if ( statement -> connection -> unicode_driver )
233 {
234 SQLWCHAR *s1;
235 int wlen;
236
237 if ( !CHECK_SQLSETCURSORNAMEW( statement -> connection ))
238 {
239 dm_log_write( __FILE__,
240 __LINE__,
241 LOG_INFO,
242 LOG_INFO,
243 "Error: IM001" );
244
245 __post_internal_error( &statement -> error,
246 ERROR_IM001, NULL,
247 statement -> connection -> environment -> requested_version );
248
249 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
250 }
251
252 s1 = ansi_to_unicode_alloc( cursor_name, name_length, statement -> connection, &wlen );
253
254 name_length = wlen;
255
256 ret = SQLSETCURSORNAMEW( statement -> connection,
257 statement -> driver_stmt,
258 s1,
259 name_length );
260
261 if ( s1 )
262 free( s1 );
263 }
264 else
265 {
266 if ( !CHECK_SQLSETCURSORNAME( statement -> connection ))
267 {
268 dm_log_write( __FILE__,
269 __LINE__,
270 LOG_INFO,
271 LOG_INFO,
272 "Error: IM001" );
273
274 __post_internal_error( &statement -> error,
275 ERROR_IM001, NULL,
276 statement -> connection -> environment -> requested_version );
277
278 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
279 }
280
281 ret = SQLSETCURSORNAME( statement -> connection,
282 statement -> driver_stmt,
283 cursor_name,
284 name_length );
285 }
286
287 if ( log_info.log_flag )
288 {
289 sprintf( statement -> msg,
290 "\n\t\tExit:[%s]",
291 __get_return_status( ret, s1 ));
292
293 dm_log_write( __FILE__,
294 __LINE__,
295 LOG_INFO,
296 LOG_INFO,
297 statement -> msg );
298 }
299
300 return function_return( SQL_HANDLE_STMT, statement, ret );
301}
302