Subversion Repositories DevTools

Rev

Rev 4466 | Rev 4544 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4466 Rev 4543
Line 35... Line 35...
35
our @EXPORT = qw();
35
our @EXPORT = qw();
36
our @EXPORT_OK = (@EXPORT, qw());
36
our @EXPORT_OK = (@EXPORT, qw());
37
our %EXPORT_TAGS = qw( );
37
our %EXPORT_TAGS = qw( );
38
our $verbose = $ENV{'GBE_DBI_VERBOSE'} || 0;
38
our $verbose = $ENV{'GBE_DBI_VERBOSE'} || 0;
39
our $errstr = "No Error";
39
our $errstr = "No Error";
40
my %appnames = (
-
 
41
                'jdbc:oracle:'  => 'ReleaseManagerSelect.jar',
40
my  $appname = 'ReleaseManagerSelect.jar';
42
                'jdbc:jtds'     => 'ClearQuestSelect.jar'
-
 
43
                );
41
my $full_app;
44
 
42
 
45
#
43
#
46
#   The following hash simplifies existing code
44
#   The following hash simplifies existing code
47
#   in that it will convert known DBI:ODBC called to a more raw form
45
#   in that it will convert known DBI:ODBC called to a more raw form
48
#
46
#
Line 63... Line 61...
63
#
61
#
64
sub connect
62
sub connect
65
{
63
{
66
    my $obclass = shift;
64
    my $obclass = shift;
67
    my $class = ref($obclass) || $obclass;
65
    my $class = ref($obclass) || $obclass;
68
    my $full_app;
-
 
69
 
66
 
70
    bless my $self = {
67
    bless my $self = {
71
        DB          => $_[0],
68
        DB          => $_[0],
72
        USER        => $_[1],
69
        USER        => $_[1],
73
        PASSWORD    => $_[2],
70
        PASSWORD    => $_[2],
Line 100... Line 97...
100
            if $verbose > 1;
97
            if $verbose > 1;
101
        $self->{DB} = $value;
98
        $self->{DB} = $value;
102
    }
99
    }
103
 
100
 
104
    #
101
    #
105
    #   Determine the underlying Java program
-
 
106
    #
-
 
107
    foreach my $entry ( keys %appnames) {
-
 
108
        if ( $self->{DB} =~ m~^$entry~){
-
 
109
            $self->{APPNAME} = $appnames{$entry};
-
 
110
        }
-
 
111
    }
-
 
112
    unless (defined $self->{APPNAME})
-
 
113
    {
-
 
114
        $errstr = "Cannot determine driver for URL";
-
 
115
        return;
-
 
116
    }
-
 
117
 
-
 
118
    print "[DBI] Using Driver: " . $self->{APPNAME} ."\n"
-
 
119
        if $verbose > 1;
-
 
120
 
-
 
121
    #
-
 
122
    #   Need to locate the path to the Java applet
102
    #   Need to locate the path to the Java applet
123
    #   This can be in th "CLASSPATH", but that simply forces the problem of
103
    #   This can be in th "CLASSPATH", but that simply forces the problem of
124
    #   locating the utility into the configuration world
104
    #   locating the utility into the configuration world
125
    #
105
    #
126
    #   Look in Perls @INC list, as we expect to find the program within one of
106
    #   Look in Perls @INC list, as we expect to find the program within one of
Line 128... Line 108...
128
    #
108
    #
129
    unless ( $full_app )
109
    unless ( $full_app )
130
    {
110
    {
131
        foreach my $dir ( @INC )
111
        foreach my $dir ( @INC )
132
        {
112
        {
133
            my $apppath = "$dir/$self->{APPNAME}";
113
            my $apppath = "$dir/$appname";
134
            next unless ( -f $apppath );
114
            next unless ( -f $apppath );
135
 
115
 
136
            $full_app = $apppath;
116
            $full_app = $apppath;
137
            last;
117
            last;
138
        }
118
        }
139
 
119
 
140
        if ( ! $full_app )
120
        if ( ! $full_app )
141
        {
121
        {
142
            $errstr = "Cannot find $self->{APPNAME} in @INC path";
122
            $errstr = "Cannot find $appname in @INC path";
143
            return;
123
            return;
144
        }
124
        }
145
    }
125
    }
146
    print "[DBI] Using Driver from: " . $full_app ."\n"
-
 
147
        if $verbose > 1;
-
 
148
 
126
 
149
    $errstr = "OK";
127
    $errstr = "OK";
150
 
128
 
151
    #
129
    #
152
    #   Initiate the external application server
130
    #   Initiate the external application server
Line 178... Line 156...
178
        #   Extract status and any error information
156
        #   Extract status and any error information
179
        #
157
        #
180
        my $fh = $self->{FH_READ};
158
        my $fh = $self->{FH_READ};
181
        while ( <$fh> )
159
        while ( <$fh> )
182
        {
160
        {
183
            $_ =~ s~\s+$~~;
161
            chomp;
184
            print "[DBI] Connect: $_\n" if $verbose;
162
            print "[DBI] Connect: $_\n" if $verbose;
185
 
163
 
186
            if ( m/^ConnectionOpened:/ )
164
            if ( m/^ConnectionOpened:/ )
187
            {
165
            {
188
                $self->{ERROR} = 0;
166
                $self->{ERROR} = 0;
189
                $errstr = "OK";
167
                $errstr = "OK";
190
                last;
168
                last;
191
            }
169
            }
192
 
170
 
193
            if ( m/^Error:(.*?)\s*$/ )
171
            if ( m/^Error:(.*)/ )
194
            {
172
            {
195
                $errstr = $1;
173
                $errstr = $1;
196
            }
174
            }
197
 
175
 
198
            if ( m/^Status:ConnectionClosed$/ )
-
 
199
            {
-
 
200
                $self->{PID} = 0;
-
 
201
            }
-
 
202
        }
176
        }
203
    }
177
    }
204
 
178
 
205
    #
179
    #
206
    #   Return class iff the connection has been established
180
    #   Return class iff the connection has been established
Line 430... Line 404...
430
        if ( m/^DataEnd:/ )
404
        if ( m/^DataEnd:/ )
431
        {
405
        {
432
            last;
406
            last;
433
        }
407
        }
434
        
408
        
435
        if ( m/^Warning:(.*?)\s*$/ )
409
        if ( m/^Warning:(.*)/ )
436
        {
410
        {
437
            $self->{ERROR} = 1;
411
            $self->{ERROR} = 1;
438
            $self->{ERRSTR} = $1;
412
            $self->{ERRSTR} = $1;
439
        }
413
        }
440
 
414
 
Line 458... Line 432...
458
{
432
{
459
    my $self = shift;
433
    my $self = shift;
460
    return $self->{ERRSTR};
434
    return $self->{ERRSTR};
461
}
435
}
462
 
436
 
-
 
437
 
-
 
438
 
463
#-------------------------------------------------------------------------------
439
#-------------------------------------------------------------------------------
464
# Function        : rows
440
# Function        : rows
465
#
441
#
466
# Description     : Return the number of rows extracted in the query
442
# Description     : Return the number of rows extracted in the query
467
#
443
#