Subversion Repositories DevTools

Rev

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

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