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 peppler dot org>
Subject: Re: Sybase::CTlib / stored procs problem
Date: Aug 14 2000 8:15PM

Mark A. Downing writes:
 > I'd like to be able to call a stored procedure from sybperl, and retrieve
 > the output from that procedure so I can manipulate it. Unfortunately, I am
 > having difficulty making it work. 
 > 
 > Could someone post an example using say, sp_helpdb or something. I can do
 > what I want to do with an old fashing ct->sql($sql) command, but I'd rather
 > not reinvent the wheel and use an existing procedure I wrote.

You just have to remember that some of the output from system stored
procs is returned via PRINT statements, which are sent to the server
callback (see ct_callback()).

Other than that, you should take a look at the basic fetch loop in
ct_sql() and possibly adapt it to your needs.

Basically, the loop goes like this:

while($dbh->ct_results($restype) == CS_SUCCEED) {
    next unless $dbh->ct_fetchable($restype);
    while(@d = $dbh->ct_fetch) {
	... do something with this set of returned rows
    }
}

Now you can adapt this behavior by doing different things for
different types of results.

A stored proc can return the following result types:

CS_STATUS_RESULT
	This is the execution status, possibly set via a "return"
	statement in proc.

CS_ROW_RESULT
	A normal SELECT statement. If there are several select
	statements in the proc then you will get several result sets
	with this $restype.

CS_PARAM_RESULT
	Return parameters that were declared with the OUTPUT
	qualifier.

CS_COMPUTE_RESULT
	Returned for any select statement that includes a COMPUTE BY
	clause. 

Hope this helps...

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com