~ubuntu-branches/debian/sid/unixodbc/sid

« back to all changes in this revision

Viewing changes to DriverManager/SQLDriverConnectW.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2004-10-15 03:07:52 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041015030752-dzw4vhxlgycz3woj
Tags: 2.2.4-11
Brown paper bag me: conflicts do not write themselves just because
you add a line to the changelog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 *
28
28
 **********************************************************************
29
29
 *
30
 
 * $Id: SQLDriverConnectW.c,v 1.2 2001/12/13 13:00:32 lurcher Exp $
 
30
 * $Id: SQLDriverConnectW.c,v 1.11 2002/12/20 11:36:46 lurcher Exp $
31
31
 *
32
32
 * $Log: SQLDriverConnectW.c,v $
 
33
 * Revision 1.11  2002/12/20 11:36:46  lurcher
 
34
 *
 
35
 * Update DMEnvAttr code to allow setting in the odbcinst.ini entry
 
36
 *
 
37
 * Revision 1.10  2002/12/05 17:44:30  lurcher
 
38
 *
 
39
 * Display unknown return values in return logging
 
40
 *
 
41
 * Revision 1.9  2002/10/14 09:46:10  lurcher
 
42
 *
 
43
 * Remove extra return
 
44
 *
 
45
 * Revision 1.8  2002/07/25 09:30:26  lurcher
 
46
 *
 
47
 * Additional unicode and iconv changes
 
48
 *
 
49
 * Revision 1.7  2002/07/24 08:49:51  lurcher
 
50
 *
 
51
 * Alter UNICODE support to use iconv for UNICODE-ANSI conversion
 
52
 *
 
53
 * Revision 1.6  2002/07/04 17:27:56  lurcher
 
54
 *
 
55
 * Small bug fixes
 
56
 *
 
57
 * Revision 1.4  2002/05/24 12:42:50  lurcher
 
58
 *
 
59
 * Alter NEWS and ChangeLog to match their correct usage
 
60
 * Additional UNICODE tweeks
 
61
 *
 
62
 * Revision 1.3  2002/01/21 18:00:51  lurcher
 
63
 *
 
64
 * Assorted fixed and changes, mainly UNICODE/bug fixes
 
65
 *
33
66
 * Revision 1.2  2001/12/13 13:00:32  lurcher
34
67
 *
35
68
 * Remove most if not all warnings on 64 bit platforms
