Issue Details (XML | Word | Printable)

Key: CORE-2965
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dmitry Yemanov
Reporter: Alex Kurov
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Incorrect ROW_COUNT value after SINGULAR condition

Created: 12/Apr/10 03:41 PM   Updated: 15/Jun/11 04:12 PM
Component/s: Engine
Affects Version/s: 2.0.5, 2.5 RC2
Fix Version/s: 2.5 RC3, 3.0 Alpha 1

Time Tracking:
Not Specified

Environment: WIN7 2.5 RC2 SS
Issue Links:
Relate
 

Planning Status: Unspecified


 Description  « Hide
Test case:

execute block
returns(rcount integer)
as
declare tmpint integer;
begin
   select rdb$relation_id from rdb$database into tmpint;
   if (SINGULAR(select rdb$relation_id from rdb$database where rdb$relation_id is null)) then begin end
   rcount = row_count;
   suspend;
end;

returns:
1

should return:
0

 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Sean Leyne added a comment - 12/Apr/10 04:56 PM
Please explain why you think the current result is incorrect.

Alex Kurov added a comment - 12/Apr/10 05:24 PM
You can try another sql statement

execute block
returns(rcount integer)
as
declare tmpint integer;
begin
   select rdb$relation_id from rdb$database into tmpint;
   if (SINGULAR(select * from rdb$relation_fields)) then begin end
   rcount = row_count;
   suspend;
end;

And you'll see it does not return 1 as the example above

So if subselect in singular condition doesn't return any dataset the ROW_COUNT variable stays unaffected.

Dmitry Yemanov added a comment - 12/Apr/10 06:53 PM
ROW_COUNT means the number of records selected or modified by the SELECT, INSERT, UPDATE or DELETE clause. It is not intended to return number of records affected by sub-queries.

Alex Kurov added a comment - 13/Apr/10 03:18 AM
Ok. But as you can see from the second example - it does. It seems like row_count is equal to number of rows fetched from rdb$relation_fields (it is subselect)

Dmitry Yemanov added a comment - 13/Apr/10 08:22 AM
You're right, we have some inconsistency here. The counter is reset for the every SELECT/UPDATE/etc statement, but incremented per every fetch, including sub-queries. I suggest to fix it by not incrementing the counter for sub-queries.