Sign in to follow this  
Followers 0
hogfan

_SQLite_GetTable2d returning error 21.

7 posts in this topic

I have done extensive troubleshooting on this issue and am at the point where it makes no sense to me why I am receiving a SQLite "misuse" error when trying to execute a query.   I can run the SQL Query manually and it works fine.

I am trying to use the _SQLite_GetTable2d function to return a 2d array from a table in my SQLite database.  However, after executing the function, instead of returning $SQLite_OK as it should, I am getting an error code 21 returned (SQLite documentation states this is a "misuse" error.  I have done some additional searching on Google, and even tried rebooting my machine thinking the database may be locked after reading some threads... but that does not appear to be the case.

I am properly starting SQLite, Opening the database, Closing the database, & Shutting down SQLite within my function.  I am getting the error specifically on the   _SQLite_GetTable2d  function.  

Here is my function:

 
Func _populateData()
 
;$magic_data variable is declared globally when the script starts and points to C:\magic_data.db
 
Local $aResult, $iRows, $iColumns, $iRval
 
;Start SQLite
_SQLite_Startup()
If @error Then
    MsgBox(16, "SQLite Error", "SQLite.dll could not be loaded!")
    Exit -1
EndIf
 
;open the SQLite database
_SQLite_Open($magic_data)
If @error Then
MsgBox(16, "SQLite Error", "Unable to open database!")
Exit -1
EndIf
 
; Query the Users_Name table
$iRval = _SQLite_GetTable2d($magic_data, "SELECT * FROM Users_Name;", $aResult, $iRows, $iColumns)
 
;Display the returned value for $iRval for troubleshooting error
Msgbox(0,"", $iRval)
 
If $iRval = $SQLITE_OK Then
_SQLite_Display2DResult($aResult)
 
Else
MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
EndIf
 
;close the SQLite database
_SQLite_Close($magic_data)
 
;shutdown SQLite
_SQLite_Shutdown()
 
 
EndFunc

Share this post


Link to post
Share on other sites



Not sure why the rest of my post wasn't included after the AutoIt code section, but here it is:

When it hits @error and returns 21 on the query, it displays the messagebox with the _SQLite_ErrMsg(), and the error message displayed is specifically "No Error message".  I can also run the query from from the SQLite Database Browser 2.0 GUI  Query Window, and I see the same information there.
 
My Users_Name table is formatted as such:
 
Last_Name   First_Name
 
Jones              Bob
Wilson             Mike
 
 
Also I am working off of the example in the AutoIT help file here:
 
 
I am not sure what to check next at this point, so any assistance is greatly appreciated.  
 
-hogfan

Share this post


Link to post
Share on other sites

Can you PM me or post here an archive with your code and the DB?

Also which version of AutoIt are you using and is your code x64 or x86?

I'd like to reproduce the problem locally.


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)

Share this post


Link to post
Share on other sites

hogfan,

Try the following 

Func _populateData()
 
;$magic_data variable is declared globally when the script starts and points to C:\magic_data.db
 
Local $aResult, $iRows, $iColumns, $iRval
 
;Start SQLite
_SQLite_Startup()
If @error Then
    MsgBox(16, "SQLite Error", "SQLite.dll could not be loaded!")
    Exit -1
EndIf
 
;open the SQLite database
local $hDB = _SQLite_Open($magic_data)  ; <--------   create handle to open DB
If @error Then
MsgBox(16, "SQLite Error", "Unable to open database!")
Exit -1
EndIf
 
; Query the Users_Name table
;$iRval = _SQLite_GetTable2d($magic_data, "SELECT * FROM Users_Name;", $aResult, $iRows, $iColumns)
$iRval = _SQLite_GetTable2d($hDB, "SELECT * FROM Users_Name;", $aResult, $iRows, $iColumns)     ; <---- use handle, not dataset name
 
;Display the returned value for $iRval for troubleshooting error
Msgbox(0,"", $iRval)
 
If $iRval = $SQLITE_OK Then
_SQLite_Display2DResult($aResult)
 
Else
MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
EndIf
 
;close the SQLite database
_SQLite_Close($magic_data)
 
;shutdown SQLite
_SQLite_Shutdown()
 
 
EndFunc

The example code you are following is using a "-1" to reference the last opened database.  In my example I am using an explicit handle.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

@kylomas

I will give that a try and post back.

@jchd

Sure,  will post it up shortly.  Busy morning at the office.  Running latest available stable AutoIT version for x86.  Thanks.

-hogfan

Share this post


Link to post
Share on other sites

Kylomas -

It seems to work as expected when creating the handle to open the DB as you suggested.  Would I need to do the same for the _SQL_Close() function when closing the database?  

Thanks for the assistance with this.  It would have taken me a long time to figure this one out. :)

-hogfan

Share this post


Link to post
Share on other sites
Would I need to do the same for the _SQL_Close() function when closing the database? 

 

Yes, use the handle or if no handle is specified the last DB opened is closed.  See the Help file for details.

 

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0