Public Sub InitSQLite(SQLRef As SQL, tmpDBLocation As String, DBName As String, FasterWrites As Boolean) As Boolean 'As ResumableSub
Try
Dim DBExists As Boolean = File.Exists(tmpDBLocation, DBName)
If DBExists Then
Dim fsize As Long = File.Size(tmpDBLocation, DBName)
If fsize < 1024 Then Log("⚠️ Warning: DB file is very small, might be corrupted.")
End If
SQLRef.InitializeSQLite(tmpDBLocation, DBName, Not(DBExists)) 'If true we have the DB so make it false no new table
SQLRef.ExecNonQuery("PRAGMA journal_mode = WAL") ' Enable Write-Ahead Logging for concurrency
SQLRef.ExecNonQuery("PRAGMA busy_timeout = 3000") ' Allow 3s wait if DB is locked
If FasterWrites = True Then
SQLRef.ExecNonQuery("PRAGMA synchronous = NORMAL")
Log("SQLite: Using FAST write mode (synchronous=NORMAL)")
Else
SQLRef.ExecNonQuery("PRAGMA synchronous = FULL")
Log("SQLite: Using SAFE write mode (synchronous=FULL)")
End If
Return True
Catch
modFunctions.ShowLog("Error: Database is corrupt", True, LastException.Message)
Return False
End Try
End Sub