On Fri, Aug 10, 2001 at 03:05:20PM -0700, Michael Peppler wrote:
> Tim Harsch writes:
>  > Hi Michael,
>  >    I was looking a t script today that ran Sybase DBI code on a Sybase table
>  > and the exact same Oracle DBI code on an Oracle table that matched the
>  > Sybase table exactly.
>  > 
>  > 00089          $sth_getrow_SYB = $hSYB->prepare( <<SQL );
>  > 00090           select *
>  > 00091            from $Stable
>  > 00092           where $PKname > ?
>  > 00093             and $PKname <= ?
>  > 00094 SQL
>  > 00095
>  > 00096          $sth_getrow_ORA = $hORA->prepare( <<SQL );
>  > 00097               select *
>  > 00098                from $Otable
>  > 00099               where $PKname > ?
>  > 00100                 and $PKname <= ?
>  > 00101 SQL
>  > 00102          $sybrows = $sth_getrow_SYB->execute( $current_min,
>  > $current_max );
>  > 00103          $orarows = $sth_getrow_ORA->execute( $current_min,
>  > $current_max );
>  > 
>  > $sybrows = -1
>  > 
>  > and
>  > 
>  > Oracle = '0E0'
>  > 
>  > Either you or Tim need to get in synch.
> 
> According to the DBI specs:
> 
>            For a non-SELECT statement, execute returns the number
>            of rows affected, if known. If no rows were affected,
>            then execute returns "0E0", which Perl will treat as 0
>            but will regard as true. Note that it is not an error
>            for no rows to be affected by a statement. If the
>            number of rows affected is not known, then execute
>            returns -1.
> 
>            For SELECT statements, execute simply "starts" the
>            query within the database engine. Use one of the fetch
>            methods to retreive the data after calling execute.
>            The execute method does not return the number of rows
>            that will be returned by the query (because most
>            databases can't tell in advance), it simply returns a
>            true value.
> 
> I guess that I took this to mean that I return -1 if I don't know the
> number of rows affected (which is the case for SELECT statements),
> rather than the 0E0 value (0 but true) which could be interpreted as
> meaning 0 rows affected, which would be wrong.
> 
> Mr. Bunce - would you care to comment?

No one should expect to get a meaningful row count back from execute() on
a select statement.

Both "0E0" and "-1" are "true values" and thus conform to the spec :)

For select statements you should only care if execute() returns a true value.

Tim.

p.s. In fact "affected" is fairly meaningless itself for select statements.

Reply via email to