public GamesRepository() { bool buildSchema = false; if (!File.Exists(DatabaseFile)) { Directory.CreateDirectory(DatabasePath); SQLiteConnection.CreateFile(DatabaseFile); buildSchema = true; } DatabaseConnection = new SQLiteConnection(ConString); DatabaseConnection.Open(); using (SQLiteCommand com = DatabaseConnection.CreateCommand()) { com.CommandText = "PRAGMA automatic_index=FALSE; PRAGMA synchronous=OFF; PRAGMA auto_vacuum=INCREMENTAL; PRAGMA foreign_keys=ON; PRAGMA encoding='UTF-8';"; com.ExecuteScalar(); } if (buildSchema) { using (SQLiteCommand com = DatabaseConnection.CreateCommand()) { string md = Resource1.MakeDatabase; com.CommandText = md; com.ExecuteNonQuery(); } } using (SQLiteCommand com = DatabaseConnection.CreateCommand()) { UpdateDatabase.Update(DatabaseConnection); } }
internal static void MakeEmptyStructure(SQLiteConnection connection) { using (SQLiteCommand com = connection.CreateCommand()) { string md = Resource1.MakeDatabase; md = md.Replace("begin transaction;", ""); md = md.Replace("commit transaction;", ""); com.CommandText = md; com.ExecuteNonQuery(); } UpdateDatabase.Update(connection); }