|
|
sybperl-l Archive
Up Prev Next
From: Alain Trembleau <apt at melbpc dot org dot au>
Subject: Connection to a server from a subroutine
Date: May 20 1999 6:59AM
Hi!
I'm new to sybperl, (and fairly new to perl!) and what I am trying to do
is the following:
(Note that I am using MP's SybTools package and I'm using sybperl 2.10)
#!/usr/bin/perl -w
use strict;
use SybTools;
use vars qw($results);
$results = runsql("TEST", "select getdate()");
$results = runsql("TEST", "select getdate()");
sub runsql {
my($server,$statements) = @_ ;
my($dbh,$output);
$dbh = new SybTools "", "", $server; # I've removed identifiers
$output = $dbh->ArrayOfHash($statements);
return $output;
}
i.e. the database connection is performed within the runsql subroutine.
What happens is that it crashes the second time runsql is called, giving
the following error:
Open Client Message:
Message number: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (129)
Message String: ct_bind(): user api layer: external error: An invalid
locale was supplied in the CS_DATAFMT structure.
ct_bind() failed at /usr/lib/perl5/site_perl/SybTools.pm line 97.
If I change the routine so that the connection to the server is done
outside the subroutine, it works fine, as below:
#!/usr/bin/perl -w
use strict;
use SybTools;
use vars qw($dbh $results);
# Now do the connection here.
$dbh = new SybTools "", "", "TEST"; # I've removed identifiers
$results = runsql("TEST", "select getdate()");
$results = runsql("TEST", "select getdate()");
sub runsql {
my($server,$statements) = @_ ;
my($output);
$output = $dbh->ArrayOfHash($statements);
return $output;
}
The documentation says that "call to new() is automatically closed when
the $dbh goes out of scope",
so I can't see why the first program shouldn't work.
Any suggestions? My feeling is that sybperl isn't cleaning up after
itself, but I'd be more than
happy to hear otherwise!
Cheers
alain trembleau
apt@melbpc.org.au
|