Issue Details (XML | Word | Printable)

Key: CORE-4233
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Vlad Khorsun
Reporter: Vlad Khorsun
Votes: 0
Watchers: 1
Operations

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

In PSQL modules with declared cursors engine could assign value to the wrong variable

Created: 22/Sep/13 10:41 AM   Updated: 25/Sep/15 01:09 PM
Component/s: Engine
Affects Version/s: 2.5.0, 2.5.1, 2.5.2, 2.5.2 Update 1
Fix Version/s: 2.5.3

Issue Links:
Relate
 

QA Status: Done successfully


 Description  « Hide
Consider following procedure:

CREATE OR ALTER PROCEDURE HIDDEN_VARS
  RETURNS (OUT_A INT, OUT_B1 INT, OUT_B2 INT)
AS
DECLARE A INT;
DECLARE C CURSOR FOR
  (SELECT COALESCE( (SELECT COUNT(*) FROM RDB$RELATIONS), -1) FROM RDB$DATABASE);
DECLARE B INT = 0;
BEGIN
  OUT_B1 = B;

  OPEN C;
  FETCH C INTO :A;
  CLOSE C;

  OUT_A = A;
  OUT_B2 = B;
  B = B + 1;
  SUSPEND;
END

Results of first execution:

OUT_A OUT_B1 OUT_B2
353 0 353

Variable B was changed when cursor was fetched !

Second and all subsequent executions:

OUT_A OUT_B1 OUT_B2
353 354 353

Value of variable B keeped after procedure execution !


 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Vlad Khorsun added a comment - 22/Sep/13 12:36 PM
PSQL module could be affected by this bug if
- it contains variable declaration after cursor declaration, and
- cursor query contains COALESCE (and probably other simple CASE equivalents)

Notes:
1. As workaround one could try to declare cursors after all variables.
2. The bug affected generated BLR so it is necessary to recompile correspondig procedures\triggers using fixed engine.
3. FB3 seems not affected because of massive changes in related DSQL code.