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: Got Slakware & Sybperl to work!
Date: Oct 16 1997 4:05PM

Rick Smith wrote:
> 
> OK I got sybperl working.  woohoo.  now, following the examples,
> I can get it to do a query, and return results.
> 
> Can anyone send me a perl script that uses CTlib calls to query
> a SQL db, return results, and DO something with them ?  I'm having
> trouble figuring out the format of how the data comes across...

Here's a sample script (it's actually the who.pl script from the
sybperl eg directory changed to use ctlib) This script is
basically a better sp_who:

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

format STDOUT_TOP=
                    Sysprocesses Report

Spid Kpid     Engine Status Suid Hostname Program    Hostpid
Cmd            Cpu  IO   Mem Bk Dbid Uid Gid
---------------------------------------------------------------------------------------------------------
..
format STDOUT=
@### @########## @# @<<<<<<< @## @<<<<<<< @<<<<<<<<<< @#####
@<<<<<<<<<<<<< @### @### @### @# @# @### @###
$dat{spid}, $dat{kpid}, $dat{engine}, $dat{status}, $dat{suid},
$dat{hostname}, $dat{program_name}, $dat{hostprocess}, $dat{cmd},
$dat{cpu}, $dat{physical_io}, $dat{memusage}, $dat{blocked}, $dat{dbid},
$dat{uid}, $dat{gid}
..

use Sybase::CTlib
require 'ctutil.pl';

### Please fill in appropriate user/pwd/server values!
my $x = Sybase::CTlib $user, $pwd, $server;
$x->ct_execute("select * from master..sysprocesses\n");
my $restype = 0;
while($x->ct_results($restype) == CS_SUCCEED) {
    next if !$x->ct_fetchable($restype);
    while(%dat = $x->ct_fetch(CS_TRUE)) {
        write;
    }
}

exit(0);

__END__

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