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: SQLSetCursorNameW.c,v 1.7 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLSetCursorNameW.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 2008/08/29 08:01:39 lurcher
37 * Alter the way W functions are passed to the driver
38 *
39 * Revision 1.5 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.4 2002/12/05 17:44:31 lurcher
47 *
48 * Display unknown return values in return logging
49 *
50 * Revision 1.3 2002/08/23 09:42:37 lurcher
51 *
52 * Fix some build warnings with casts, and a AIX linker mod, to include
53 * deplib's on the link line, but not the libtool generated ones
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:07 lurcher
60 *
61 * First upload to SourceForge
62 *
63 * Revision 1.3 2001/07/03 09:30:41 nick
64 *
65 * Add ability to alter size of displayed message in the log
66 *
67 * Revision 1.2 2001/04/12 17:43:36 nick
68 *
69 * Change logging and added autotest to odbctest
70 *
71 * Revision 1.1 2000/12/31 20:30:54 nick
72 *
73 * Add UNICODE support
74 *
75 *
76 **********************************************************************/
77
78#include <config.h>
79#include "drivermanager.h"
80
81static char const rcsid[]= "$RCSfile: SQLSetCursorNameW.c,v $";
82
83SQLRETURN SQLSetCursorNameW( SQLHSTMT statement_handle,
84 SQLWCHAR *cursor_name,
85 SQLSMALLINT name_length )
86{
87 DMHSTMT statement = (DMHSTMT) statement_handle;
88 SQLRETURN ret;
89 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
90
91 /*
92 * check statement
93 */
94
95 if ( !__validate_stmt( statement ))
96 {
97 dm_log_write( __FILE__,
98 __LINE__,
99 LOG_INFO,
100 LOG_INFO,
101 "Error: SQL_INVALID_HANDLE" );
102
103 return SQL_INVALID_HANDLE;
104 }
105
106 function_entry( statement );
107
108 if ( log_info.log_flag )
109 {
110 sprintf( statement -> msg, "\n\t\tEntry:\
111\n\t\t\tStatement = %p\
112\n\t\t\tCursor name = %s",
113 statement,
114 __wstring_with_length( s1, cursor_name, name_length ));
115
116 dm_log_write( __FILE__,
117 __LINE__,
118 LOG_INFO,
119 LOG_INFO,
120 statement -> msg );
121 }
122
123 thread_protect( SQL_HANDLE_STMT, statement );
124
125 if ( !cursor_name ||
126 (name_length < 0 && name_length != SQL_NTS ) )
127 {
128 dm_log_write( __FILE__,
129 __LINE__,
130 LOG_INFO,
131 LOG_INFO,
132 "Error: HY009" );
133
134 __post_internal_error( &statement -> error,
135 ERROR_HY009, NULL,
136 statement -> connection -> environment -> requested_version );
137
138 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
139 }
140
141 /*
142 * check states
143 */
144
145 if ( statement -> state == STATE_S4 ||
146 statement -> state == STATE_S5 ||
147 statement -> state == STATE_S6 ||
148 statement -> state == STATE_S7 )
149 {
150 dm_log_write( __FILE__,
151 __LINE__,
152 LOG_INFO,
153 LOG_INFO,
154 "Error: 24000" );
155
156 __post_internal_error( &statement -> error,
157 ERROR_24000, NULL,
158 statement -> connection -> environment -> requested_version );
159
160 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
161 }
162
163 if ( statement -> state == STATE_S8 ||
164 statement -> state == STATE_S9 ||
165 statement -> state == STATE_S10 ||
166 statement -> state == STATE_S11 ||
167 statement -> state == STATE_S12 ||
168 statement -> state == STATE_S13 ||
169 statement -> state == STATE_S14 ||
170 statement -> state == STATE_S15 )
171 {
172 dm_log_write( __FILE__,
173 __LINE__,
174 LOG_INFO,
175 LOG_INFO,
176 "Error: HY010" );
177
178 __post_internal_error( &statement -> error,
179 ERROR_HY010, NULL,
180 statement -> connection -> environment -> requested_version );
181
182 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
183 }
184
185 if ( statement -> connection -> unicode_driver ||
186 CHECK_SQLSETCURSORNAMEW( statement -> connection ))
187 {
188 if ( !CHECK_SQLSETCURSORNAMEW( statement -> connection ))
189 {
190 dm_log_write( __FILE__,
191 __LINE__,
192 LOG_INFO,
193 LOG_INFO,
194 "Error: IM001" );
195
196 __post_internal_error( &statement -> error,
197 ERROR_IM001, NULL,
198 statement -> connection -> environment -> requested_version );
199
200 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
201 }
202
203 ret = SQLSETCURSORNAMEW( statement -> connection,
204 statement -> driver_stmt,
205 cursor_name,
206 name_length );
207 }
208 else
209 {
210 SQLCHAR *as1;
211 int clen;
212
213 if ( !CHECK_SQLSETCURSORNAME( statement -> connection ))
214 {
215 dm_log_write( __FILE__,
216 __LINE__,
217 LOG_INFO,
218 LOG_INFO,
219 "Error: IM001" );
220
221 __post_internal_error( &statement -> error,
222 ERROR_IM001, NULL,
223 statement -> connection -> environment -> requested_version );
224
225 return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR );
226 }
227
228 as1 = (SQLCHAR*) unicode_to_ansi_alloc( cursor_name, name_length, statement -> connection, &clen );
229
230 name_length = clen;
231
232 ret = SQLSETCURSORNAME( statement -> connection,
233 statement -> driver_stmt,
234 as1,
235 name_length );
236
237 if ( as1 ) free( as1 );
238 }
239
240 if ( log_info.log_flag )
241 {
242 sprintf( statement -> msg,
243 "\n\t\tExit:[%s]",
244 __get_return_status( ret, s1 ));
245
246 dm_log_write( __FILE__,
247 __LINE__,
248 LOG_INFO,
249 LOG_INFO,
250 statement -> msg );
251 }
252
253 return function_return( SQL_HANDLE_STMT, statement, ret );
254}
255