macran

Can't Found sqlite3.exe

4 posts in this topic

#1 ·  Posted (edited)

Func _SQLite_SQLiteExe($sDatabaseFile, $sInput, ByRef $sOutput, $sSQLiteExeFilename = -1, $bDebug = False)
    If $sSQLiteExeFilename = -1 Or $sSQLiteExeFilename = Default Then
        $sSQLiteExeFilename = "sqlite3.exe"
        If Not FileExists($sSQLiteExeFilename) Then
            Local $sInlineVersion = "_" & Call('__SQLite_Inline_Version')
            If @error Then $sInlineVersion = "" ; no valid SQLite version define so use any version
            Local $sSQLiteExe_FilePath = @TempDir & "\"
            $sSQLiteExeFilename = __SQLite_Download_SQLite3File($sSQLiteExe_FilePath, "sqlite3", $sInlineVersion, ".exe", True)
            MsgBox(0,"","download")
            If @error Then Return SetError(2, 0, $SQLITE_MISUSE) ; Can't Found sqlite3.exe
            $sSQLiteExeFilename = $sSQLiteExe_FilePath & $sSQLiteExeFilename
         
        EndIf
        
    EndIf
    If Not FileExists($sDatabaseFile) Then
        Local $hNewFile = FileOpen($sDatabaseFile, $FO_OVERWRITE + $FO_CREATEPATH)
        If $hNewFile = -1 Then
            Return SetError(1, 0, $SQLITE_CANTOPEN) ; Can't Create new Database
        EndIf
        FileClose($hNewFile)
    EndIf
    Local $sInputFile = _TempFile(), $sOutputFile = _TempFile(), $iRval = $SQLITE_OK
    Local $hInputFile = FileOpen($sInputFile, $FO_OVERWRITE)
    If $hInputFile > -1 Then
        $sInput = ".output stdout" & @CRLF & $sInput
        FileWrite($hInputFile, $sInput)
        FileClose($hInputFile)
        Local $sCmd = @ComSpec & " /c " & FileGetShortName($sSQLiteExeFilename) & '  "' _
                 & FileGetShortName($sDatabaseFile) _
                 & '" > "' & FileGetShortName($sOutputFile) _
                 & '" < "' & FileGetShortName($sInputFile) & '"'
                
        Local $nErrorLevel = RunWait($sCmd, @WorkingDir,@SW_HIDE)
        MsgBox(0,"",@error) ;error=0 $nErrorLevel=1
        If $bDebug = True Then
            Local $nErrorTemp = @error
            If @error Then __SQLite_Print('@@ Debug(_SQLite_SQLiteExe) : $sCmd = ' & $sCmd & @CRLF & '>ErrorLevel: ' & $nErrorLevel & @CRLF)
            SetError($nErrorTemp)
        EndIf
        MsgBox(0,"",$nErrorLevel)
        If @error = 1 Or $nErrorLevel = 1 Then 
            $iRval = $SQLITE_MISUSE ; SQLite.exe not found
        Else
            $sOutput = FileRead($sOutputFile, FileGetSize($sOutputFile))
            If StringInStr($sOutput, "SQL error:", 1) > 0 Or StringInStr($sOutput, "Incomplete SQL:", 1) > 0 Then 
                $iRval = $SQLITE_ERROR 
                ;MsgBox(0,"",$iRval); SQL error / Incomplete SQL
            EndIf
            EndIf
    Else
        $iRval = $SQLITE_CANTOPEN ; Can't open Input File
    EndIf
    If FileExists($sInputFile) Then FileDelete($sInputFile)
    Switch $iRval
        Case $SQLITE_MISUSE
            SetError(2)
            ;MsgBox(0,"",$sSQLiteExeFilename)
        Case $SQLITE_ERROR
            SetError(3)
        Case $SQLITE_CANTOPEN
            SetError(4)
    EndSwitch
    Return $iRval
EndFunc   ;==>_SQLite_SQLiteExe

I test the UDF _SQLite_SQLiteExe in  help file the result is" Can't Found sqlite3.exe" .  I find the reason is @error=0  but $nErrorLevel=1which return from RunWait(). why??

Edited by macran

Share this post


Link to post
Share on other sites



Did you #include the relevant *.au3 or did you just extract the function? Which version of AutoIt do you use?

Else, the simplest is to download the very latest version of sqlite3.exe (in ZIP file http://www.sqlite.org/2015/sqlite-shell-win32-x86-3080900.zip) from the official site and copy it to either a directory in path or something and run it from there with arguments or stdin command file.


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

some time it is ok ,some time it is error o:)  now it is ok

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