Normal Topic Downside to a duplicate XResultSetClose (Read 903 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Downside to a duplicate XResultSetClose
Apr 20th, 2012 at 2:53am
Print Post Print Post  
I now have personal knowledge of the downside (locked records, irritation) to an @XResultSetSearch statement that is not properly mated with an XResultSetClose statement.

But, is there a downside to an inadvertent extra XResultSetClose statement?
  

Larry
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Downside to a duplicate XResultSetClose
Reply #1 - Apr 20th, 2012 at 1:52pm
Print Post Print Post  
lksseven wrote on Apr 20th, 2012 at 2:53am:
But, is there a downside to an inadvertent extra XResultSetClose statement?


It can result in you closing an XResultSet you didn't intend to. You want to have exactly as many closes as opens. The structure you want is:

vRS = @XResultSetSearch(...)
If vRS > -1
{
        Do stuff ...
        XResultSetClose(vRS)
}

If it opened successfully, close it. Once.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Downside to a duplicate XResultSetClose
Reply #2 - Apr 20th, 2012 at 4:09pm
Print Post Print Post  
Erica,

I was just thinking in terms of trouble-shooting ... scenario:  my recent scenario:  an application with involved/complex code is having lockup problems, and a missing XResultSetClose is suspected as the culprit ... I didn't know for sure that a missing XResultSetClose was the problem (it could have been a hardware issue (router, server, client, cabling).  It occurred to me (after I found the solution the hard way, of course, and also replaced two network switches and replaced 2 cable runs just for good measure while I went through code with a fine tooth comb) "what if I just went into each event and put an XResultSetClose for each "vRS" as the last thing before the final "}" in that event, then reconciled and tested?"   If I had done that and my lockups had gone away, then I would have quickly at least identified that the needle was in the 'programming haystack' instead of maybe being in the 'hardware malfunction haystack', and kick started me in the right direction to find the missing statement (or misplaced statement).

I just didn't want to keep that in my back pocket for the future if there was going to be a damaging downside to doing so (database corruption, massive hole created in the ozone, etc).
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Downside to a duplicate XResultSetClose
Reply #3 - Apr 20th, 2012 at 4:30pm
Print Post Print Post  
There is no harm so long as you are closing the same result set that you previously opened and closed. But the scenario Erika described does need to be avoided. A result set handle is simply an index into an array of indexes. When you open a result set the actual engine-side index is placed in the client side array. When you close it, that array entry can then be reused. If it has been reused, and you close it again, you are closing the wrong result set. Its not going to harm anything in and of itself. But any decision your code makes about the incorrectly closed secondary (or tertiary) result set, may cause harm.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Downside to a duplicate XResultSetClose
Reply #4 - Apr 20th, 2012 at 4:52pm
Print Post Print Post  
Is it advisable to use different Resultset name instead of using the same one again and again?  My tendency is to use name RSHandlle. I can see this could conflict sometimes if you try to open more than two at the same time with the same name and not closing properly before opening up the other one.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Downside to a duplicate XResultSetClose
Reply #5 - Apr 20th, 2012 at 6:15pm
Print Post Print Post  
Bharat_Naik wrote on Apr 20th, 2012 at 4:52pm:
Is it advisable to use different Resultset name instead of using the same one again and again?  My tendency is to use name RSHandlle. I can see this could conflict sometimes if you try to open more than two at the same time with the same name and not closing properly before opening up the other one.


It depends on the scope of the variable. If global, then - yes, always use different names if there is any possibility of multiple open result sets. If the scope is local, its fine to use a generic name, so long as each open result set is addressed in a different event or subroutine. And, try to use local variables where ever possible. Prefer locals over globals, and globals over fields/elements.

Using either, be careful for this case:
Code
Select All
var aa as int

aa = Open(1)
if(aa > -1)
{
  aa = Open(2)
  if(aa > -1)
  {
    close(aa)
  }
  close(aa)
}
 



In the case above, the result set first opened, is never closed.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Downside to a duplicate XResultSetClose
Reply #6 - Apr 20th, 2012 at 11:36pm
Print Post Print Post  
Bharat,

I always (almost always) use different names for different XResultSetSearches (vRS1,  vRS2,  vRS3, etc)  because - for me - it's the only way to keep them straight without my eyes swimming into one big blur.

Just as an aside comment, I also label my beginning and ending "{" brackets to make it easier to 'see the entire playing field in a complex event where I have to scroll several pages down in the programming editor.   I don't know if it's a dumb idea or not, but it works for me.  As in:

If @Mode() = 0
  { // A  begins 'if @Mode() = 0'
      vRS1 = @XResultSetSearch(....)
      vRS1Tot = @XResultSetTotal(vRS1)
      If vRS1Tot = 1
        { // B begins 'if vRS1Tot = 1'
            a bunch of programming lines here

        } // B ends 'if vRS1Tot = 1'
      XResultSetClose(vRS1)
   } // A ends 'if @Mode() = 0'



Actually, it would be really nice if the program editor was capable of making different font colors  Huh
  

Larry
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Downside to a duplicate XResultSetClose
Reply #7 - Apr 21st, 2012 at 12:13am
Print Post Print Post  
lksseven wrote on Apr 20th, 2012 at 11:36pm:
Actually, it would be really nice if the program editor was capable of making different font colors  Huh

That may be nice, but it would certainly cause a problem with the Syntax Highlighting feature.

But, what would be GREAT, would be if the curly braces could dynamically change to another color (in pairs) or be highlighted when the cursor was placed next to one of them. Many text editors designed for programming do this. They automatically locate the matching component when you put the cursor immediately before or after the item in question. Maybe this should be a requested feature for version 3?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged