PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Beginner question - doing async communications with Sybase
Date: Dec 4 1997 10:08PM

Wechsler, Steven M wrote:
> 
> 
> However, looking at the Sybperl CT-LIB documentation doesn't seem to
> shed any light on how I can do this.  Sending commands and receiving
> data back is fairly straightforward, but how can I tell that the SQL
> server has sent the data before I start querying.  Can I do something
> like this:
> 
> 
> finished=1;     # flag
> foreach $server (@dbh) { # dbh is an array of DB handles
>   if (($rc = $server->ct_results(CS_CMD_DONE)) != CS_SUCCEED) {
>     if ($rc == CS_FAIL) {
>       # command failed; take appropriate action
>     } elsif (($rc = $server->ct_results(CS_COMPUTE_RESULT)) ==
> CS_SUCCEED {
>       # does this mean that the command is still running?  if so,
>       $finished=0;
>       last; # in real life there'd be some sort of timeout, after
>       # which we'd assume the server was down because it hadn't
>       # responded in time.
>     }
>   }
> }

I'd do it like this:

foreach $dbh (@dbh) {
   $dbh->ct_execute($cmd);
   while($dbh->ct_results($restype) == CS_SUCCEED) {
      if($dbh->ct_fetchable($restype)) {
          while(@dat = $dbh->ct_fetch) {
   	     # do something with the data here
          }
      }
   }
}

This way you query each server one after the other.
Sybperl does not allow you to do asynchronous querying, so this
way is simplest, and is usually good enough, especially if
you're running simple things like sp_who, sp_locks, etc.

Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler