1821244 Members
2821 Online
109632 Solutions
New Discussion юеВ

perl scripts error!

 
Asics
Occasional Advisor

perl scripts error!

Dear sir:
F0llowing is my per1 scripts,it has some error...
What I going to do it ? Thanks!
#! /opt/perl64/bin/perl5.8.3
use DBI;
use DBD::Informix;
my $data_source = "DBI:Informix:pdview";
my $server = "aaatcp";
my $database = "pdaaa";
my $username = "pdbbb";
my $password = "pdbbb";
my $dbh = DBI->connect($data_source, $username, $password) or die "Error! $DBI::errstr";
print "Connetc informix server ok......\n";
$sql = "SELECT * FROM cam2asics";
$sth = $dbh->prepare($sql);
$sth -> execute() or die ("error!");
print "$database include......:\n";
while(@rows = $sth->fetchrow_array)
{
foreach(@rows)
{
print "$_\t";
}
print "\n";
}
$sth->finish;
$dbh -> disconnect();
exit 0;

result message:
Connetc informix server ok......
Can't call method "execute" on an undefined value at connect2 line 13.


5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: perl scripts error!

Tough one.

When I used perl to handle sqlplus I had to worry about special characters like @ that trip up the interpreter. You have to put a special character in froont of special characters to have them not break up the string and blow up the script.

@ has to be \@

" needs to be \"

I don't know the full list of special characters, but this is a likely problem with your script.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hein van den Heuvel
Honored Contributor

Re: perl scripts error!


Hmmm, should line 13 read:

$result = $sth -> execute() or die ("error!");

Hein.
H.Merijn Brand (procura
Honored Contributor

Re: perl scripts error!

SEP: for that, there is a ->quote () method:

$quoted_string = $dbh->quote ($string);

Hein: no, the error is earlier. The error complains about the statement handle being undefined, and thus cannot execute the 'execute' method at all.

It is the prepare that fails

print "Connect informix server ok......\n";
$sql = "SELECT * FROM cam2asics";
$dbh->trace (9);
$sth = $dbh->prepare ($sql);
# At this point, the $sth is probably undefined
$dbh->trace (0);
print STDERR $dbh->errstr;

Could probably give you the information you need to resolv the issue

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Asics
Occasional Advisor

Re: perl scripts error!

Dear sir:
I use this scripts runing with the windows 2000 environment is ok!
But use it with HPUX still error....
Please give me help,thanks sir!
=========================================
use DBI;
use DBD::Informix;
my $data_source = "DBI:Informix:pdview";
my $username = "pduser";
my $password = "pduser";
my $dbh = DBI->connect($data_source, $username, $password) or die "Error! $DBI::errstr";
print "Connetc informix server ok......\n";
$sql = "SELECT * FROM cam2asics";
$dbh->trace(9);
$sth = $dbh->prepare($sql);
$dbh->trace(0);
print STDERR $dbh->errstr;
$sth -> execute() or die "error! can't prepare SQL", $dbh->errstr(), "\n";
print "$rrr\n";
print "$database include......:\n";
while(@rows = $sth->fetchrow_array)
{
foreach(@rows)
{
print "$_\t";
}
print "\n";
}
$sth->finish;
$dbh -> disconnect();
exit 0;
=============================================
#result message
Connetc informix server ok......
DBI::db=HASH(0x800000000025bb00) trace level set to 9 in DBI 1.40-nothread (pid 7614)
Note: perl is running without the recommended perl -w option
-> prepare for DBD::Informix::db (DBI::db=HASH(0x8000000000046758)~0x800000000025bb00 'SELECT * FROM cam2asics')
dbih_setup_handle(DBI::st=HASH(0x800000000025bc68)=>DBI::st=HASH(0x800000000025bd08), DBD::Informix::st, 800000000025bc78, Null!)
dbih_make_com(DBI::db=HASH(0x800000000025bb00), 8000000000152940, DBD::Informix::st, 360, 0) thr#0
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), Err, DBI::db=HASH(0x800000000025bb00)) SCALAR(0x800000000014e1e8) (already defined)
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), State, DBI::db=HASH(0x800000000025bb00)) SCALAR(0x800000000014e188) (already defined)
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), Errstr, DBI::db=HASH(0x800000000025bb00)) SCALAR(0x800000000014e1b8) (already defined)
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), TraceLevel, DBI::db=HASH(0x800000000025bb00)) 9 (already defined)
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), FetchHashKeyName, DBI::db=HASH(0x800000000025bb00)) 'NAME' (already defined)
dbih_setup_attrib(DBI::st=HASH(0x800000000025bd08), HandleError, DBI::db=HASH(0x800000000025bb00)) undef (not defined)
-->> DBD::Informix::dbd_ix_st_prepare()
<<-- DBD::Informix::dbd_ix_st_prepare()
>> DESTROY DISPATCH (DBI::st=HASH(0x800000000025bc68) rc1/1 @1 g0 ima4 pid#7614) at connect2 line 10
<> DESTROY ignored for outer handle DBI::st=HASH(0x800000000025bc68) (inner DBI::st=HASH(0x800000000025bd08))
>> DESTROY DISPATCH (DBI::st=HASH(0x800000000025bd08) rc1/1 @1 g0 ima4 pid#7614) at connect2 line 10
-> DESTROY for DBD::Informix::st (DBI::st=HASH(0x800000000025bd08)~INNER)
Statement handle DBI::st=HASH(0x800000000025bd08) DESTROY ignored - never set up
<- DESTROY= undef at connect2 line 10
DESTROY (dbih_clearcom) (sth 0x800000000025bc68 0x0, com 0x8000000000283b88, imp DBD::Informix::st):
FLAGS 0x111: COMSET Warn PrintError
PARENT DBI::db=HASH(0x800000000025bb00)
KIDS 0 (0 Active)
IMP_DATA undef
NUM_OF_FIELDS 0
NUM_OF_PARAMS 0
dbih_clearcom 0x800000000025bc68 (com 0x8000000000283b88, type 3) done.

<- prepare= undef at connect2 line 10
-> trace for DBD::Informix::db (DBI::db=HASH(0x8000000000046758)~0x800000000025bb00 0)
<- trace= 9 at connect2 line 11
Can't call method "execute" on an undefined value at connect2 line 13.
H.Merijn Brand (procura
Honored Contributor

Re: perl scripts error!

I don't see why that would fail. Sorry, I don't have informix.

I also do not see the error message.
Could you show:

my $dbh = DBI->connect ($data_source, $username, $password) or die "Error! $DBI::errstr";
print "Connect informix server ok......\n";
$dbh->{PrintError} = 1;
$dbh->{RaiseError} = 1;
$sql = "SELECT * FROM cam2asics";
$sth = $dbh->prepare ($sql);

And also, given that "name" is a valid field in table cam2asics, what does

my $dbh = DBI->connect ($data_source, $username, $password) or die "Error! $DBI::errstr";
print "Connect informix server ok......\n";
$dbh->{PrintError} = 1;
$dbh->{RaiseError} = 1;
$sth = $dbh->prepare ("select name from cam2asics");

Also consider taking this to dbi-users mailing list, where Informix expertise is more likely to be present

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn