DaLiMan Posted September 15, 2017 Posted September 15, 2017 Hi, I'm trying to create an SQLite database. After Importing 2 csv files I'm creating a new tabel and trying to export this table to a new file. Now I think I'm pretty close, but the code seems buggy. It's telling (50% of the time) me sqlite3.exe is not found. Yet, it absolutely exist in the @scriptdir. Please help? expandcollapse popup#include <File.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <StringConstants.au3> ; Filenames Local $sTsvFile_new = FileGetShortName(@DesktopDir & "\HGSwijzgingen_new.csv") Local $sTsvFile_oud = FileGetShortName(@DesktopDir & "\HGSwijzgingen_oud.csv") Local $sDbFile = @ScriptDir & "\ArtLev.db" FileDelete($sDbFile) ; == CREATE Table NEW == ; import (using SQLite3.exe) Local $sIn, $sOut, $i, $sCreate = "CREATE TABLE TblImportNEW ("; For $i = 1 To _StringCountOccurance(FileReadLine($sTsvFile_new, 1), ";") + 1 $sCreate &= "Column_" & $i & "," Next $sCreate = StringTrimRight($sCreate, 1) & ");" $sIn = $sCreate & @CRLF ; Create Table $sIn &= ".separator \;" & @CRLF ; Select @TAB as Separator $sIn &= ".import '" & $sTsvFile_new & "' TblImportNEW" & @CRLF _SQLite_SQLiteExe($sDbFile, $sIn, $sOut, -1, True) ; == CREATE Table OUD == ; import (using SQLite3.exe) Local $sIn, $sOut, $i, $sCreate = "CREATE TABLE TblImportOUD ("; For $i = 1 To _StringCountOccurance(FileReadLine($sTsvFile_oud, 1), ";") + 1 $sCreate &= "Column_" & $i & "," Next $sCreate = StringTrimRight($sCreate, 1) & ");" $sIn = $sCreate & @CRLF ; Create Table $sIn &= ".separator \;" & @CRLF ; Select @TAB as Separator $sIn &= ".import '" & $sTsvFile_oud & "' TblImportOUD" & @CRLF _SQLite_SQLiteExe($sDbFile, $sIn, $sOut, -1, True) ; == JOIN QUERY SQLite == Dim $hQuery Dim $SQlite_Qry = 'CREATE Table HGSwijzigingen AS SELECT TblImportNEW.Column_1 AS "ART", TblImportNEW.Column_2 AS "OMSCHRIJVING", TblImportNEW.Column_3 AS "NEW", TblImportOUD.Column_3 AS "OLD" FROM TblImportNEW LEFT JOIN TblImportOUD ON TblImportNEW.Column_1 = TblImportOUD.Column_1 WHERE TblImportOUD.Column_3 <> TblImportNEW.Column_3;' _SQLite_SQLiteExe($sDbFile, $SQlite_Qry, $sOut, -1, True) ; CREATE JOIN Table and import as Array for export to file. If @error = 0 Then ;Show Table (using SQLite3.dll) Local $iRows, $iColumns, $aRes _SQLite_Startup() ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open($sDbFile) _SQLite_GetTable2d(-1, "SELECT ROWID,* FROM TblImportNEW WHERE Column_1 = '9899820';", $aRes, $iRows, $iColumns) _SQLite_Display2DResult($aRes) ; Output to Console _SQLite_GetTable2d(-1, "SELECT * FROM HGSwijzigingen';", $aRes, $iRows, $iColumns) _ArrayDisplay($aRes) _SQLite_Close() _SQLite_Shutdown() Else If @error = 2 Then ConsoleWrite("ERROR: Sqlite3.exe file not found" & @CRLF) Else ConsoleWrite("ERROR: @error=" & @error & " when calling _SQLite_SQLiteExe" & @CRLF) EndIf EndIf Func _StringCountOccurance($sSearchString, $sSubString, $iCaseSense = $STR_NOCASESENSE) ; Returns Number of $sSubString in $sSearchString Local $iOccCnt = 1 Do If StringInStr($sSearchString, $sSubString, $iCaseSense, $iOccCnt) > 0 Then $iOccCnt += 1 Else ExitLoop EndIf Until 0 Return $iOccCnt - 1 EndFunc ;==>_StringCountOccurance >"C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install\SciTE4AutoIt3_Portable\..\AutoIt3.exe" "C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install\SciTE4AutoIt3_Portable\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\T12037\OneDrive - SONEPAR\Scripts\SQLite\SQLite_SQLiteExe_v1.0.au3" /UserParams +>10:58:22 Starting AutoIt3Wrapper v.16.306.1237.0 SciTE v.3.6.2.0 Keyboard:00020409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0413) CodePage:0 utf8.auto.check:4 # detect ascii high characters and if none found set default encoding to UTF8 and do not add BOM +> SciTEDir => C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install\SciTE4AutoIt3_Portable UserDir => C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install\SciTE4AutoIt3_Portable\AutoIt3Wrapper >Running AU3Check (3.3.14.2) from:C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install input:C:\Users\T12037\OneDrive - SONEPAR\Scripts\SQLite\SQLite_SQLiteExe_v1.0.au3 +>10:58:22 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Users\T12037\OneDrive - SONEPAR\PortableApps\AutoIt\install\autoit3_x64.exe "C:\Users\T12037\OneDrive - SONEPAR\Scripts\SQLite\SQLite_SQLiteExe_v1.0.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop ERROR: Sqlite3.exe file not found +>10:58:40 AutoIt3.exe ended.rc:0 +>10:58:40 AutoIt3Wrapper Finished. >Exit code: 0 Time: 18.96
FrancescoDiMuro Posted September 15, 2017 Posted September 15, 2017 (edited) Did you try to remove the #include <SQLite.dll.au3> , using the path of the sqlite3.exe ( in your current @ScriptDir ) as parameter when you call _SQLite_SQLiteExe() function, downloadable from here? Edited September 15, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
DaLiMan Posted September 15, 2017 Author Posted September 15, 2017 I don't think that's the answer for me. It seems like the first ** CREATE TABLE ** works fine, after that the code crashes. Maybe it's locking the SQLite3.exe so it can't be used / called again?
Developers Jos Posted September 15, 2017 Developers Posted September 15, 2017 I see in the name you are using a OneDrive directory. Could that be re reason it is giving issues where OneDrive is locking files? Also see you are running the X64 version of AutoIt3, maybe something to try and run the x86 version? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
DaLiMan Posted September 15, 2017 Author Posted September 15, 2017 Jos, looks like ONEDRIVE is the problem here. Changing the output to C:\ has given me no errors except when de original SQLite.db already exists. So it seems ONEDRIVE is just to slow to keep up. Thanx!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now