Hi All i have created the script which calls method from other script lib and while executing i get and error Can't call method "prepare" on an undefined value at /home/patriat/sourcescr/input/lib/patriat_lib.pl line 226. -
# conect to database
-
$dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
-
-
################################ {
-
-
# inserting into job_audit table
-
print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
-
&insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
-
-
print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
-
-
$dbh->disconnect;
-
another script is -
#################################
-
#Insert into JOB_AUDIT table
-
#################################
-
-
sub insert_job_audit {
-
-
local($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED) = @_;
-
$SQL = "
-
INSERT INTO JOB_AUDIT@TO_P1DBDEV ('JOB_NAME','STATUS','SENT_TO','RUN_DATE','EXTRACT_FILE_NAME','FILE_SEQ_NO')
-
VALUES (?,?,?,?,?,?)";
-
-
$csr4 = $dbh->prepare($SQL);
-
-
if ($DBI::errstr) {
-
&log_error($SQL,$DBI::errstr,$YES);
-
}
-
-
-
$csr4->execute ($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED);
-
-
if ($DBI::errstr) {
-
&log_error($SQL,$DBI::errstr,$YES);
-
}
-
-
$dbh->commit;
-
$csr4->finish();
-
printf STDLOG ("values inserted in the JOB_AUDIT table\n");
-
}
-
11 13990
thisis the only line I see with "prepre" in it:
$csr4 = $dbh->prepare($SQL);
so $dbh is undefined when you try and call the prepare method. You have to determine why it is undefined.
i defined it but again its giving same error. but i dont think we need to define the handle
You definitely have to determine why that value isn't being set and I think you should set some print statements after variable declarations to ensure they are being set.
Another thing, you definitely aren't using "use strict" because you don't have 'my' in front of your initial declarations. This makes me wonder if you are using "use warnings". They both will help you to avoid the silly errors and allow people to trouble shoot the actual issues in your code, not the silly stuff.
Regards,
Jeff
i defined it but again its giving same error. but i dont think we need to define the handle
Well, the error message clearly tells you that $dbh needs to be defined and needs to be defined properly. How did you 'define' it?
Note what Jeff said above too about using "strict" and warnings".
hi,
i have use strict and defined the dbh too. can there is some other problem with perl module as i am new to perl. still getting error as
Can't call method "prepare" on an undefined value at /home/patriat/sourcescr/input/lib/patriat_lib.pl line 226.
$csr4 = $dbh->prepare($SQL);
Since we cannot see the whole of your code, we are only going to be able to speculate what is going on.
I wonder, do you previously in your code have the line to assign the new() object to $dbh?
ie: -
my $dbh = new(DBI..... );
-
Just curious.
Regards,
Jeff
-
# conect to database
-
$dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
-
-
...
-
-
&insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
-
another script is -
#################################
-
#Insert into JOB_AUDIT table
-
#################################
-
-
sub insert_job_audit {
-
...
-
$csr4 = $dbh->prepare($SQL);
-
}
-
You have defined $dbh in your primary script, but it is not defined in your secondary script in which the sub insert_job_audit is located. I suggest that you pass the $dbh as the first parameter to the function so that it is defined.
Also, do not use local for subroutine parameters. In fact, unless there is a specific reason why you need it, you should never use local. Instead use my
And I second all of the things that Jeff and Kevin stated about including "use strict;" at the top of all of your scripts. If you really had included it, then an error should have been thrown during compile time instead of at runtime when the prepare statement is reached.
- Miller
Since we cannot see the whole of your code, we are only going to be able to speculate what is going on.
I wonder, do you previously in your code have the line to assign the new() object to $dbh?
ie: -
my $dbh = new(DBI..... );
-
Just curious.
Regards,
Jeff
nopes i dint use new()
still i am not able to resolve my problem.
now its saying as
Can't locate strict.pm in @INC (@INC contains: /opt/perl5.6.1/lib/site_perl/5.6.1 /opt/perl5.6.1/lib/5.6.1 /opt/perl5.6.1/lib/5.6.1/PA-RISC2.0 /opt/perl5.6.1/lib/site_perl/5.6.1/PA-RISC2.0 /home/patriat/sourcescr/input/lib /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/5.00503/PA-RISC2.0 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/5.00503 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/site_perl/5.005/PA-RISC2.0 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/site_perl/5.005 .) at /home/patriat/sourcescr/output/src/ras2coh.pl line 21.
BEGIN failed--compilation aborted at /home/patriat/sourcescr/output/src/ras2coh.pl line 21.
That is just weird that you are getting that. Strict is part of the base installation of Perl. If it is not installed, then you are going to have to go to CPAN and install the strict module from there. That should clear up that error.
Regards,
Jeff
lets see the first 30 or so lines of ras2coh.pl
if "strict" really is not there your version of perl is no good for reasons unkown. It is long overdue for upgrade anyway since perl 5.6 is very old.
-
#
-
# Description:
-
#
-
# ftp extract file to cohesion and compress the extract file.
-
#
-
# This script was created to overcome OS problems encountered when
-
# this code was included in the ras_attr_extract.pl script. The
-
# error encountered was "Not enough space" when the extract files
-
# grew in size.
-
#
-
# Change history:
-
#
-
# Manu Kodiyan 04/05/04 Created
-
#
-
#
-
#
-
unshift (@INC, "/home/patriat/sourcescr/input/lib");
-
require 'getopts.pl';
-
require '/home/patriat/sourcescr/input/lib/patriat_lib.pl';
-
use strict;
-
use Getopt::Std;
-
use vars qw($opt_p $opt_d);
-
use File::Copy;
-
require "comfunc.pl";
-
use DBI;
-
use Data::Dumper;
-
getopts('p:d:');
-
-
my $emailmsg;
-
my $loglines;
-
my $raspath = "/home/patriat/data/ras/";
-
my $cohpath = "/home/patriat/data/ras/";
-
my $backup = "/home/patriat/backup/ras/";
-
my $weblink = "/home/patriat/sourcescr/web_pages/html/onlinedoc/";
-
my $total = 0;
-
my ($timestamp) = timestamp ();
-
my $LAST_FILE_PROCESSED= 0;
-
my $COMPLETE = "COMPLETE";
-
my $COHESION = "COHESION";
-
-
my ($subject, $content, $cc);
-
$subject = "PROGRAM $opt_p";
-
$cc = $ENV{PROD_SUPPORT};
-
my ($dbh);
-
-
-
###################################################################################
-
# conect to database
-
#################################################################################
-
-
my ($subject, $content, $cc);
-
$subject = "PROGRAM $opt_p";
-
$cc = $ENV{PROD_SUPPORT};
-
my ($dbh);
-
-
-
-
-
-
-
if (!$opt_d || !$opt_p)
-
{
-
$emailmsg = "ftp to cohesion script not configured properly\n\n" .
-
"USAGE ras2coh.pl -p <calling program> -d <extract file>\n";
-
$subject .= " -FAILURE";
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
}
-
-
-
my $TMP_LOG = "/home/patriat/log/ras/log.tmp";
-
-
my $PEX_LOG = "/home/patriat/log/ras/${opt_d}";
-
$PEX_LOG =~ s/csv/log/;
-
-
my $PEX_LOG_FTP = $PEX_LOG;
-
$PEX_LOG_FTP =~ s/\.log/_ftp\.log/;
-
-
open ( PLOG, ">>$PEX_LOG" );
-
print PLOG "\n";
-
print PLOG `date`;
-
print PLOG "Preparing to ftp ras $opt_d file to cohesion\n\n";
-
-
-
my ($cohfileout) = $opt_d;
-
-
# rename extension to .dat fro Cohesion
-
$cohfileout =~ s/csv$/dat/;
-
-
-
$total = `wc -l ${raspath}$opt_d`;
-
$total =~ /^(\d+)/;
-
$total = $1 - 1; # -1 for the header
-
-
rename $raspath . $opt_d, $cohpath . $cohfileout;
-
-
my ($coherrstr, $cohcmd, $coherrstr);
-
-
#
-
# ftp to the cohesion drop box
-
#
-
#$cohcmd = "/home/patriat/sourcescr/output/src/ftp2coh.sh $cohfileout >$PEX_LOG_FTP 2>&1";
-
#$coherrstr = system($cohcmd);
-
-
if ($coherrstr) {
-
open (TMP, "<$PEX_LOG_FTP");
-
$loglines = '';
-
while (<TMP>) {
-
$loglines = $loglines . $_;
-
}
-
close (TMP);
-
# some error occured in the ftp script
-
$emailmsg = "Error during ftp of $cohfileout extract to cohesion. $loglines\n";
-
print PLOG $emailmsg;
-
$subject .= " -FAILURE";
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
}
-
-
print PLOG "DATA file $cohfileout (renamed extension) is Succesfully ftp-ed to Cohesion\n";
-
-
-
-
-
##############################################################################
-
# inserting into job_audit table
-
##############################################################################
-
-
print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
-
&insert_job_audit('$opt_p','$COMPLETE','$COHESION','$timestamp','$cohfileout','$LAST_FILE_PROCESSED');
-
-
print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
-
-
###############################################################################
-
-
-
$dbh->disconnect;
-
-
# Move the file back and compress
-
rename $cohpath . $cohfileout, $raspath . $opt_d;
-
-
unlink ( $raspath. $opt_d . ".Z" );
-
my($command) = "compress ${raspath}$opt_d";
-
$coherrstr = system("$command >$TMP_LOG 2>&1");
-
if ( $coherrstr )
-
{
-
open (TMP, "<$TMP_LOG");
-
$loglines = '';
-
while (<TMP>) {
-
$loglines = $loglines . $_;
-
}
-
close (TMP);
-
$emailmsg = "Error when compressing $opt_d extract file\n. $loglines";
-
$subject .= " -FAILURE";
-
print PLOG $emailmsg;
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by Gene Mat |
last post: by
|
1 post
views
Thread by Asyn lordasyn |
last post: by
|
6 posts
views
Thread by David N |
last post: by
|
1 post
views
Thread by Jean Stax |
last post: by
|
reply
views
Thread by Michael R |
last post: by
| | | | | | | | | | | | | | |