|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at peppler dot org>
Subject: Finding the empty results
Date: Jun 9 1999 4:17PM
Dave Edwards writes:
> Howdy,
>
> I'm sure there is a simple answer, but I just can't see it.
>
> I have the following code (that I modifiey a little from the SybPerl docs) to find the name of a person from their login. I have the user enter a login they want to find: $findlogin. The code works fine, except I want to print a message to the user if there is no one with that login name. How can I test for the empty results set?
>
See added lines in your code below.
Michael
>
> ========== Begin Code ==========
> # Open the connection and use the correct database
> $dbh = new Sybase::CTlib '', '', '';
> $dbh->ct_sql("use ");
>
> # This is our select statement
> $dbh->ct_execute("select login, name, class, is_inactive
> from userinfo
> where lower(login) like \"$findlogin\"");
>
> # Print out the results, if we have any
> # This checks to see if any rows were returned
my $found = 0;
> while (( $davetest = $dbh->ct_results($restype)) == CS_SUCCEED) {
> next unless $dbh->ct_fetchable($restype);
>
> # This actually prints the results
> while (($login, $name, $class, $is_inactive) = $dbh->ct_fetch) {
++$found;
> print "\n";
> print "Login: $login ";
> print "Name: $name\n";
> print "Class: $class ";
> print "Active: $is_inactive\n";
>
> } # End of while (($login, $name, $class, $is_inactive) = $dbh->ct_fetch)
>
> } # End of while ($dbh->ct_results($restype) == CS_SUCCEED)
print "No user found for $findLogin\n" unless $found;
__END__
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@peppler.org -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
|