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