#include <SQLite.au3>
#include <SQLite.batch.au3>
If Not FileExists(@ScriptDir & "\sqlite3.dll") then FileInstall("sqlite3.dll", @ScriptDir & "\sqlite3.dll")
_SQLite_Startup(@ScriptDir & "\sqlite3.dll", Default, 1)
Global $hDB = _SQLite_Open(@ScriptDir & '\ex.sqlite')
$TableName = 'TestTable'
_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS '" & $TableName & "' (Datestamp string, Counter1 int, Counter2 double, Data blob);")
Local $Data[100000][5]
For $i = 0 to 99999
$Data[$i][0] = "teststring"
$Data[$i][1] = $i*2
$Data[$i][2] = $i/3
$Data[$i][3] = Binary("This is string in BLOB with 3 trailing zeroes." & Chr(0) & Chr(0) & Chr(0))
Next
$hQuery = 0
;----------------------------------------------------------------------------------------------
$t = TimerInit()
_SQLite_Exec(-1, 'BEGIN TRANSACTION;')
_SQLite_Query(-1, "INSERT INTO '" & $TableName & "' VALUES (?, ?, ?, ?);",$hQuery)
For $i = 0 To UBound($Data)-1
_SQLite_BindText($hQuery, 1, $Data[$i][0])
_SQLite_BindInt($hQuery, 2, $Data[$i][1])
_SQLite_BindDouble($hQuery, 3, $Data[$i][2])
_SQLite_BindBlob($hQuery, 4, $Data[$i][3])
_SQLite_Step($hQuery)
_SQLite_ClearBindings($hQuery)
_SQLite_QueryReset($hQuery)
Next
_SQLite_QueryFinalize($hQuery)
_SQLite_Exec(-1, 'END TRANSACTION;')
$dt1 = TimerDiff($t)
;----------------------------------------------------------------------------------------------
_SQLite_Exec(-1, "DROP TABLE IF EXISTS '" & $TableName & "';")
_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS '" & $TableName & "' (Datestamp string, Counter1 int, Counter2 double, Data blob);")
;----------------------------------------------------------------------------------------------
$t = TimerInit()
_FillTableEX()
$dt2 = TimerDiff($t)
;----------------------------------------------------------------------------------------------
MsgBox(64,"","Bind-insert = " & @TAB & Round($dt1) & " ms" & @crlf & "Chain-insert = " & @TAB & Round($dt2) & " ms" & @crlf & "Bind / Chain = " & @TAB & Round($dt1/$dt2*100,2) & " %")
_SQLite_Close()
_SQLite_Shutdown()
Func _FillTableEX()
Local $sSqlBuild_Query = "", $k = 0, $iCount = UBound($Data), $n = Int($iCount/100)
For $i = 0 To $iCount-1 Step $n
$k = (($i+$n) > $iCount) ? ($iCount-$i-2) : ($n-2)
$sSqlBuild_Query &= "INSERT INTO '" & $TableName & "' (Datestamp, Counter1, Counter2, Data) VALUES "
For $j = 0 To $k
$sSqlBuild_Query &= "('" & StringReplace( $Data[$i+$j][0], "'", "''") & "'"
$sSqlBuild_Query &= "," & $Data[$i+$j][1]
$sSqlBuild_Query &= "," & $Data[$i+$j][2]
$sSqlBuild_Query &= ",'" & $Data[$i+$j][3] & "'),"
Next
$sSqlBuild_Query &= "('" & StringReplace( $Data[$i+$j][0], "'", "''") & "'"
$sSqlBuild_Query &= "," & $Data[$i+$k+1][1]
$sSqlBuild_Query &= "," & $Data[$i+$k+1][2]
$sSqlBuild_Query &= ",'" & $Data[$i+$k+1][3] & "');"
Next
_SQLite_Exec(-1, $sSqlBuild_Query )
EndFunc