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: "Wechsler, Steven" <steven dot wechsler at wsaccess dot com>
Subject: ct-lib printing extraneous row
Date: Mar 8 2001 9:19PM

I have a CT-library script that retrieves rows of data from a database based
on a SQL query, and outputs it in a BCP-style format. When it calls a stored
proc rather than executing an ad-hoc query, I get a row with a '0' on it,
which screws up the format of the file. Ad-hoc queries seem to work fine.
Here's the part that does the data retrieval and writing (most of it stolen
from the examples on Michael's web page, since I'm new to CT-Library):

while(($rc = $source_handle->ct_results($restype)) == CS_SUCCEED) {
    next if($restype == CS_CMD_DONE || $restype == CS_CMD_FAIL ||
	    $restype == CS_CMD_SUCCEED);
    die "Error returned from SQL Server\n" if $DB_ERROR;
    $cols = int($source_handle->ct_col_types());
    undef $\;
    print "retrieving data" if $debug;

    while(@row = $source_handle->ct_fetch) {
	next if (@oldrow eq @row && $opt_d);
	@oldrow = @row;
	$count = 0;
	foreach (@row) {
	    $count++;
	    print OUT "$_";
	    print OUT $opt_t unless $count == @row;
	}
	print OUT $opt_r;
    }
}

opt_t and opt_r are column and row terminator, respectively. Any ideas as to
what could be causing that trailing '0'?

Thanks,

Steve
--
Steve Wechsler/Application Manager/Wall St. Access
Steven.Wechsler@wsaccess.com
"There is no reason anyone would want a computer in their home." 
-- Ken Olson, president, chairman and founder of DEC, 1977
Support Anti-Spam legislation: http://www.cauce.org