SQL result set stepped on when calling to another method

Caché

Hi all,

We just encountered an instance of a result set RS and while looping through the results,  RS is getting overwritten when method 1 calls out to method 2 (in the same class).  Method 2 creates it own result set also named RS.     

This code is several years old and never had this problem.    When I changed the name of the result set variable in method 1 the problem cleared up.  

I though that variables were automatically 'newed' in classmethods. ???

We also recently upgrade to the latest Cache version from a much older version.    Is it possible that variable scope has changed across methods?

 

Thanks for any info  you can provide!

  • 0
  • 0
  • 51
  • 2
  • 2

Answers

for details on variable scoping see Summary on Local Variable Scoping

As the SQL Code generator dates from times where ProcedureBlock was unknown
any generated code for SQL access I've seen over decades just works with  [ ProcedureBlock = 0 ]

The 'automatic' you mention is the default if your class is set t to [ ProcedureBlock = 1 ] which is a default.

By changing the variable name you found the best solution yourself.   yes

Does your class (base class) or method has these modifiers:

?

This class has the following:

Extends %CSP.Page [ ClassType = "", Not ProcedureBlock ]

From docs:

Procedure blocks enforce variable scoping: methods cannot see variables defined by their caller. New applications use procedure blocks; non-procedure blocks exist for backwards compatibility.