Subject Re: [firebird-support] Rows affected...
Author Helen Borrie
At 12:36 AM 9/07/2004 +0000, you wrote:
>Hi
>
>In MSSQL one can use the @@RowCount system value, that holds :
>
>--MSSQL help--
>Returns the number of rows affected by the last statement
>--MSSQL help--
>
>What is the closest equiv. in FB 1.5 ?
>
>More specifically : I want to optimize the translation of this in
>general :
>(MSSQL)
><select query>
>if @@ROWCOUNT = 0 then <do_something_rescue>

OK, this isn't really a good way to do an existential query (although MSSQL
programmers use @@ROWCOUNT = 0 a lot for this purpose!!)


>..without doing the trivial ineff. rewrite :
>(FB)
>(select count(*) <same select's FROM+WHERE part, FB flavoured>)
>into :tmp;
>if(:tmp = 0) then <do_something_rescue>
>else
><select query, FB flavoured>;

You can get a rowcount in PSQL (Fb 1.5) using the ROW_COUNT context
variable. However, it returns the number of rows that were affected by an
insert, update or delete operation within the block. It *doesn't* give you
a rowcount of a SELECT. (There are cheaper ways to get this in PSQL if you
absolutely must!!)

Use the EXISTS() predicate to determine existence, viz.

IF (EXISTS (SELECT 1 FROM ATABLE
WHERE blah)) THEN

/heLen