473,513 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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 14465
KevinADC
4,059 Recognized Expert Specialist
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
gautamga
7 New Member
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 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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
gautamga
7 New Member
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 Recognized Expert Moderator Specialist
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 Recognized Expert Top Contributor
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
gautamga
7 New Member
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 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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
gautamga
7 New Member
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
2536
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
7240
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
2155
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
3990
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
1163
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
12596
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
28520
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
2204
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
5127
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...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.