74
107
{
75
108
struct con_pair *cp;
76
109
char *local_str, *ptr;
 
110
int len;
77
111
int got_dsn = 0;    /* if we have a DSN then ignore any DRIVER or FILEDSN */
78
112
int got_driver = 0;    /* if we have a DRIVER or FILEDSN then ignore any DSN */
79
113
 
80
114
    con_str -> count = 0;
81
115
    con_str -> list = NULL;
82
116
 
83
 
    local_str = unicode_to_ansi( str, str_len );
 
117
    if ( str_len == SQL_NTS )
 
118
    {
 
119
        len =  wide_strlen( str ) + sizeof( SQLWCHAR );
 
120
        local_str = malloc( len );
 
121
    }
 
122
    else
 
123
    {
 
124
        len = str_len + sizeof( SQLWCHAR );
 
125
        local_str = malloc( len );
 
126
    }
 
127
 
 
128
    unicode_to_ansi_copy( local_str, str, len, NULL );
84
129
 
85
130
    if ( !local_str || strlen( local_str ) == 0 ||
86
131
        ( strlen( local_str ) == 1 && *local_str == ';' ))
141
186
{
142
187
    DMHDBC connection = (DMHDBC)hdbc;
143
188
    struct con_struct con_struct;
144
 
    char *driver, *dsn;
 
189
    char *driver = NULL, *dsn = NULL;
145
190
    char lib_name[ INI_MAX_PROPERTY_VALUE + 1 ];
146
191
    char driver_name[ INI_MAX_PROPERTY_VALUE + 1 ];
147
192
    SQLRETURN ret_from_connect;
148
193
    SQLCHAR s1[ 2048 ];
 
194
    int warnings;
149
195
 
150
196
    /*
151
197
     * check connection
152
198
     */
153
199
 
 
200
    strcpy( driver_name, "" );
 
201
 
154
202
    if ( !__validate_dbc( connection ))
155
203
    {
156
204
        dm_log_write( __FILE__, 
337
385
        }
338
386
 
339
387
        strcpy( connection -> dsn, "" );
 
388
        __handle_attr_extensions( connection, NULL, driver_name );
340
389
    }
341
390
    else
342
391
    {
343
392
        dsn = __get_attribute_value( &con_struct, "DSN" );
 
393
 
344
394
        if ( !dsn )
345
395
        {
346
396
            dm_log_write( __FILE__, 
399
449
        }
400
450
 
401
451
        strcpy( connection -> dsn, dsn );
 
452
        __handle_attr_extensions( connection, dsn, driver_name );
 
453
    }
 
454
 
 
455
    if ( dsn )
 
456
    {
 
457
        /*
 
458
         * do we have any Environment, Connection, or Statement attributes set in the ini ?
 
459
         */
 
460
 
 
461
        __handle_attr_extensions( connection, dsn, driver_name );
402
462
    }
403
463
 
404
464
    __release_conn( &con_struct );
406
466
    /*
407
467
     * we have now got the name of a lib to load
408
468
     */
409
 
    if ( !__connect_part_one( connection, lib_name, driver_name ))
 
469
    if ( !__connect_part_one( connection, lib_name, driver_name, &warnings ))
410
470
    {
411
471
        thread_release( SQL_HANDLE_DBC, connection );
412
472
        return function_return( connection, SQL_ERROR );
433
493
 
434
494
    if ( CHECK_SQLDRIVERCONNECTW( connection ))
435
495
    {
 
496
        if ( CHECK_SQLSETCONNECTATTR( connection ))
 
497
        {
 
498
            int lret;
 
499
                
 
500
            lret = SQLSETCONNECTATTR( connection,
 
501
                    connection -> driver_dbc,
 
502
                    SQL_ATTR_ANSI_APP,
 
503
                    SQL_AA_FALSE,
 
504
                    0 );
 
505
        }
 
506
 
436
507
        ret_from_connect = SQLDRIVERCONNECTW( connection,
437
508
                connection -> driver_dbc,
438
509
                hwnd,
443
514
                ptr_conn_str_out,
444
515
                driver_completion );
445
516
 
446
 
        if ( !SQL_SUCCEEDED( ret_from_connect ))
 
517
        if ( ret_from_connect != SQL_ERROR )
447
518
        {
448
519
            SQLWCHAR sqlstate[ 6 ];
449
520
            SQLINTEGER native_error;
476
547
                        __post_internal_error_ex_w( &connection -> error,
477
548
                                sqlstate,
478
549
                                native_error,
479
 
                                message_text );
 
550
                                message_text,
 
551
                                SUBCLASS_ODBC, SUBCLASS_ODBC );
480
552
                    }
481
553
                }
482
554
                while( SQL_SUCCEEDED( ret ));
503
575
                        __post_internal_error_ex_w( &connection -> error,
504
576
                                sqlstate,
505
577
                                native_error,
506
 
                                message_text );
 
578
                                message_text,
 
579
                                SUBCLASS_ODBC, SUBCLASS_ODBC );
507
580
                    }
508
581
                }
509
582
                while( SQL_SUCCEEDED( ret ));
522
595
 
523
596
                sprintf( connection -> msg,
524
597
                        "\n\t\tExit:[%s]",
525
 
                            __get_return_status( ret_from_connect ));
 
598
                            __get_return_status( ret_from_connect, s1 ));
526
599
 
527
600
                dm_log_write( __FILE__,
528
601
                        __LINE__,
537
610
    }
538
611
    else
