Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Dave Edwards <ITSDSE at qe2-hsc dot ns dot ca>
Subject: Finding the empty results
Date: Jun 9 1999 4:03PM


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?

Thanks for your help.

========== 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
  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) {
 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)

========== End Code ==========

Dave Edwards
QEII Health Science Centre
Halifax, Nova Scotia