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: Running multiple SQL statements concatenated together
Date: Oct 14 2003 4:35PM

On Tue, 2003-10-14 at 09:08, Avis, Ed wrote:
> In Sybase command shells such as sqsh, you can run more than one
> SQL query or statement at a time:
> 
> sqsh> select 5 from foo
> sqsh> select 7
> sqsh> go

That functionality is implicit in the Sybase TDS protocol - multiple
result sets are support in a single query (i.e. in a command batch).

> I would like to do this from Perl programs using DBI - I want to
> write a simple command interpreter and it should have roughly the
> same behaviour as sqsh in this case.  But when I give the string
> to DBI, it seems that only the first query is executed and the
> 'select 7' gets ignored.

Err - it would appear that you haven't read the DBD::Sybase docs
correctly.

Here's how you do it:

$sth = $dbh->prepare($sql_cmd);
$sth->execute;
do {
    while($d = $sth->fetch) {
        print "@$d\n";
    }
} while($sth->{syb_more_results});

Michael
-- 
Michael Peppler                              Data Migrations, Inc.
mpeppler@peppler.org                 http://www.mbay.net/~mpeppler
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or 
long term contract positions - http://www.mbay.net/~mpeppler/resume.html