is cursor automatically closed with sqlquery_retrieveAsArray

This is the place to post technical queries about SQL Yoga

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

is cursor automatically closed with sqlquery_retrieveAsArray

Post by trevordevore » Fri Oct 11, 2013 2:32 pm

[This post is an archive from the old SQL Yoga forums]

I notice that in a sqlyoga query object, there is a "cursor id" in the query object array. Should I be calling "sqlquery_close" on that cursor id?

The API says that this call "Closes an open database cursor associated with a SQL Query Object." Although it seems to imply that only sqlquery_retrieve returns an open cursor.

Calling sqlquery_get(tQueryA, "cursor id") also returns a number greater than zero. I'm using sqlyoga version 1.0.2 build 5, and I understand from some of the earlier release notes, that using sqlquery_get to get a cursor id will return zero if the cursor does not exist. Perhaps I have misunderstood that. But I think that one needs to know if there are open cursors, otherwise one is likely to incur memory leakage (or worse).

Whilst the cursor id in the query object is a number greater than 0 (or non-empty) that suggests the cursor is still open. If I try to call "sqlquery_close" on Valentina (passing the query object), then LiveCode crashes (and the LC log reports that it was dealing with a Valentina Cursor Destructor action immediately before the crash.) If I try and use the cursor id with the Valentina API (e.g. to ask the cursor for one of its properties) that also causes a crash.

I'm guessing that sql yoga is automatically closing the cursor, and whilst the query object is returning the handle for a Valentina cursor, that cursor no longer exists.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: is cursor automatically closed with sqlquery_retrieveAsA

Post by trevordevore » Fri Oct 11, 2013 2:32 pm

SQL Yoga closes the cursor in all instances except when calling sqlquery_retrieve. SQL Yoga is failing to reset the cursor property, however. I will fix this.

On a side note - when developing with Valentina you should change the debug level so that passing in bad cursors doesn't crash the application. You can use dbconn_setVendor to set the debug level. Just use the string literals that are listed in the Valentina documentation.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: is cursor automatically closed with sqlquery_retrieveAsA

Post by trevordevore » Fri Oct 11, 2013 2:32 pm

Thanks for clarifying. I'll ask on the Valentina list about this debug leval and its relationship to crashing. In my experience, any kind of error in interacting with Valentina causes LC to crash. I've often been running with debug set to the max on Valentina, and I believe I've still had crashes (possibly I just did not notice the failure to crash). Now that I have this closed cursor issue. I should be able to discover definitively if setting the debug level for Valentina prevents LC from crashing. I'd been working on the assumption that Valentina's developers thought that crashing a the application misusing the Valentina api was considered a feature :)
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: is cursor automatically closed with sqlquery_retrieveAsA

Post by trevordevore » Fri Oct 11, 2013 2:32 pm

Depending on the debug level Valentina may or may not check whether a cursor or other reference you pass in is valid. I believe this has to do with speed considerations. If Valentina isn't set to check and you pass in a bad cursor reference then a crash occurs. Of course, there may be other causes of crashes but this is a common one during development.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “SQL Yoga”