Jump to content

SQL - GetRows method fails when no records are returned


Gorby7
 Share

Recommended Posts

I'm using 3 easy SQL functions written by Locodarwin found here: They work great, I use the GetRows method to extract the results into a 2D array.

The problem comes when there are no records/rows returned. The GetRows method fails with a console output error of "The requested action with this object has failed" and "$aResults=$oResults.GetRows()^ ERROR". I cannot figure out a way to check to see if there no records before calling the GetRows method. I tried using the RecordCount method but it always returns -1 because the recordset is forward-only/read-only. I tried to UBound the results object, but of course that didn't work. Any ideas? Here's my code:

$oOpen=_SQLConnect("server","database",1,"sa","password")
$oResults=_SQLQuery($oOpen,"EXEC Stored_Procedure_Name")
$iColumns=$oResults.Fields.Count
MsgBox(0,"","Rows: " & UBound($oResults))
MsgBox(0,"","Rows: " & $oResults.RecordCount)
$aResults=$oResults.GetRows()
$iIndex=UBound($aResults)
_SQLDisconnect($oOpen)
Link to comment
Share on other sites

A standard way to avoid hitting this wall if doing something like:

If Not $oResults.EOF Then
$aResult = $oResults.GetRows()
...
EndIf

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

You're welcome; glad it works as expected in your case.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...