sqlcode in DBD::Informix
Posted in 2000
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL
Hi all: I am newer in DBD::Informix,but have good experience in ESQL/C. I am writting some CGI scripts to access informix Dynamic Server 7.x on Linux,but there is a little question confuse me,and hopes your help !! Q: After the execute command,no matter found the records or not ,the $sth->{ix_sqlcode} is always 0,so how can i judge there are really no rows found in table ? For example,a table:car_reg with column name:plt_no #!/usr/bin/perl -w use DBI; use CGI qw(:standard); my $plt_no = param("plt_no"); print header, start_html("Car_reg quering"); print h1("DB Car_reg Query"); $dbh = DBI->connect("DBI:Informix:mvdis",{PrintError=>1}) or err_chk('connect'); $sth = $dbh->prepare(q%select * from car_reg where plt_no = ? %) or err_chk('prepare'); $sth->execute( $plt_no ) or err_chk('execute') ; while ($car= $sth_car->fetchrow_hashref()){ print "<p>PLT_NO=$car->{plt_no}</p>"; } print "</TABLE>\\n"; print end_html(); $dbh->disconnect; undef $dbh; sub err_chk { my $progress=shift; my $errstr=$DBI::errstr; my $err=$DBI::err; if (defined $errstr){ print '<p>Opps'IDatabase error</p>'; print "<p>During :$progress </p>"; print "<p>Reason :$errstr</p>",end_html; die; } }
David CHANG wrote: > Hi all: > I am newer in DBD::Informix,but have good experience in ESQL/C. > I am writting some CGI scripts to access informix Dynamic Server 7.x on > Linux,but there is a little question confuse me,and hopes your help !! > > Q: After the execute command,no matter found the records or not ,the > $sth->{ix_sqlcode} is always 0,so how can i judge there are really no rows > found in table ? > > For example,a table:car_reg with column name:plt_no > > #!/usr/bin/perl -w > use DBI; > use CGI qw(:standard); > my $plt_no = param("plt_no"); > print header, start_html("Car_reg quering"); > print h1("DB Car_reg Query"); > $dbh = DBI->connect("DBI:Informix:mvdis",{PrintError=>1}) or > err_chk('connect'); > $sth = $dbh->prepare(q%select * from car_reg where plt_no = ? %) or > err_chk('prepare'); > $sth->execute( $plt_no ) or err_chk('execute') ; > while ($car= $sth_car->fetchrow_hashref()){ > print "<p>PLT_NO=$car->{plt_no}</p>"; > } > print "</TABLE>\\n"; > print end_html(); > > $dbh->disconnect; > undef $dbh; > > sub err_chk { > my $progress=shift; > my $errstr=$DBI::errstr; > my $err=$DBI::err; > if (defined $errstr){ > print '<p>Opps¡IDatabase error</p>'; > print "<p>During :$progress </p>"; > print "<p>Reason :$errstr</p>",end_html; > die; > } > } Where is your code checking $sth->{ix_sqlcode}? If no rows are processed, then you might, perhaps, get SQLNOTFOUND, 100, in $sth->{ix_sqlcode}. On the other hand, you probably won't for a SELECT since when the internal fetch code detects the last row is found, it has to close the cursor, and that loses the info from FETCH. Of course, the fetchrow_hashref() code is told that there are no more rows found, but that's no help. You could use $sth->rows to determine the number of rows processed. You could use an explicit counter of your own. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>