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: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Objects-in-objects Question
Date: Nov 24 1997 4:56PM

bpollock@ResGen.COM wrote:
> Hi-
> I am trying to write a simple package to help expedite generating some
> reports.  I have some questions on accessing a Sybase::CTlib object that
> must be included in my SybSelect package.  I have included my constructor
> and one of the methods I am using for debugging.
> Is there a better way to include the instantiation of the Sybase::CTlib
> object other than by referencing it through the hash?

You basically have two options. You can do it the way you did,
linking an instance of the Sybase::CTlib object to your new
SybSelect object, or you could inherit Sybase::CTlib in your
SybSelect class. The second method works great if you want
to be able to get at the underlying API when necessary (note - 
untested code - but you should get the idea :-):

package SybSelect;
use Sybase::CTlib
require Exporter;

use vars qw($VERSION @ISA @EXPORT);

@EXPORT = @Sybase::CTlib::EXPORT;  # re-export the symbols from 
                                   # Sybase::CTlib;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self;
    my $srv = shift;
    my $usr = shift;
    my $pwd = shift;

    $self  = new Sybase::CTlib $usr, $pwd, $srv, {SELECT => undef};

    bless $self, $class;

# Supply a DESTROY method so that we make sure that the CTlib DESTROY
# gets called

    my $self = shift;


sub querydb {
    my $self = shift;
    my $ref = $self->ct_sql($self->{SELECT});
    my $line="";
    foreach $line (@$ref) {
        print "@$line\n";

# Return a single row in hash format
sub hashRow {
    my $self = shift;
    return undef if !defined($self->{SELECT});
    my $restype;
    my $data = {};
    while($self->ct_results($restype) == CS_SUCCEED) {
        if($self->ct_fetchable($restype)) {
             %$data = $self->ct_fetch(1);
             $self->ct_cancel(CS_CANCEL_ALL);   # ignore any further


Hope this helps!

Michael Peppler       -||-  Data Migrations Inc.  -||-