private void CreateOrOpenDatabase()
{
lock (_lock)
{
this.DBfileFullPath = System.IO.Path.Combine(AmazonHookedPlatformInfo.Instance.PersistentDataPath, dbFileName);
string vacuumCommand = "PRAGMA auto_vacuum = 1";
string sqlCommand = string.Format(CultureInfo.InvariantCulture, "CREATE TABLE IF NOT EXISTS {0} ({1} TEXT NOT NULL,{2} TEXT NOT NULL UNIQUE,{3} TEXT NOT NULL, {4} INTEGER NOT NULL DEFAULT 0 )",
TABLE_NAME, EVENT_COLUMN_NAME, EVENT_ID_COLUMN_NAME, MA_APP_ID_COLUMN_NAME, EVENT_DELIVERY_ATTEMPT_COUNT_COLUMN_NAME);
if (!File.Exists(this.DBfileFullPath))
{
string directory = Path.GetDirectoryName(this.DBfileFullPath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
SqliteConnection.CreateFile(this.DBfileFullPath);
}
try
{
connection = new SqliteConnection("URI=file:" + this.DBfileFullPath);
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = vacuumCommand;
command.ExecuteNonQuery();
}
using (var command = connection.CreateCommand())
{
command.CommandText = sqlCommand;
command.ExecuteNonQuery();
}
}
finally
{
if (connection != null)
{
connection.Close();
connection.Dispose();
}
}
}
}