lNoVal

FileOpenDialog and SQLite Error

4 posts in this topic

#1 ·  Posted (edited)

Hi Guys,

first of all i wanna thank you for this greate forum. I am a autoit newbie and leaned allready a lot (i belive) by reading this forum.

Now i got to a strange problem. 

If i open a FileOpenDialoge befor using my sqlite connection. SQL will not find the DB table. (See first script)

But if i comment the FileDialog it works fine and i get the result of my DB Table.

Where is the mistake?

Thx for your help.

 
#include <Array.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
local $sMessage
local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\" , "All (*.*)")

global $sSQliteDll = _SQLite_Startup("SQLite3.dll")
If @error Then
MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
"Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir or from www.autoitscript.com")
Exit -1
 EndIf

local $DB_Main_MainDB = _SQLite_Open("Main_DB.db3")
Local $hQuery,$aRow
local $sql = "SELECT * FROM testscript"
 _SQLite_Query($DB_Main_MainDB, $sql,$hQuery)

dim $test
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
    $test = $arow[0]
wEnd
msgbox (0,0,$test)
#include <Array.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
local $sMessage
;--------------------------------------------------------------------------------------------
;local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\" , "All (*.*)")
;-----------------------------------------------------------------------------------------
global $sSQliteDll = _SQLite_Startup("SQLite3.dll")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
            "Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir or from www.autoitscript.com")
    Exit -1
 EndIf

local $DB_Main_MainDB = _SQLite_Open("Main_DB.db3")
Local $hQuery,$aRow
local $sql = "SELECT * FROM testscript"
 _SQLite_Query($DB_Main_MainDB, $sql,$hQuery)

dim $test
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
    $test = $arow[0]
wEnd
msgbox (0,0,$test)
Edited by lNoVal
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

lNoVal,

A successful return from FileOpenDialog resets the @WorkingDir to the path of the returned file. I imagine that the _SQLite_Open cannot then find the database file as it is looking in the wrong place. :(>

Try passing the full path, or reset the path with FileChangeDir. :)

M23

Edit: And welcome to the AutoIt forums. :)

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba23 your the best :)

Here is the working code if someone has the same Problem..

#include <Array.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>


Global $glb_MAIN_DBname = @WorkingDir&"\Main_DB.db3"
local $sMessage
local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\" , "All (*.*)")


 FileChangeDir(@WorkingDir)
global $sSQliteDll = _SQLite_Startup("SQLite3.dll")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
            "Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir or from www.autoitscript.com")
    Exit -1
 EndIf

;msgbox(0,0,$glb_MAIN_DBname)
local $DB_Main_MainDB = _SQLite_Open($glb_MAIN_DBname)

Local $hQuery,$aRow
local $sql = "SELECT * FROM amis_testcasescript"
 _SQLite_Query($DB_Main_MainDB, $sql,$hQuery)

dim $test
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
    $test = $arow[0]
wEnd
msgbox (0,0,$test)
1 person likes this

Share this post


Link to post
Share on other sites

lNoVal,

This line merely sets the @WorkingDir to its current content and so is completely superfluous: :(>

FileChangeDir(@WorkingDir)
What you need to do is something like this: ;)

Local $sWorkingDir = @WorkingDir ; Save current WorkingDir in a variable
Global $glb_MAIN_DBname = $sWorkingDir & "\Main_DB.db3"
local $sMessage
local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\" , "All (*.*)")
; WorkingDir will now be changed
FileChangeDir($sWorkingDir) ; So reset WorkingDir to the original saved path
All clear? :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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