Jump to content
c.haslam

_SQLite_Open() sets @extended to 21

Recommended Posts

c.haslam
#RequireAdmin
#include <sqlite.au3>
#include <SQLite.dll.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup()
Local $hsq = _SQLite_Open(@ScriptDir&'\ar.db',$SQLITE_READONLY)
MsgBox(0,'',@error&'  '&@extended&'  '&_SQLite_ErrCode() & @CRLF & "Error Message: " & _SQLite_ErrMsg())
$iRval = _SQLite_GetTable(-1, "schema sqlite_master", $aResult, $iRows, $iColumns)

_SQLite_Close($hsq)
_SQLite_Shutdown()

Why am I getting @extended 21, Library used incorrectly?

SciTe console shows:

@@ Debug(257) : __SQLite_Download_SQLite3File : $URL = http://www.autoitscript.com/autoit3/files/beta/autoit/archive/sqlite/sqlite3.dll
    $sTempfile = C:\Users\Chris\AppData\Local\Temp\~qqhdtom.dll
>Error: 13


I am running AutoIt 3.3.14.0

...chris


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
kylomas

Try it without this...#include <SQLite.dll.au3>


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
benners

_SQLite_Startup() function no longer automatically downloads the SQLite DLL files from autoitscript.com. The url in the console gives a 404 error.

From AutoIt v3.3.14.2 you have to download the files manually from here and put the files in @ScriptDir, @SystemDir, @WindowsDir, or @WorkingDir.

You can put the file in other directories but must specify the file path. Read the latest help file for _SQLite_Startup

Share this post


Link to post
Share on other sites
c.haslam

Thank you both for the help.

I:

  • Updated to AutoIt 3.3.14.2
  • Removed #include <SQLite.db.au3>
  • Downloaded sqlite3.dll from the link you provided

but this script errored out as before:

#include <sqlite.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup()
Local $hsq = _SQLite_Open(@ScriptDir&'\ar.db',$SQLITE_READONLY)
MsgBox(0,'',@error&'  '&@extended&'  '&_SQLite_ErrCode() & @CRLF & "Error Message: " & _SQLite_ErrMsg())
$iRval = _SQLite_GetTable(-1, "schema sqlite_master", $aResult, $iRows, $iColumns)

_SQLite_Close($hsq)
_SQLite_Shutdown()

It ran OK when I removed $SQLITE_READONLY

I will report what appears to be an error to M Lipok (if no one has done so already)


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
kylomas

c.haslam,

Apologies for not looking more closely.  $SQLITE_READONLY is a variable for return codes and is set by SQLite, hence your problem.

No need to notify Mlipok of anything as the doc is correct.

kylomas

Edited by 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
c.haslam

Thnak you for telling me. My error.


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
tremolux66
On 3/20/2017 at 7:19 PM, kylomas said:

c.haslam,

Apologies for not looking more closely.  $SQLITE_READONLY is a variable for return codes and is set by SQLite, hence your problem.

No need to notify Mlipok of anything as the doc is correct.

kylomas

PROBLEM SOLVED:  I had the SQLite function calls out of order: the backup was being done (by an external program) before the original database had been opened, so when _SQLiteOpen() was called to open the backup database, _SQLite_Startup() hadn't been called yet. My bad. :>

Original post:

I'm still using AutoIt 3.3.14.2 with SQLite 3.8.11.1 and am having the same problem (@extended = 21) when I call _SQLite_Open("dbase_backup.db", $SQLITE_OPEN_READONLY). I looked at SQLite.au3 and that constant does seem to be an access flag; it's grouped with $SQLITE_OPEN_READWRITE and $SQLITE_OPEN_CREATE.

I'm opening a backup database (that was just created) and don't want to accidentally modify it. Any ideas?

 

UPDATE: I tried calling _SQLite_Open("dbase_backup.db"), i.e., without the access flag, and I still get a handle of 0 and @extended = 21, so perhaps my problem isn't as closely related to this question as I originally thought. (Still grateful for suggestions, though. :))

Edited by tremolux66
Solved problem myself - cockpit error.

When the going gets tough, the tough start coding.

Share this post


Link to post
Share on other sites
dmob

Here's a shot in the dark:
 

Check if you're using the correct sqlite.dll for your @CPUArch. I get the error when I Run (x64) instead of Run for x86.

Share this post


Link to post
Share on other sites
jchd

@tremolux66 be warned that an SQLite DB may have hot journal file(s) along the .db file itself. If you don't copy all of them while no other process is modifying the DB you are at risk of relying on an inconsistant copy.

Always prefer using the SQLite backup API. Here's an example implementation (read the thread):

 


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
tremolux66

@dmob

Thanks. It turns out it was nothing complex, just a dumb mistake that occurred while modifying old code, as follows:

Original sequence:

  1. Back up database (exec external program)
  2. Start SQLite and open original database
  3. Proceed with processing; backup database never accessed

New (broken) sequence:

  1. Back up database (exec external program) and open backup database for reading (fail)
  2. Start SQLite and open original database
  3. Proceed with processing; backup database might be read later in the program

Corrected sequence:

  1. Start SQLite and open original database
  2. Back up database (exec external program) and open backup database for reading (success)
  3. Proceed with processing; backup database might be read later in the program

The error wasn't immediately obvious due to the way the code is organized; the simplest fix was to just swap steps 1 and 2. As for the DLL, we place a copy of the desired SQLite DLL in @ScriptDir and start SQLite with _SQLite_Startup("", False, 1) to force use of the local copy (a carryover from the days when it still tried to download the DLL; our system is not connected to the Internet so we had to solve that problem immediately).

@jchd

Thanks. No worries, I think: we're not copying the database file, we exec a Bash script that tells SQLIte to make the backup:

#!/bin/bash
# Iniitalization ...

# Back up the database
sqlite3 "$DBASE_PATH" <<_EOF_
.echo on
.backup "$DB_BACKUP_FILE"
.quit
_EOF_

# Wrap up and exit

This technique may not win any awards for elegance, but it's simple and it enables us to back up a database either from the command-line or an AutoIt script (ShellExecuteWait()). There's additional logic in the Bash script to get the database location from a config file, etc., and if we need to change some details, we can edit the Bash script and don't have to modify the compiled AutoIt script.

Edited by tremolux66
Fix wording.

When the going gets tough, the tough start coding.

Share this post


Link to post
Share on other sites
jchd

Fine. I was simply pointing out that hot journal files might be present and needed for getting a full correct backup. Good that you already know that and use the CLI (sqlite3.exe) but some other future readers of this thread may benefit from the remark.

BTW, _SQLite_Startup() doesn't try to download a DLL anymore as it caused too much pressure on AutoIt server.


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

×