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: Queries n rows at a time
Date: Jul 16 1998 9:54PM

Simon Yaminian writes:
 > 
 > > 
 > > Perhaps I have misunderstood the question but isn't it enough to run the query
 > > through $dbh->dbcmd, dbsqlexec (not thru $dbh->sql or siblings). Then run a
 > > dbnextrow loop and in the loop, work with 200 rows at a time, then get the next
 > > 20 rows, etc.
 > > 
 > > Something like :
 > > 
 > > $dbh->dbcmd($query);
 > > $dbh->dbsqlexec;
 > > $dbh->dbresults;
 > > my ($count) = 0;
 > > while (($col1, $col2, $col3) = $dbh->dbnextrow)
 > > {
 > >     $count++;
 > >     # save $col1, $col2, $col3 into some structure
 > >     if ($count == 200)
 > >     {
 > >         $count = 0;
 > >         # process the batch of rows
 > >     }
 > > }
 > > 
 > > 
 > 	Thank you for the thought.
 > 
 > The hangup is that when the query is put together in the dbcmd, the 
 > dbsqlexec call does not return until the query is completed and this
 > may take a while. The catch is to break the dbsqlexec call for instance
 > into a set of "current" and "next" exec calls so we can have a break
 > in the processing time while also having some data to work with. Again
 > put all query semantics aside. The idea may seem complicated but it is
 > in really simple. The key is to maintain a reference point (by Sybperl)
 > in the submitted query.

The if the query takes time to complete you should consider modifying
it, or adding indexes. The time dbsqlexec() takes to return is not
necessarily linked with the number of rows the query will ultimately
return.

Setting rowcount should not affect the time it takes to run the query, 
but it will limit the number of rows that are returned, obviously.

This being said, you can't do what you'd like to do because there are
no SQL primitives to handle that sort of thing directly.

The only way is to do multiple queries on smaller chunks, using a
primary key in a where clause.

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com