539
612
    {
 
613
        char *in_str, *out_str;
 
614
        int len;
 
615
 
 
616
        if ( conn_str_in )
 
617
        {
 
618
            if ( len_conn_str_in == SQL_NTS )
 
619
            {
 
620
                len = wide_strlen( conn_str_in ) + sizeof( SQLWCHAR );
 
621
            }
 
622
            else
 
623
            {
 
624
                len = len_conn_str_in + sizeof( SQLWCHAR );
 
625
            }
 
626
            in_str = malloc( len );
 
627
            unicode_to_ansi_copy( in_str, conn_str_in, len, connection );
 
628
        }
 
629
        else
 
630
        {
 
631
            in_str = NULL;
 
632
        }
 
633
 
 
634
        if ( conn_str_out && conn_str_out_max > 0 )
 
635
        {
 
636
            out_str = malloc( conn_str_out_max + sizeof( SQLWCHAR ) );
 
637
        }
 
638
        else
 
639
        {
 
640
            out_str = NULL;
 
641
        }
 
642
       
540
643
        ret_from_connect = SQLDRIVERCONNECT( connection,
541
644
                connection -> driver_dbc,
542
645
                hwnd,
543
 
                conn_str_in,
 
646
                (SQLCHAR*)in_str,
544
647
                len_conn_str_in,
545
 
                conn_str_out,
 
648
                (SQLCHAR*)out_str,
546
649
                conn_str_out_max,
547
650
                ptr_conn_str_out,
548
651
                driver_completion );
549
652
 
550
 
        if ( !SQL_SUCCEEDED( ret_from_connect ))
 
653
        if ( in_str )
 
654
        {
 
655
            free( in_str );
 
656
        }
 
657
 
 
658
        if ( out_str )
 
659
        {
 
660
            if ( SQL_SUCCEEDED( ret_from_connect ))
 
661
            {
 
662
                ansi_to_unicode_copy( conn_str_out, out_str, SQL_NTS, connection );
 
663
            }
 
664
 
 
665
            free( out_str );
 
666
        }
 
667
 
 
668
        if ( ret_from_connect != SQL_SUCCESS )
551
669
        {
552
670
            SQLCHAR sqlstate[ 6 ];
553
671
            SQLINTEGER native_error;
574
692
                            sizeof( message_text ),
575
693
                            &ind );
576
694
 
577
 
 
578
695
                    if ( SQL_SUCCEEDED( ret ))
579
696
                    {
580
697
                        __post_internal_error_ex( &connection -> error,
581
698
                                sqlstate,
582
699
                                native_error,
583
 
                                message_text );
 
700
                                message_text,
 
701
                                SUBCLASS_ODBC, SUBCLASS_ODBC );
584
702
                    }
585
703
                }
586
704
                while( SQL_SUCCEEDED( ret ));
601
719
                            sizeof( message_text ),
602
720
                            &ind );
603
721
 
604
 
 
605
722
                    if ( SQL_SUCCEEDED( ret ))
606
723
                    {
607
724
                        __post_internal_error_ex( &connection -> error,
608
725
                                sqlstate,
609
726
                                native_error,
610
 
                                message_text );
 
727
                                message_text,
 
728
                                SUBCLASS_ODBC, SUBCLASS_ODBC );
611
729
                    }
612
730
                }
613
731
                while( SQL_SUCCEEDED( ret ));
625
743
 
626
744
                sprintf( connection -> msg,
627
745
                        "\n\t\tExit:[%s]",
628
 
                            __get_return_status( ret_from_connect ));
 
746
                            __get_return_status( ret_from_connect, s1 ));
629
747
 
630
748
                dm_log_write( __FILE__,
631
749
                        __LINE__,
678
796
            sprintf( connection -> msg, 
679
797
                    "\n\t\tExit:[%s]\
680
798
                    \n\t\t\tConnection Out [%.64s...]",
681
 
                        __get_return_status( ret_from_connect ),
682
 
                        conn_str_out );
 
799
                        __get_return_status( ret_from_connect, s1 ),
 
800
                        __wstring_with_length_hide_pwd( s1, conn_str_out, SQL_NTS ));
683
801
        }
684
802
        else
685
803
        {
690
808
            sprintf( connection -> msg, 
691
809
                    "\n\t\tExit:[%s]\
692
810
                    \n\t\t\tConnection Out [%s]",
693
 
                        __get_return_status( ret_from_connect ),
694
 
                        __wstring_with_length_hide_pwd( s1, 
695
 
                            conn_str_out ? conn_str_out : ansi_to_unicode_in_place((SQLCHAR*) null, SQL_NTS ), SQL_NTS ));
 
811
                        __get_return_status( ret_from_connect, s1 ),
 
812
                        __wstring_with_length_hide_pwd( s1, conn_str_out, SQL_NTS ));
696
813
        }
697
814
 
698
815
        dm_log_write( __FILE__, 
704
821
 
705
822
    thread_release( SQL_HANDLE_DBC, connection );
706
823
 
 
824
    if ( warnings && ret_from_connect == SQL_SUCCESS )
 
825
    {
 
826
        ret_from_connect = SQL_SUCCESS_WITH_INFO;
 
827
    }
 
828
 
707
829
    return function_return( connection, ret_from_connect );
708
830
}