Craig Sharp wrote:

> I need to be able to determine if a value is not found within a database and if so, 
>report that the data and or row is not available back to the browser.

This is a classic instance of why the DBD::Informix docs says "when you ask about 
problems related to DBD::Informix, include DBD::Informix in the subject line".  I 
completely missed the start of the
conversation because I didn't spot that it was related to DBD::Informix.


> Here is my script that I am using to retrieve the data:
>
> >>>>>> SNIP >>>>>>>>>
>
> $dbh = DBI->connect("DBI:Informix:domain",
>                     {
>                       RaiseError => 1,
>                       AutoCommit => 0
>                     }
>                     );
>
> $sth = $dbh->prepare("update reg_info set active = ? where domain_name = ?");
> $sth->bind_param( 1, $postInputs{'active'} );
> $sth->bind_param( 2, $postInputs{'domain_name'} );
> $sth->execute();
>
> $sth = $dbh->prepare("select * from reg_info where domain_name = ? and active = ?");
> $sth->bind_param( 1, $postInputs{'domain_name'} );
> $sth->bind_param( 2, $postInputs{'active'} );
> $sth->execute();
>
> @row=$sth->fetchrow_array();
>
> print "<h3><center>You have successfully updated the following 
>information!</center></h3>";
> print "<center>Domain Name: $row[0]</center>";
> print "<center>Active: $row[5]</center>";
> print "</body></html>";
> print "&nbsp";
>
> >>>>>> SNIP >>>>>>>>>
>
> If the update statement cannot run due to the domain_name not existing in the 
>database I need to send an error back to the browser.

The update statement can run regardless of whether there are any rows with the given 
domain name in the database.  It is just that if there are no such entries, the SQL 
will update zero rows.

You can find out how many rows were updated with $sth->rows, or with the 
Informix-specific attributes such as $sth->{ix_sqlerrd}[1] -- check the index number 
since I'm working from memory.

If it says zero rows updated, that means that there was no matching row in the 
database.  You can generate your appropriate error message.

Note that in standard Informix databases (other than MODE ANSI), an UPDATE that 
updates zero rows succeeds.  In a MODE ANSI database, you get back an SQLNOTFOUND 
status, at the ESQL/C level.  I forget off the
top of my head how DBD::Informix maps that.

>  A similar thing would be if the user was searching for a domain such as:
>
> select * from reg_info where domain_name = "mydomain.com"
>
> and the domain cannot be found in the table.

That too will return zero rows of data.  No error, just no data either.

>
> Thanks,
>
> Craig A. Sharp
> Unix Systems Administrator
> DNS Administrator
> Roush Industries
> Office: 734-466-6286
> Cell: 734-231-6769
> Fax: 734-466-6939
> [EMAIL PROTECTED]
> ====================================================
> I have not lost my mind, it's backed up on tape somewhere!
> ====================================================




--
Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED])
Guardian of DBD::Informix 1.00.PC1 -- see http://www.cpan.org/
#include <disclaimer.h>


Reply via email to