Jump to content
Sign in to follow this  
anandchakru

SQLite close problem

Recommended Posts

anandchakru

#include <SQLite.au3>
#include <SQLite.dll.au3>
Local $hQuery, $aRow, $aNames, $sMsg
_SQLite_Startup ()
 _SQLite_Open ("test.db")
_SQLite_Exec(-1,"CREATE TABLE IF NOT EXISTS T (varchar2 blob);")

$sData = _SQLite_Encode(Binary("Hello"))
_SQLite_Exec(-1,"INSERT INTO T VALUES ( " & $sData & " );")
_SQLite_Query(-1,"SELECT * FROM T;",$hQuery)
_SQlite_Query (-1, "SELECT ROWID,* FROM T;", $hQuery)
_SQLite_FetchNames ($hQuery, $aNames)
While _SQLite_FetchData ($hQuery, $aRow,1) = $SQLITE_OK
ConsoleWrite(($aRow[0]))
$sMsg &= Hex($aRow[0]) & @CR
WEnd
_SQLite_Close ()
_SQLite_Shutdown ()

I keep getting this error, wats worng here? can anybody please help

1! SQLite.au3 Error

--> Function: _SQLite_Close

--> Error: Unable to close due to unfinalised statements


[font="Book Antiqua"]Thanks`A[/font]

Share this post


Link to post
Share on other sites
Zinthose

The issue is with the first query not being finalized before the second is executed. Since you don't read the data from the first query, you can simply comment it out and the script works.

If you want to keep it in there for the sake of knowing how to leave it in there, you use the "_SQLite_QueryFinalize" function.

Result:

#include <SQLite.au3>
#include <SQLite.dll.au3>
Local $hQuery, $aRow, $aNames, $sMsg
_SQLite_Startup ()
_SQLite_Open ("test.db")
_SQLite_Exec(-1,"CREATE TABLE IF NOT EXISTS T (varchar2 blob);")

$sData = _SQLite_Encode(Binary("Hello"))
_SQLite_Exec(-1,"INSERT INTO T VALUES ( " & $sData & " );")
_SQLite_Query(-1,"SELECT * FROM T;",$hQuery);       <-- Issue is here
_SQLite_QueryFinalize($hQuery);                     <-- Fix is finallizing the previous query
_SQlite_Query (-1, "SELECT ROWID,* FROM T;", $hQuery)
_SQLite_FetchNames ($hQuery, $aNames)
While _SQLite_FetchData ($hQuery, $aRow,1) = $SQLITE_OK
ConsoleWrite(($aRow[0]))
$sMsg &= Hex($aRow[0]) & @CR
WEnd
_SQLite_Close ()
_SQLite_Shutdown ()

Fixed Sleepy Programmer Error

Edited by Zinthose

--- TTFN

Share this post


Link to post
Share on other sites
anandchakru

The issue is with the first query not being finalized before the second is executed. Since you don't read the data from the first query, you can simply comment it out and the script works.

If you want to keep it in there for the sake of knowing how to leave it in there, you use the "_SQLite_FetchNames" function.

Result:

#include <SQLite.au3>
#include <SQLite.dll.au3>
Local $hQuery, $aRow, $aNames, $sMsg
_SQLite_Startup ()
_SQLite_Open ("test.db")
_SQLite_Exec(-1,"CREATE TABLE IF NOT EXISTS T (varchar2 blob);")

$sData = _SQLite_Encode(Binary("Hello"))
_SQLite_Exec(-1,"INSERT INTO T VALUES ( " & $sData & " );")
_SQLite_Query(-1,"SELECT * FROM T;",$hQuery);       <-- Issue is here
_SQLite_QueryFinalize($hQuery);                     <-- Fix is finallizing the previous query
_SQlite_Query (-1, "SELECT ROWID,* FROM T;", $hQuery)
_SQLite_FetchNames ($hQuery, $aNames)
While _SQLite_FetchData ($hQuery, $aRow,1) = $SQLITE_OK
ConsoleWrite(($aRow[0]))
$sMsg &= Hex($aRow[0]) & @CR
WEnd
_SQLite_Close ()
_SQLite_Shutdown ()
Thank you verymuch, Zinthose ^_^

[font="Book Antiqua"]Thanks`A[/font]

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  

×