CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
script cannot find prepare method when connect to Oracle

 



digioleg54
User

Apr 28, 2017, 11:46 AM

Post #1 of 5 (898 views)
script cannot find prepare method when connect to Oracle Can't Post

I have a script:

Code
#!/usr/bin/dwebenv perl 


my($lib_path,$data_path);
BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}
use strict;
use warnings;
use DBI;
use DBD::Oracle;
use lib $lib_path.'/lib/web'; ##=> configurable param
use lib $data_path.'/monitor';
#print "Content-type: text/html\n\n";
require "dteacl_b.pl";



sub get_processing_date
{
my $this_dbh = @_;

my $sql = (q{select to_char(parameter_date,'YYYYMMDD')
from dte_parameter
where parameter_name = 'DTE_PROCESSING_DATE'});
my $this_sth = $this_dbh->prepare($sql);
$this_sth->execute();
my $process_date;
while ($process_date = $this_sth->fetchrow_array) {
print "Content-type: text/plain\n\n DTE PROCESSING DATE IS $process_date\n";
}
#&close_and_exit(\$this_dbh);
&close_and_exit();

return ($process_date);
1;
}


When I call that sub from test.pl it shows an error:

Code
 Can't locate object method "prepare" via package "1" (perhaps you forgot to load "1"?) at /vhosts/dw18637/lib/web/GetDates.pl line 27.


could you please tell me why?

Thanks


Laurent_R
Veteran / Moderator

Apr 28, 2017, 12:00 PM

Post #2 of 5 (896 views)
Re: [digioleg54] script cannot find prepare method when connect to Oracle [In reply to] Can't Post

Hi,

you don't show the call to the sub get_processing_date subroutine, so it looks like it's never called or we don't see a full program.

One thing you should try is to replace this:

Code
my $this_dbh = @_;

with this:

Code
my ($this_dbh) = @_;

or possibly:

Code
my $this_dbh = shift;

Because your code above evaluates @_ in scalar context, which would return the number of items in @_, presumably 1 if @_ contains only one element.


BillKSmith
Veteran

Apr 28, 2017, 12:25 PM

Post #3 of 5 (895 views)
Re: [digioleg54] script cannot find prepare method when connect to Oracle [In reply to] Can't Post

This code is neither a stand alone script nor module. It is probably possible to load and execute it, but I am not sure how. If you received it from someone else and are not able to make changes to it, consult their documentation. If possible, I would rewrite the file as a method. Then it would be easy to load and call. What you have to do depends on whether get_processing_data is intended to be a function or a method.

If you must use the existing file and do not have documentation, post a sample program which attempts to load and execute it. Provide links to perl documentation that justifies your approach.
Good Luck,
Bill


digioleg54
User

Apr 28, 2017, 12:31 PM

Post #4 of 5 (894 views)
Re: [Laurent_R] script cannot find prepare method when connect to Oracle [In reply to] Can't Post

this sub call

Code
#!/usr/bin/dwebenv perl 

#use lib "/vhosts/dw18637/lib/web/";
use strict;
use warnings;
use DBI;
use DBD::Oracle;
use Spreadsheet::ParseExcel;
use File::Basename;
#use ReportTypes::RptReq qw(fru_process_failrpt fru_run_report);
#use ReportTypes::SD qw(sd_flds_all);
my($lib_path,$data_path);
BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}
use lib $lib_path.'/lib/web';
require 'GetDates.pl';
print "Content-type: text/html\n\n";
my $this_dbh = &db_connect({'DSN'=> 'FISSAPP_MIS'});
my $dt = &get_processing_date($this_dbh);
print "THE processing date is $dt\n";


Please check again

Thanks


Laurent_R
Veteran / Moderator

May 1, 2017, 3:38 PM

Post #5 of 5 (875 views)
Re: [digioleg54] script cannot find prepare method when connect to Oracle [In reply to] Can't Post

With the change I suggested, the error you mentioned should be gone. If your script still doesn't work with this change, please show the errors you have now.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives