Sign in to follow this  
Followers 0
Edifice

#OnAutoItStartRegister and SQlite_startup()

6 posts in this topic

Hello

I thought the new #OnAutoItStartRegister feature was pretty cool, so I decided to use it to initiate SQlite.

I found that if you do that, scite will give you an error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Lasse\Documents\My Dropbox\Programmering\Auto-IT\SQlite.au3"

C:\Program Files\AutoIt3\Include\SQLite.au3 (1168) : ==> Variable used without being declared.:

If @error Then Return $SQLITE_CORRUPT

If @error Then Return ^ ERROR

>Exit code: 1 Time: 0.511

Here is the code used:

#include <SQLite.au3>
#include <SQLite.dll.au3>
#OnAutoItStartRegister "program_start"

Func program_start()
    _SQLite_Startup ()
EndFunc

However, if you replace the OnAutoItStartRegister with a regular function call, it works perfectly:

#include <SQLite.au3>
#include <SQLite.dll.au3>
;#OnAutoItStartRegister "program_start"

program_start()

Func program_start()
    _SQLite_Startup ()
EndFunc

Hope someone can use this info for something :(

Share this post


Link to post
Share on other sites



You're using a very old version of AutoIt. Go to the download page and update first Scite4AutoIt3 then latest AutoIt release.


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

You're using a very old version of AutoIt. Go to the download page and update first Scite4AutoIt3 then latest AutoIt release.

I'm using newest release 3.3.6.0

This problem is with one of the features in V3.3.6.0 so I cannot understand why you would say it's an old version.

Share this post


Link to post
Share on other sites

Oops, sorry, _I_ was mixing versions (I had to double check I didn't goof in SQLite.au3).

I'm looking at that.


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

Your calling _SQLite_Startup () before the constants are declared with the includes at the top of the script. AutoIt jumps directly to the Func program_start() EndFunc declaration and then it starts from the top of the script down.

This code does the same thing

#OnAutoItStartRegister "program_start"
$variable = 'OK'

Func program_start()
    If $variable Then
        MsgBox(0, '', $variable)
    EndIf
EndFunc

program_start() causes error of $variable being undeclared as the $variable declaration will not happen until after the execution of program_start() as defined by #OnAutoItStartRegister.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I was afraid ther could be an awful boo boo in the UDF, but hopefully SQLite.au3 has nothing to do with your problem, as MHz just explained.

What you can do in functions invoked by #OnAutoItStartRegister is limited to what resides inside the function(s) called, so no #include, no global declarations,(*) etc.

In practice, there's no need to initialize SQLite in such contrived way, simply do something like (on the fly translate):

; SQLite
    _SQLite_Startup(@ScriptDir & "\sqlite3.dll", 1)
    If @error Then
        _ByeBox("SQLite3.dll can't be found.")
    EndIf
    OnAutoItExitRegister("_SQLite_ShutDown")

    ; auto-extension Unifuzz
    _SQLite_LoadAutoExtension(@ScriptDir & "\unifuzz.dll")
    If @error Then
        _ConsoleWrite("@error = " & @error & ', @extended = ' & @extended & @LF)
        _ByeBox("Error loading extension Unifuzz.")
    EndIf

    ; open temporary memory database
    $hMemDB = _SQLite_Open()
    OnAutoItExitRegister("_MemDbClose")
    _SQLite_Exec($hMemDB, "PRAGMA foreign_keys = 1;PRAGMA recursive_triggers = 1;")
...

IMHO, OnAutoItExitRegister() is much more useful to be sure things get closed/shutdown properly in the right order in all cases (except AI crash, but that's exceptional).

Edit: (*) this isn't exactly true: you can #include something, but it can't in turn define functions (remember we're already inside a function). You may as well define globals, but hiding them inside a function can be very tricky.

Edited by jchd

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

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