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: "Rolf G Lear" <lear_rolf at jpmorgan dot com>
Subject: Connections and Forking ....
Date: May 16 2000 12:48PM

Excuse me as a recent arrival on to this list ...

I have a question about forking and database connections. My situation is that I
would like to run queries simultaneously on two different servers ($dbs and
$dbt).

Basically, this is more a perl question than a sybperl question, but I am hoping
there is an answer.

Bottom line, really, can be explained with one connection. Is it possible to
connect, and then in a child, do a retrieve, and make the results available
again to the parent?

Rolf

#!/usr/local/bin/perl -T -w

use Sybase::CTlib;
use strict;

my ($uid, $pwd, $srv) = ('lear', 'mysafepassword', 'SYBASE');

my $db;

$db = Sybase::CTlib->ct_connect($uid, $pwd, $srv) or die "Could not connect.";

my $child;
my $ret;
my $res_type;
$child = fork ();
if ($child) {
  # then parent ... ;-)
  # Do lots and lots of other stuff.
  wait ();
  # The following line does not work.
  do_fetches ();
} else {
  $ret = $db->ct_execute ("select suid, name from master..syslogins");
  die ("Could not execute sql.") unless $ret == CS_SUCCEED;
  $ret = $db->ct_results($res_type);
  while ($ret == CS_SUCCEED && ! $db->ct_fetchable ($res_type)) {
    $ret = $db->ct_results($res_type);
  }
  die "No valid results" unless $ret = CS_SUCCEED;
  # The following line works.
  #do_fetches ();
  exit 1;
}

sub do_fetches () {
  my @dat;
  while (@dat = $db->ct_fetch ()) {
    print "ID $dat[0], Name $dat[1]\n";
  }
}



This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan & Co. Incorporated, its
subsidiaries and affiliates.