473,372 Members | 798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Error: Can't call method "prepare" on an undefined value $dbh

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.

Expand|Select|Wrap|Line Numbers
  1. # conect to database
  2. $dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
  3.  
  4. ################################ {
  5.  
  6. # inserting into job_audit table
  7. print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
  8. &insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
  9.  
  10. print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
  11.  
  12. $dbh->disconnect;
  13.  
another script is

Expand|Select|Wrap|Line Numbers
  1. #################################
  2. #Insert into JOB_AUDIT table
  3. #################################
  4.  
  5. sub insert_job_audit {
  6.  
  7.     local($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED) = @_;
  8.     $SQL = "
  9. INSERT INTO JOB_AUDIT@TO_P1DBDEV ('JOB_NAME','STATUS','SENT_TO','RUN_DATE','EXTRACT_FILE_NAME','FILE_SEQ_NO') 
  10. VALUES (?,?,?,?,?,?)";
  11.  
  12.     $csr4 = $dbh->prepare($SQL);
  13.  
  14.     if ($DBI::errstr) {
  15.         &log_error($SQL,$DBI::errstr,$YES);
  16.     }
  17.  
  18.  
  19.     $csr4->execute ($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED);
  20.  
  21.     if ($DBI::errstr) {
  22.         &log_error($SQL,$DBI::errstr,$YES);
  23.     }
  24.  
  25.     $dbh->commit;
  26.     $csr4->finish();
  27.     printf STDLOG ("values inserted in the JOB_AUDIT table\n");
  28. }
  29.  
Aug 30 '07 #1
11 14435
KevinADC
4,059 Expert 2GB
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.
Aug 30 '07 #2
i defined it but again its giving same error. but i dont think we need to define the handle
Aug 30 '07 #3
numberwhun
3,509 Expert Mod 2GB
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
Aug 30 '07 #4
KevinADC
4,059 Expert 2GB
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".
Aug 30 '07 #5
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);
Sep 3 '07 #6
numberwhun
3,509 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. my $dbh = new(DBI..... );
  2.  
Just curious.

Regards,

Jeff
Sep 3 '07 #7
miller
1,089 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. # conect to database
  2. $dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
  3.  
  4. ...
  5.  
  6. &insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
  7.  
another script is

Expand|Select|Wrap|Line Numbers
  1. #################################
  2. #Insert into JOB_AUDIT table
  3. #################################
  4.  
  5. sub insert_job_audit {
  6. ...
  7.     $csr4 = $dbh->prepare($SQL);
  8. }
  9.  
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
Sep 3 '07 #8
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:
Expand|Select|Wrap|Line Numbers
  1. my $dbh = new(DBI..... );
  2.  
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.
Sep 6 '07 #9
numberwhun
3,509 Expert Mod 2GB
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
Sep 6 '07 #10
KevinADC
4,059 Expert 2GB
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.
Sep 6 '07 #11
Expand|Select|Wrap|Line Numbers
  1. #
  2. #  Description:
  3. #
  4. #  ftp extract file to cohesion and compress the extract file.
  5. #
  6. #  This script was created to overcome OS problems encountered when
  7. #  this code was included in the ras_attr_extract.pl script. The
  8. #  error encountered was "Not enough space" when the extract files
  9. #  grew in size.
  10. #
  11. #  Change history:
  12. #
  13. #  Manu Kodiyan         04/05/04  Created
  14. #
  15. #
  16. #
  17. unshift (@INC, "/home/patriat/sourcescr/input/lib");
  18. require 'getopts.pl';
  19. require '/home/patriat/sourcescr/input/lib/patriat_lib.pl';
  20. use strict;
  21. use Getopt::Std;
  22. use vars qw($opt_p $opt_d);
  23. use File::Copy;
  24. require "comfunc.pl";
  25. use DBI;
  26. use Data::Dumper;
  27. getopts('p:d:');
  28.  
  29. my $emailmsg;
  30. my $loglines;
  31. my $raspath = "/home/patriat/data/ras/";
  32. my $cohpath = "/home/patriat/data/ras/";
  33. my $backup = "/home/patriat/backup/ras/";
  34. my $weblink = "/home/patriat/sourcescr/web_pages/html/onlinedoc/";
  35. my $total = 0;
  36. my ($timestamp) = timestamp ();
  37. my $LAST_FILE_PROCESSED= 0;
  38. my $COMPLETE = "COMPLETE";
  39. my $COHESION = "COHESION";
  40.  
  41. my ($subject, $content, $cc);
  42. $subject = "PROGRAM $opt_p";
  43. $cc = $ENV{PROD_SUPPORT};
  44. my ($dbh);
  45.  
  46.  
  47. ###################################################################################
  48. # conect to database
  49. #################################################################################
  50.  
  51. my ($subject, $content, $cc);
  52. $subject = "PROGRAM $opt_p";
  53. $cc = $ENV{PROD_SUPPORT};
  54. my ($dbh);
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. if (!$opt_d || !$opt_p)
  62. {
  63.   $emailmsg = "ftp to cohesion script not configured properly\n\n" .
  64.               "USAGE ras2coh.pl -p <calling program> -d <extract file>\n";
  65.   $subject .= " -FAILURE";
  66.   sendMail ($subject, $emailmsg, $cc);
  67.   exit 1;
  68. }
  69.  
  70.  
  71. my $TMP_LOG = "/home/patriat/log/ras/log.tmp";
  72.  
  73. my $PEX_LOG = "/home/patriat/log/ras/${opt_d}";
  74. $PEX_LOG =~ s/csv/log/;
  75.  
  76. my $PEX_LOG_FTP = $PEX_LOG;
  77. $PEX_LOG_FTP =~ s/\.log/_ftp\.log/;
  78.  
  79. open ( PLOG, ">>$PEX_LOG" );
  80. print PLOG "\n";
  81. print PLOG `date`;
  82. print PLOG "Preparing to ftp ras $opt_d file to cohesion\n\n";
  83.  
  84.  
  85. my ($cohfileout) = $opt_d;
  86.  
  87. # rename extension to .dat fro Cohesion
  88. $cohfileout =~ s/csv$/dat/;
  89.  
  90.  
  91. $total = `wc -l ${raspath}$opt_d`;
  92. $total =~ /^(\d+)/;
  93. $total = $1 - 1; # -1 for the header
  94.  
  95. rename $raspath . $opt_d, $cohpath . $cohfileout;
  96.  
  97. my ($coherrstr, $cohcmd, $coherrstr);
  98.  
  99. #
  100. # ftp to the cohesion drop box
  101. #
  102. #$cohcmd = "/home/patriat/sourcescr/output/src/ftp2coh.sh $cohfileout >$PEX_LOG_FTP 2>&1";
  103. #$coherrstr = system($cohcmd);
  104.  
  105. if ($coherrstr) {
  106.   open (TMP, "<$PEX_LOG_FTP");
  107.   $loglines = '';
  108.   while (<TMP>) {
  109.     $loglines = $loglines . $_;
  110.   }
  111.   close (TMP);
  112.   # some error occured in the ftp script
  113.   $emailmsg = "Error during ftp of $cohfileout extract to cohesion. $loglines\n";
  114.   print PLOG $emailmsg;
  115.   $subject .= " -FAILURE";
  116.   sendMail ($subject, $emailmsg, $cc);
  117.   exit 1;
  118. }
  119.  
  120. print PLOG "DATA file $cohfileout (renamed extension) is Succesfully ftp-ed to Cohesion\n";
  121.  
  122.  
  123.  
  124.  
  125. ##############################################################################
  126. # inserting into job_audit table
  127. ##############################################################################
  128.  
  129. print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
  130. &insert_job_audit('$opt_p','$COMPLETE','$COHESION','$timestamp','$cohfileout','$LAST_FILE_PROCESSED');
  131.  
  132. print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
  133.  
  134. ###############################################################################
  135.  
  136.  
  137. $dbh->disconnect;
  138.  
  139. # Move the file back and compress
  140. rename $cohpath . $cohfileout, $raspath . $opt_d;
  141.  
  142. unlink ( $raspath. $opt_d . ".Z" );
  143. my($command) = "compress ${raspath}$opt_d";
  144. $coherrstr = system("$command >$TMP_LOG 2>&1");
  145. if ( $coherrstr )
  146. {
  147.   open (TMP, "<$TMP_LOG");
  148.   $loglines = '';
  149.   while (<TMP>) {
  150.     $loglines = $loglines . $_;
  151.   }
  152.   close (TMP);
  153.   $emailmsg = "Error when  compressing $opt_d extract file\n. $loglines";
  154.   $subject .= " -FAILURE";
  155.   print PLOG $emailmsg;
  156.   sendMail ($subject, $emailmsg, $cc);
  157.   exit 1;
  158.  
Sep 7 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gene Mat | last post by:
Hi, I'm trying to build a simple Perl program to get a list of newsgroups. Here's what I have... #!/opt/local/bin/perl use Net::NNTP; $nntp = Net::NNTP->new("nntp.perl.org",Debug,10);...
1
by: Asyn lordasyn | last post by:
Ok... I know there is got to be something simple that I forgot, but I for the life of me can't find it. Please, for the sake of the wall I keep slamming my head into, any insight would be helpful. ...
6
by: David N | last post by:
Hi All, What is a best way to handle an undefined value object class that returned from a function. I have a function that call the ADO.NET ExecuteScalar() function and returns the object to...
1
by: Jean Stax | last post by:
Hi ! I created a sample library project. In my second project I reference this library and make the following call, which returns "undefined value": Type myType =...
0
by: Michael R | last post by:
Here's one that's got me stumped... I have a class with a member variable. I set it in a member method. In the debugger, it shows up as <undefined> before AND AFTER it is set. However,...
2
by: gmccammon | last post by:
I am getting an error that says that I can't call method "prepare" on an undefined value! Here is what I have as code.... I don't understand what is not defined. # opens connection to Access...
8
by: pnsreee | last post by:
Hi all, Im trying to print ARRAY OF ARRAYS using following code. for $i (0..10) { print "\t } ] ,\n"; }
0
by: tgkprog | last post by:
hi i'm trying to use Win32::IEAutomation to automate clickbank.com navigation and page saving i can login and go to the https://www.clickbank.com/account/showTransactions.htm page but cannot...
1
by: mithunmo | last post by:
If I run the below program . I get the following error message Can't call method "value" on an undefined value at C:/Perl/site/lib/Win32/IE/Mec hanize.pm line 900. Please let me know your...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.