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: SQLSetConnectAttrW.c,v 1.14 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLSetConnectAttrW.c,v $ |
33 | * Revision 1.14 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.13 2008/08/29 08:01:39 lurcher |
37 | * Alter the way W functions are passed to the driver |
38 | * |
39 | * Revision 1.12 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.11 2006/04/18 10:24:47 lurcher |
43 | * Add a couple of changes from Mark Vanderwiel |
44 | * |
45 | * Revision 1.10 2003/10/30 18:20:46 lurcher |
46 | * |
47 | * Fix broken thread protection |
48 | * Remove SQLNumResultCols after execute, lease S4/S% to driver |
49 | * Fix string overrun in SQLDriverConnect |
50 | * Add initial support for Interix |
51 | * |
52 | * Revision 1.9 2003/03/05 09:48:44 lurcher |
53 | * |
54 | * Add some 64 bit fixes |
55 | * |
56 | * Revision 1.8 2002/12/05 17:44:31 lurcher |
57 | * |
58 | * Display unknown return values in return logging |
59 | * |
60 | * Revision 1.7 2002/08/23 09:42:37 lurcher |
61 | * |
62 | * Fix some build warnings with casts, and a AIX linker mod, to include |
63 | * deplib's on the link line, but not the libtool generated ones |
64 | * |
65 | * Revision 1.6 2002/07/24 08:49:52 lurcher |
66 | * |
67 | * Alter UNICODE support to use iconv for UNICODE-ANSI conversion |
68 | * |
69 | * Revision 1.5 2002/07/16 13:08:18 lurcher |
70 | * |
71 | * Filter attribute values from SQLSetStmtAttr to SQLSetStmtOption to fit |
72 | * within ODBC 2 |
73 | * Make DSN's double clickable in ODBCConfig |
74 | * |
75 | * Revision 1.4 2002/07/04 17:27:56 lurcher |
76 | * |
77 | * Small bug fixes |
78 | * |
79 | * Revision 1.3 2002/01/30 12:20:02 lurcher |
80 | * |
81 | * Add MyODBC 3 driver source |
82 | * |
83 | * Revision 1.2 2001/12/13 13:00:32 lurcher |
84 | * |
85 | * Remove most if not all warnings on 64 bit platforms |
86 | * Add support for new MS 3.52 64 bit changes |
87 | * Add override to disable the stopping of tracing |
88 | * Add MAX_ROWS support in postgres driver |
89 | * |
90 | * Revision 1.1.1.1 2001/10/17 16:40:07 lurcher |
91 | * |
92 | * First upload to SourceForge |
93 | * |
94 | * Revision 1.7 2001/09/27 17:05:48 nick |
95 | * |
96 | * Assorted fixes and tweeks |
97 | * |
98 | * Revision 1.6 2001/08/08 17:05:17 nick |
99 | * |
100 | * Add support for attribute setting in the ini files |
101 | * |
102 | * Revision 1.5 2001/08/03 15:19:00 nick |
103 | * |
104 | * Add changes to set values before connect |
105 | * |
106 | * Revision 1.4 2001/07/03 09:30:41 nick |
107 | * |
108 | * Add ability to alter size of displayed message in the log |
109 | * |
110 | * Revision 1.3 2001/05/23 13:48:37 nick |
111 | * |
112 | * Remove unwanted include |
113 | * |
114 | * Revision 1.2 2001/04/12 17:43:36 nick |
115 | * |
116 | * Change logging and added autotest to odbctest |
117 | * |
118 | * Revision 1.1 2000/12/31 20:30:54 nick |
119 | * |
120 | * Add UNICODE support |
121 | * |
122 | * |
123 | **********************************************************************/ |
124 | |
125 | #include <config.h> |
126 | #include "drivermanager.h" |
127 | |
128 | static char const rcsid[]= "$RCSfile: SQLSetConnectAttrW.c,v $" ; |
129 | |
130 | SQLRETURN SQLSetConnectAttrW( SQLHDBC connection_handle, |
131 | SQLINTEGER attribute, |
132 | SQLPOINTER value, |
133 | SQLINTEGER string_length ) |
134 | { |
135 | DMHDBC connection = (DMHDBC)connection_handle; |
136 | SQLRETURN ret; |
137 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
138 | SQLWCHAR buffer[ 512 ]; |
139 | |
140 | /* |
141 | * doesn't require a handle |
142 | */ |
143 | |
144 | if ( attribute == SQL_ATTR_TRACE ) |
145 | { |
146 | if ((SQLLEN) value != SQL_OPT_TRACE_OFF && |
147 | (SQLLEN) value != SQL_OPT_TRACE_ON ) |
148 | { |
149 | if ( __validate_dbc( connection )) |
150 | { |
151 | thread_protect( SQL_HANDLE_DBC, connection ); |
152 | dm_log_write( __FILE__, |
153 | __LINE__, |
154 | LOG_INFO, |
155 | LOG_INFO, |
156 | "Error: HY024" ); |
157 | |
158 | __post_internal_error( &connection -> error, |
159 | ERROR_HY024, NULL, |
160 | connection -> environment -> requested_version ); |
161 | |
162 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
163 | } |
164 | else |
165 | { |
166 | return SQL_INVALID_HANDLE; |
167 | } |
168 | } |
169 | |
170 | if ((SQLLEN) value == SQL_OPT_TRACE_OFF ) |
171 | { |
172 | char force_string[ 30 ]; |
173 | |
174 | SQLGetPrivateProfileString( "ODBC" , "ForceTrace" , "0" , |
175 | force_string, sizeof( force_string ), |
176 | "ODBCINST.INI" ); |
177 | |
178 | if ( force_string[ 0 ] == '1' || |
179 | toupper( force_string[ 0 ] ) == 'Y' || |
180 | ( toupper( force_string[ 0 ] ) == 'O' && |
181 | toupper( force_string[ 1 ] ) == 'N' )) |
182 | { |
183 | if ( log_info.log_flag ) |
184 | { |
185 | dm_log_write( __FILE__, |
186 | __LINE__, |
187 | LOG_INFO, |
188 | LOG_INFO, |
189 | "Application tried to turn logging off" ); |
190 | } |
191 | } |
192 | else |
193 | { |
194 | if ( log_info.log_flag ) |
195 | { |
196 | dm_log_write( __FILE__, |
197 | __LINE__, |
198 | LOG_INFO, |
199 | LOG_INFO, |
200 | "Application turning logging off" ); |
201 | } |
202 | log_info.log_flag = 0; |
203 | } |
204 | } |
205 | else |
206 | { |
207 | log_info.log_flag = 1; |
208 | } |
209 | |
210 | return SQL_SUCCESS; |
211 | } |
212 | else if ( attribute == SQL_ATTR_TRACEFILE ) |
213 | { |
214 | if ( value ) |
215 | { |
216 | if (((SQLWCHAR*)value)[ 0 ] == 0 ) |
217 | { |
218 | if ( __validate_dbc( connection )) |
219 | { |
220 | thread_protect( SQL_HANDLE_DBC, connection ); |
221 | dm_log_write( __FILE__, |
222 | __LINE__, |
223 | LOG_INFO, |
224 | LOG_INFO, |
225 | "Error: HY024" ); |
226 | |
227 | __post_internal_error( &connection -> error, |
228 | ERROR_HY024, NULL, |
229 | connection -> environment -> requested_version ); |
230 | |
231 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
232 | } |
233 | else |
234 | { |
235 | return SQL_INVALID_HANDLE; |
236 | } |
237 | } |
238 | else |
239 | { |
240 | if ( log_info.log_file_name ) |
241 | { |
242 | free( log_info.log_file_name ); |
243 | } |
244 | log_info.log_file_name = unicode_to_ansi_alloc((SQLWCHAR *) value, SQL_NTS, connection, NULL ); |
245 | } |
246 | } |
247 | else |
248 | { |
249 | if ( __validate_dbc( connection )) |
250 | { |
251 | thread_protect( SQL_HANDLE_DBC, connection ); |
252 | dm_log_write( __FILE__, |
253 | __LINE__, |
254 | LOG_INFO, |
255 | LOG_INFO, |
256 | "Error: HY024" ); |
257 | |
258 | __post_internal_error( &connection -> error, |
259 | ERROR_HY024, NULL, |
260 | connection -> environment -> requested_version ); |
261 | |
262 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
263 | } |
264 | else |
265 | { |
266 | return SQL_INVALID_HANDLE; |
267 | } |
268 | } |
269 | return SQL_SUCCESS; |
270 | } |
271 | |
272 | /* |
273 | * check connection |
274 | */ |
275 | |
276 | if ( !__validate_dbc( connection )) |
277 | { |
278 | dm_log_write( __FILE__, |
279 | __LINE__, |
280 | LOG_INFO, |
281 | LOG_INFO, |
282 | "Error: SQL_INVALID_HANDLE" ); |
283 | |
284 | #ifdef WITH_HANDLE_REDIRECT |
285 | { |
286 | DMHDBC parent_connection; |
287 | |
288 | parent_connection = find_parent_handle( connection, SQL_HANDLE_DBC ); |
289 | |
290 | if ( parent_connection ) { |
291 | dm_log_write( __FILE__, |
292 | __LINE__, |
293 | LOG_INFO, |
294 | LOG_INFO, |
295 | "Info: found parent handle" ); |
296 | |
297 | if ( CHECK_SQLSETCONNECTATTRW( parent_connection )) |
298 | { |
299 | dm_log_write( __FILE__, |
300 | __LINE__, |
301 | LOG_INFO, |
302 | LOG_INFO, |
303 | "Info: calling redirected driver function" ); |
304 | |
305 | return SQLSETCONNECTATTRW( parent_connection, |
306 | connection_handle, |
307 | attribute, |
308 | value, |
309 | string_length ); |
310 | } |
311 | } |
312 | } |
313 | #endif |
314 | return SQL_INVALID_HANDLE; |
315 | } |
316 | |
317 | function_entry( connection ); |
318 | |
319 | if ( log_info.log_flag ) |
320 | { |
321 | sprintf( connection -> msg, "\n\t\tEntry:\ |
322 | \n\t\t\tConnection = %p\ |
323 | \n\t\t\tAttribute = %s\ |
324 | \n\t\t\tValue = %p\ |
325 | \n\t\t\tStrLen = %d" , |
326 | connection, |
327 | __con_attr_as_string( s1, attribute ), |
328 | value, |
329 | (int)string_length ); |
330 | |
331 | dm_log_write( __FILE__, |
332 | __LINE__, |
333 | LOG_INFO, |
334 | LOG_INFO, |
335 | connection -> msg ); |
336 | } |
337 | |
338 | thread_protect( SQL_HANDLE_DBC, connection ); |
339 | |
340 | if ( connection -> state == STATE_C2 ) |
341 | { |
342 | if ( attribute == SQL_ATTR_TRANSLATE_OPTION || |
343 | attribute == SQL_ATTR_TRANSLATE_LIB ) |
344 | { |
345 | dm_log_write( __FILE__, |
346 | __LINE__, |
347 | LOG_INFO, |
348 | LOG_INFO, |
349 | "Error: 08003" ); |
350 | |
351 | __post_internal_error( &connection -> error, |
352 | ERROR_08003, NULL, |
353 | connection -> environment -> requested_version ); |
354 | |
355 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
356 | } |
357 | } |
358 | else if ( connection -> state == STATE_C3 ) |
359 | { |
360 | dm_log_write( __FILE__, |
361 | __LINE__, |
362 | LOG_INFO, |
363 | LOG_INFO, |
364 | "Error: HY010" ); |
365 | |
366 | __post_internal_error( &connection -> error, |
367 | ERROR_HY010, NULL, |
368 | connection -> environment -> requested_version ); |
369 | |
370 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
371 | } |
372 | else if ( connection -> state == STATE_C4 || |
373 | connection -> state == STATE_C5 || |
374 | connection -> state == STATE_C6 ) |
375 | { |
376 | if ( attribute == SQL_ATTR_ODBC_CURSORS ) |
377 | { |
378 | dm_log_write( __FILE__, |
379 | __LINE__, |
380 | LOG_INFO, |
381 | LOG_INFO, |
382 | "Error: 08002" ); |
383 | |
384 | __post_internal_error( &connection -> error, |
385 | ERROR_08002, NULL, |
386 | connection -> environment -> requested_version ); |
387 | |
388 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
389 | } |
390 | else if ( attribute == SQL_ATTR_PACKET_SIZE ) |
391 | { |
392 | dm_log_write( __FILE__, |
393 | __LINE__, |
394 | LOG_INFO, |
395 | LOG_INFO, |
396 | "Error: HY011" ); |
397 | |
398 | __post_internal_error( &connection -> error, |
399 | ERROR_HY011, NULL, |
400 | connection -> environment -> requested_version ); |
401 | |
402 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
403 | } |
404 | } |
405 | |
406 | /* |
407 | * is it a legitimate value |
408 | */ |
409 | ret = dm_check_connection_attrs( connection, attribute, value ); |
410 | |
411 | if ( ret != SQL_SUCCESS ) |
412 | { |
413 | dm_log_write( __FILE__, |
414 | __LINE__, |
415 | LOG_INFO, |
416 | LOG_INFO, |
417 | "Error: HY024" ); |
418 | |
419 | __post_internal_error( &connection -> error, |
420 | ERROR_HY024, NULL, |
421 | connection -> environment -> requested_version ); |
422 | |
423 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
424 | } |
425 | |
426 | /* |
427 | * is it a connection attribute or statement, check state of any active connections |
428 | */ |
429 | |
430 | switch( attribute ) |
431 | { |
432 | /* ODBC 3.x statement attributes are not settable at the connection level */ |
433 | case SQL_ATTR_APP_PARAM_DESC: |
434 | case SQL_ATTR_APP_ROW_DESC: |
435 | case SQL_ATTR_CURSOR_SCROLLABLE: |
436 | case SQL_ATTR_CURSOR_SENSITIVITY: |
437 | case SQL_ATTR_ENABLE_AUTO_IPD: |
438 | case SQL_ATTR_FETCH_BOOKMARK_PTR: |
439 | case SQL_ATTR_IMP_PARAM_DESC: |
440 | case SQL_ATTR_IMP_ROW_DESC: |
441 | case SQL_ATTR_PARAM_BIND_OFFSET_PTR: |
442 | case SQL_ATTR_PARAM_BIND_TYPE: |
443 | case SQL_ATTR_PARAM_OPERATION_PTR: |
444 | case SQL_ATTR_PARAM_STATUS_PTR: |
445 | case SQL_ATTR_PARAMS_PROCESSED_PTR: |
446 | case SQL_ATTR_PARAMSET_SIZE: |
447 | case SQL_ATTR_ROW_ARRAY_SIZE: |
448 | case SQL_ATTR_ROW_BIND_OFFSET_PTR: |
449 | case SQL_ATTR_ROW_OPERATION_PTR: |
450 | case SQL_ATTR_ROW_STATUS_PTR: |
451 | case SQL_ATTR_ROWS_FETCHED_PTR: |
452 | __post_internal_error( &connection -> error, |
453 | ERROR_HY092, NULL, |
454 | connection -> environment -> requested_version ); |
455 | |
456 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
457 | |
458 | case SQL_ATTR_CONCURRENCY: |
459 | case SQL_BIND_TYPE: |
460 | case SQL_ATTR_CURSOR_TYPE: |
461 | case SQL_ATTR_MAX_LENGTH: |
462 | case SQL_MAX_ROWS: |
463 | case SQL_ATTR_KEYSET_SIZE: |
464 | case SQL_ROWSET_SIZE: |
465 | case SQL_ATTR_NOSCAN: |
466 | case SQL_ATTR_QUERY_TIMEOUT: |
467 | case SQL_ATTR_RETRIEVE_DATA: |
468 | case SQL_ATTR_SIMULATE_CURSOR: |
469 | case SQL_ATTR_USE_BOOKMARKS: |
470 | if( __check_stmt_from_dbc_v( connection, 8, STATE_S8, STATE_S9, STATE_S10, STATE_S11, STATE_S12, STATE_S13, STATE_S14, STATE_S15 )) { |
471 | |
472 | dm_log_write( __FILE__, |
473 | __LINE__, |
474 | LOG_INFO, |
475 | LOG_INFO, |
476 | "Error: 24000" ); |
477 | |
478 | __post_internal_error( &connection -> error, |
479 | ERROR_24000, NULL, |
480 | connection -> environment -> requested_version ); |
481 | |
482 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
483 | } |
484 | break; |
485 | |
486 | default: |
487 | |
488 | if( __check_stmt_from_dbc_v( connection, 8, STATE_S8, STATE_S9, STATE_S10, STATE_S11, STATE_S12, STATE_S13, STATE_S14, STATE_S15 )) { |
489 | |
490 | dm_log_write( __FILE__, |
491 | __LINE__, |
492 | LOG_INFO, |
493 | LOG_INFO, |
494 | "Error: HY010" ); |
495 | |
496 | __post_internal_error( &connection -> error, |
497 | ERROR_HY010, NULL, |
498 | connection -> environment -> requested_version ); |
499 | |
500 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
501 | } |
502 | break; |
503 | } |
504 | |
505 | /* |
506 | * is it something overridden |
507 | */ |
508 | |
509 | value = __attr_override_wide( connection, SQL_HANDLE_DBC, attribute, value, &string_length, buffer ); |
510 | |
511 | /* |
512 | * we need to save this even if connected so we can use it for the next connect |
513 | */ |
514 | if ( attribute == SQL_ATTR_LOGIN_TIMEOUT ) |
515 | { |
516 | connection -> login_timeout = ( SQLLEN ) value; |
517 | connection -> login_timeout_set = 1; |
518 | } |
519 | |
520 | /* |
521 | * if connected, call the driver |
522 | * otherwise we need to save the states and set them when we |
523 | * do connect |
524 | */ |
525 | if ( connection -> state == STATE_C2 ) |
526 | { |
527 | /* |
528 | * is it for us |
529 | */ |
530 | |
531 | if ( attribute == SQL_ATTR_ODBC_CURSORS ) |
532 | { |
533 | connection -> cursors = ( SQLLEN ) value; |
534 | } |
535 | else if ( attribute == SQL_ATTR_ACCESS_MODE ) |
536 | { |
537 | connection -> access_mode = ( SQLLEN ) value; |
538 | connection -> access_mode_set = 1; |
539 | } |
540 | else if ( attribute == SQL_ATTR_ASYNC_ENABLE ) |
541 | { |
542 | connection -> async_enable = ( SQLLEN ) value; |
543 | connection -> async_enable_set = 1; |
544 | } |
545 | else if ( attribute == SQL_ATTR_AUTO_IPD ) |
546 | { |
547 | connection -> auto_ipd = ( SQLLEN ) value; |
548 | connection -> auto_ipd_set = 1; |
549 | } |
550 | else if ( attribute == SQL_ATTR_AUTOCOMMIT ) |
551 | { |
552 | connection -> auto_commit = ( SQLLEN ) value; |
553 | connection -> auto_commit_set = 1; |
554 | } |
555 | else if ( attribute == SQL_ATTR_CONNECTION_TIMEOUT ) |
556 | { |
557 | connection -> connection_timeout = ( SQLLEN ) value; |
558 | connection -> connection_timeout_set = 1; |
559 | } |
560 | else if ( attribute == SQL_ATTR_METADATA_ID ) |
561 | { |
562 | connection -> metadata_id = ( SQLLEN ) value; |
563 | connection -> metadata_id_set = 1; |
564 | } |
565 | else if ( attribute == SQL_ATTR_PACKET_SIZE ) |
566 | { |
567 | connection -> packet_size = ( SQLLEN ) value; |
568 | connection -> packet_size_set = 1; |
569 | } |
570 | else if ( attribute == SQL_ATTR_QUIET_MODE ) |
571 | { |
572 | connection -> quite_mode = ( SQLLEN ) value; |
573 | connection -> quite_mode_set = 1; |
574 | } |
575 | else if ( attribute == SQL_ATTR_TXN_ISOLATION ) |
576 | { |
577 | connection -> txn_isolation = ( SQLLEN ) value; |
578 | connection -> txn_isolation_set = 1; |
579 | } |
580 | else if ( attribute != SQL_ATTR_LOGIN_TIMEOUT ) |
581 | { |
582 | /* |
583 | * save any unknown attributes untill connect |
584 | */ |
585 | |
586 | struct save_attr *sa = calloc( 1, sizeof( struct save_attr )); |
587 | |
588 | sa -> attr_type = attribute; |
589 | if ( string_length > 0 ) |
590 | { |
591 | sa -> str_attr = malloc( string_length ); |
592 | memcpy( sa -> str_attr, value, string_length ); |
593 | sa -> str_len = string_length; |
594 | } |
595 | else if ( string_length == SQL_NTS ) |
596 | { |
597 | if (!value) |
598 | { |
599 | __post_internal_error( &connection -> error, |
600 | ERROR_HY024, "Invalid argument value" , |
601 | connection -> environment -> requested_version ); |
602 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
603 | } |
604 | else |
605 | { |
606 | sa -> str_attr = unicode_to_ansi_alloc( value, string_length, connection, NULL ); |
607 | sa -> str_len = string_length; |
608 | } |
609 | } |
610 | else |
611 | { |
612 | sa -> int_attr = ( SQLLEN ) value; |
613 | } |
614 | sa -> next = connection -> save_attr; |
615 | connection -> save_attr = sa; |
616 | } |
617 | |
618 | sprintf( connection -> msg, |
619 | "\n\t\tExit:[%s]" , |
620 | __get_return_status( SQL_SUCCESS, s1 )); |
621 | |
622 | dm_log_write( __FILE__, |
623 | __LINE__, |
624 | LOG_INFO, |
625 | LOG_INFO, |
626 | connection -> msg ); |
627 | |
628 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_SUCCESS ); |
629 | } |
630 | else |
631 | { |
632 | if ( connection -> unicode_driver || |
633 | CHECK_SQLSETCONNECTATTRW( connection )) |
634 | { |
635 | if ( !CHECK_SQLSETCONNECTATTRW( connection )) |
636 | { |
637 | if ( CHECK_SQLSETCONNECTOPTIONW( connection )) |
638 | { |
639 | /* |
640 | * Is it in the legal range of values |
641 | */ |
642 | |
643 | if ( attribute < SQL_CONN_DRIVER_MIN && |
644 | ( attribute > SQL_PACKET_SIZE || attribute < SQL_ACCESS_MODE )) |
645 | { |
646 | dm_log_write( __FILE__, |
647 | __LINE__, |
648 | LOG_INFO, |
649 | LOG_INFO, |
650 | "Error: HY092" ); |
651 | |
652 | __post_internal_error( &connection -> error, |
653 | ERROR_HY092, NULL, |
654 | connection -> environment -> requested_version ); |
655 | |
656 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
657 | } |
658 | |
659 | ret = SQLSETCONNECTOPTIONW( connection, |
660 | connection -> driver_dbc, |
661 | attribute, |
662 | value ); |
663 | } |
664 | else |
665 | { |
666 | dm_log_write( __FILE__, |
667 | __LINE__, |
668 | LOG_INFO, |
669 | LOG_INFO, |
670 | "Error: IM001" ); |
671 | |
672 | __post_internal_error( &connection -> error, |
673 | ERROR_IM001, NULL, |
674 | connection -> environment -> requested_version ); |
675 | |
676 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
677 | } |
678 | } |
679 | else |
680 | { |
681 | ret = SQLSETCONNECTATTRW( connection, |
682 | connection -> driver_dbc, |
683 | attribute, |
684 | value, |
685 | string_length ); |
686 | } |
687 | } |
688 | else |
689 | { |
690 | if ( !CHECK_SQLSETCONNECTATTR( connection )) |
691 | { |
692 | if ( CHECK_SQLSETCONNECTOPTION( connection )) |
693 | { |
694 | SQLCHAR *as1 = NULL; |
695 | |
696 | /* |
697 | * Is it in the legal range of values |
698 | */ |
699 | |
700 | if ( attribute < SQL_CONN_DRIVER_MIN && |
701 | ( attribute > SQL_PACKET_SIZE || attribute < SQL_ACCESS_MODE )) |
702 | { |
703 | dm_log_write( __FILE__, |
704 | __LINE__, |
705 | LOG_INFO, |
706 | LOG_INFO, |
707 | "Error: HY092" ); |
708 | |
709 | __post_internal_error( &connection -> error, |
710 | ERROR_HY092, NULL, |
711 | connection -> environment -> requested_version ); |
712 | |
713 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
714 | } |
715 | |
716 | switch( attribute ) |
717 | { |
718 | case SQL_ATTR_CURRENT_CATALOG: |
719 | case SQL_ATTR_TRACEFILE: |
720 | case SQL_ATTR_TRANSLATE_LIB: |
721 | if ( value ) |
722 | { |
723 | as1 = (SQLCHAR*) unicode_to_ansi_alloc( value, SQL_NTS, connection, NULL ); |
724 | } |
725 | break; |
726 | } |
727 | |
728 | ret = SQLSETCONNECTOPTION( connection, |
729 | connection -> driver_dbc, |
730 | attribute, |
731 | as1 ? as1 : value ); |
732 | |
733 | if ( as1 ) free( as1 ); |
734 | } |
735 | else |
736 | { |
737 | dm_log_write( __FILE__, |
738 | __LINE__, |
739 | LOG_INFO, |
740 | LOG_INFO, |
741 | "Error: IM001" ); |
742 | |
743 | __post_internal_error( &connection -> error, |
744 | ERROR_IM001, NULL, |
745 | connection -> environment -> requested_version ); |
746 | |
747 | return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR ); |
748 | } |
749 | } |
750 | else |
751 | { |
752 | SQLCHAR *as1 = NULL; |
753 | |
754 | switch( attribute ) |
755 | { |
756 | case SQL_ATTR_CURRENT_CATALOG: |
757 | case SQL_ATTR_TRACEFILE: |
758 | case SQL_ATTR_TRANSLATE_LIB: |
759 | if ( value ) |
760 | { |
761 | if ( string_length > 0 ) |
762 | { |
763 | as1 = (SQLCHAR*) unicode_to_ansi_alloc( value, string_length, connection, NULL ); |
764 | } |
765 | else if ( string_length == SQL_NTS ) |
766 | { |
767 | as1 = (SQLCHAR*) unicode_to_ansi_alloc( value, SQL_NTS, connection, NULL ); |
768 | } |
769 | } |
770 | |
771 | ret = SQLSETCONNECTATTR( connection, |
772 | connection -> driver_dbc, |
773 | attribute, |
774 | as1 ? as1 : value, |
775 | string_length / sizeof( SQLWCHAR )); |
776 | |
777 | if ( as1 ) |
778 | { |
779 | free( as1 ); |
780 | } |
781 | break; |
782 | |
783 | default: |
784 | ret = SQLSETCONNECTATTR( connection, |
785 | connection -> driver_dbc, |
786 | attribute, |
787 | value, |
788 | string_length ); |
789 | break; |
790 | } |
791 | } |
792 | } |
793 | |
794 | if ( log_info.log_flag ) |
795 | { |
796 | sprintf( connection -> msg, |
797 | "\n\t\tExit:[%s]" , |
798 | __get_return_status( ret, s1 )); |
799 | |
800 | dm_log_write( __FILE__, |
801 | __LINE__, |
802 | LOG_INFO, |
803 | LOG_INFO, |
804 | connection -> msg ); |
805 | } |
806 | } |
807 | |
808 | /* |
809 | * catch this |
810 | */ |
811 | |
812 | if ( attribute == SQL_ATTR_USE_BOOKMARKS && SQL_SUCCEEDED( ret )) |
813 | { |
814 | connection -> bookmarks_on = (SQLULEN) value; |
815 | } |
816 | |
817 | return function_return( SQL_HANDLE_DBC, connection, ret ); |
818 | } |
819 | |