Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Accessing @@rowcount global variable
Date: Jul 21 1998 4:56PM
Simon Yaminian writes:
> > Simon Yaminian writes:
> > >
> > > >
> > > > Simon Yaminian writes:
> > > > > Hello,
> > > > >
> > > > > The number of rows affected by a query is reflected in the @@rowcount
> > > > > global variable. Is this variable accessible through Sybperl and if it is
> > > > > how?
> > > >
> > > > In DBlib is DBCOUNT().
> > > > In CTlib it's
> > > > $rows = $dbh->ct_res_info(CS_ROW_COUNT);
> > > >
> > > I tried using the DBlib version, DBCOUNT() right after the
> > >
> > > $dbh->dbsqlexec
> > >
> > > call and it returned -1. The dbsqlexec call was issued after building
> > > the query as a batch of commands using multiple dbcmd calls. Is this a
> > > permissible scenario for using DBCOUNT()?
> > @@rowcount (and hence DBCOUNT()) only return valid data for a SELECT
> > operation *after* all the rows have been processed. This is the normal
> > behaviour (and is the same on other SQL servers, such as Oracle).
> > Michael
> > --
> > Michael Peppler -||- Data Migrations Inc.
> > firstname.lastname@example.org -||- http://www.mbay.net/~mpeppler
> > Int. Sybase User Group -||- http://www.isug.com
> Thanks for your reply.
> I just think that it would have been much more meaningful if @@rowcount
> was available before the rows were processed. Why? Because first of all,
> if you are going through the rows one by one, you can keep track of the
> total rows by merely updating a counter yourself. Second, knowing the rowcount
> ahead of time helps in the decision making process and proper preparation in
> processing the rows especially when dealing with large rowcounts. If you think
> this is just an opinion, consider the following analogy.
> You are trying to walk from street A to street B and you also have the town's
> map with you. However the map can not tell you how many blocks you need to walk
> before you reach your destination unless you have finished walking and made it
> to your destination. I wonder if that map has any significant and sensibe usage!
> Please take that for whatever it's worth to you, maybe I am just mistaken
> about the concept.
I just use the data that Sybase returns to me. The only way that I
could provide you with the @@rowcount info earlier would be to process
all the rows in the query internally.
The Sybase server would have to do the same thing to return an
accurate @@rowcount value *before* returning the rows. This is a
serious performance issue. Please read the documentation on DBCOUNT()
and/or ct_res_info() in the Sybase OpenClient manuals for more info
behind this issue.
Michael Peppler -||- Data Migrations Inc.
email@example.com -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com