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: SQLGetCursorNameW.c,v 1.9 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLGetCursorNameW.c,v $ |
33 | * Revision 1.9 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.8 2008/08/29 08:01:39 lurcher |
37 | * Alter the way W functions are passed to the driver |
38 | * |
39 | * Revision 1.7 2007/02/28 15:37:48 lurcher |
40 | * deal with drivers that call internal W functions and end up in the driver manager. controlled by the --enable-handlemap configure arg |
41 | * |
42 | * Revision 1.6 2003/10/30 18:20:46 lurcher |
43 | * |
44 | * Fix broken thread protection |
45 | * Remove SQLNumResultCols after execute, lease S4/S% to driver |
46 | * Fix string overrun in SQLDriverConnect |
47 | * Add initial support for Interix |
48 | * |
49 | * Revision 1.5 2002/12/05 17:44:30 lurcher |
50 | * |
51 | * Display unknown return values in return logging |
52 | * |
53 | * Revision 1.4 2002/08/23 09:42:37 lurcher |
54 | * |
55 | * Fix some build warnings with casts, and a AIX linker mod, to include |
56 | * deplib's on the link line, but not the libtool generated ones |
57 | * |
58 | * Revision 1.3 2002/07/24 08:49:52 lurcher |
59 | * |
60 | * Alter UNICODE support to use iconv for UNICODE-ANSI conversion |
61 | * |
62 | * Revision 1.2 2001/12/13 13:00:32 lurcher |
63 | * |
64 | * Remove most if not all warnings on 64 bit platforms |
65 | * Add support for new MS 3.52 64 bit changes |
66 | * Add override to disable the stopping of tracing |
67 | * Add MAX_ROWS support in postgres driver |
68 | * |
69 | * Revision 1.1.1.1 2001/10/17 16:40:05 lurcher |
70 | * |
71 | * First upload to SourceForge |
72 | * |
73 | * Revision 1.4 2001/07/03 09:30:41 nick |
74 | * |
75 | * Add ability to alter size of displayed message in the log |
76 | * |
77 | * Revision 1.3 2001/04/12 17:43:36 nick |
78 | * |
79 | * Change logging and added autotest to odbctest |
80 | * |
81 | * Revision 1.2 2001/01/04 13:16:25 nick |
82 | * |
83 | * Add support for GNU portable threads and tidy up some UNICODE compile |
84 | * warnings |
85 | * |
86 | * Revision 1.1 2000/12/31 20:30:54 nick |
87 | * |
88 | * Add UNICODE support |
89 | * |
90 | * |
91 | **********************************************************************/ |
92 | |
93 | #include <config.h> |
94 | #include "drivermanager.h" |
95 | |
96 | static char const rcsid[]= "$RCSfile: SQLGetCursorNameW.c,v $" ; |
97 | |
98 | SQLRETURN SQLGetCursorNameW( SQLHSTMT statement_handle, |
99 | SQLWCHAR *cursor_name, |
100 | SQLSMALLINT buffer_length, |
101 | SQLSMALLINT *name_length ) |
102 | { |
103 | DMHSTMT statement = (DMHSTMT) statement_handle; |
104 | SQLRETURN ret; |
105 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
106 | |
107 | /* |
108 | * check statement |
109 | */ |
110 | |
111 | if ( !__validate_stmt( statement )) |
112 | { |
113 | dm_log_write( __FILE__, |
114 | __LINE__, |
115 | LOG_INFO, |
116 | LOG_INFO, |
117 | "Error: SQL_INVALID_HANDLE" ); |
118 | |
119 | #ifdef WITH_HANDLE_REDIRECT |
120 | { |
121 | DMHSTMT parent_statement; |
122 | |
123 | parent_statement = find_parent_handle( statement, SQL_HANDLE_STMT ); |
124 | |
125 | if ( parent_statement ) { |
126 | dm_log_write( __FILE__, |
127 | __LINE__, |
128 | LOG_INFO, |
129 | LOG_INFO, |
130 | "Info: found parent handle" ); |
131 | |
132 | if ( CHECK_SQLGETCURSORNAMEW( parent_statement -> connection )) |
133 | { |
134 | dm_log_write( __FILE__, |
135 | __LINE__, |
136 | LOG_INFO, |
137 | LOG_INFO, |
138 | "Info: calling redirected driver function" ); |
139 | |
140 | return SQLGETCURSORNAMEW( parent_statement -> connection, |
141 | statement_handle, |
142 | cursor_name, |
143 | buffer_length, |
144 | name_length ); |
145 | } |
146 | } |
147 | } |
148 | #endif |
149 | return SQL_INVALID_HANDLE; |
150 | } |
151 | |
152 | function_entry( statement ); |
153 | |
154 | if ( log_info.log_flag ) |
155 | { |
156 | sprintf( statement -> msg, "\n\t\tEntry:\ |
157 | \n\t\t\tStatement = %p\ |
158 | \n\t\t\tCursor Name = %p\ |
159 | \n\t\t\tBuffer Length = %d\ |
160 | \n\t\t\tName Length= %p" , |
161 | statement, |
162 | cursor_name, |
163 | buffer_length, |
164 | name_length ); |
165 | |
166 | dm_log_write( __FILE__, |
167 | __LINE__, |
168 | LOG_INFO, |
169 | LOG_INFO, |
170 | statement -> msg ); |
171 | } |
172 | |
173 | thread_protect( SQL_HANDLE_STMT, statement ); |
174 | |
175 | if ( buffer_length < 0 ) |
176 | { |
177 | dm_log_write( __FILE__, |
178 | __LINE__, |
179 | LOG_INFO, |
180 | LOG_INFO, |
181 | "Error: HY090" ); |
182 | |
183 | __post_internal_error( &statement -> error, |
184 | ERROR_HY090, NULL, |
185 | statement -> connection -> environment -> requested_version ); |
186 | |
187 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
188 | } |
189 | |
190 | /* |
191 | * check states |
192 | */ |
193 | |
194 | if ( statement -> state == STATE_S8 || |
195 | statement -> state == STATE_S9 || |
196 | statement -> state == STATE_S10 || |
197 | statement -> state == STATE_S11 || |
198 | statement -> state == STATE_S12 || |
199 | statement -> state == STATE_S13 || |
200 | statement -> state == STATE_S14 || |
201 | statement -> state == STATE_S15 ) |
202 | { |
203 | dm_log_write( __FILE__, |
204 | __LINE__, |
205 | LOG_INFO, |
206 | LOG_INFO, |
207 | "Error: HY010" ); |
208 | |
209 | __post_internal_error( &statement -> error, |
210 | ERROR_HY010, NULL, |
211 | statement -> connection -> environment -> requested_version ); |
212 | |
213 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
214 | } |
215 | |
216 | if ( statement -> connection -> unicode_driver || |
217 | CHECK_SQLGETCURSORNAMEW( statement -> connection )) |
218 | { |
219 | if ( !CHECK_SQLGETCURSORNAMEW( statement -> connection )) |
220 | { |
221 | dm_log_write( __FILE__, |
222 | __LINE__, |
223 | LOG_INFO, |
224 | LOG_INFO, |
225 | "Error: IM001" ); |
226 | |
227 | __post_internal_error( &statement -> error, |
228 | ERROR_IM001, NULL, |
229 | statement -> connection -> environment -> requested_version ); |
230 | |
231 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
232 | } |
233 | |
234 | ret = SQLGETCURSORNAMEW( statement -> connection, |
235 | statement -> driver_stmt, |
236 | cursor_name, |
237 | buffer_length, |
238 | name_length ); |
239 | } |
240 | else |
241 | { |
242 | SQLCHAR *as1 = NULL; |
243 | |
244 | if ( !CHECK_SQLGETCURSORNAME( statement -> connection )) |
245 | { |
246 | dm_log_write( __FILE__, |
247 | __LINE__, |
248 | LOG_INFO, |
249 | LOG_INFO, |
250 | "Error: IM001" ); |
251 | |
252 | __post_internal_error( &statement -> error, |
253 | ERROR_IM001, NULL, |
254 | statement -> connection -> environment -> requested_version ); |
255 | |
256 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
257 | } |
258 | |
259 | if ( cursor_name && buffer_length > 0 ) |
260 | { |
261 | as1 = malloc( buffer_length + 1 ); |
262 | } |
263 | |
264 | ret = SQLGETCURSORNAME( statement -> connection, |
265 | statement -> driver_stmt, |
266 | as1 ? as1 : (SQLCHAR*) cursor_name, |
267 | buffer_length, |
268 | name_length ); |
269 | |
270 | if ( SQL_SUCCEEDED( ret ) && cursor_name && as1 ) |
271 | { |
272 | ansi_to_unicode_copy( cursor_name, (char*) as1, SQL_NTS, statement -> connection, NULL ); |
273 | } |
274 | |
275 | if ( as1 ) |
276 | { |
277 | free( as1 ); |
278 | } |
279 | } |
280 | |
281 | if ( log_info.log_flag ) |
282 | { |
283 | sprintf( statement -> msg, |
284 | "\n\t\tExit:[%s]\ |
285 | \n\t\t\tCursor Name = %s" , |
286 | __get_return_status( ret, s1 ), |
287 | __sdata_as_string( s1, SQL_WCHAR, |
288 | name_length, cursor_name )); |
289 | |
290 | dm_log_write( __FILE__, |
291 | __LINE__, |
292 | LOG_INFO, |
293 | LOG_INFO, |
294 | statement -> msg ); |
295 | } |
296 | |
297 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
298 | } |
299 | |