void CreateNewDatabaseFromDialogOrExit() { MessageBoxResult messageResult = MessageBox.Show("SQLite database not attached. Would you like to attach an existing database? (Clicking \"No\" will prompt to create a new database.)", "Attach Database", MessageBoxButton.YesNo); if (messageResult == MessageBoxResult.Yes) { OpenFileDialog dialog = new OpenFileDialog { Title = "Open SQLite Database", Filter = "SQLite Database|*.sqlite3", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; if (dialog.ShowDialog() == true) { Settings.Default.AttachedDatabase = dialog.FileName; Settings.Default.Save(); if (FileIsSQLiteDatabase() == false) { Settings.Default.AttachedDatabase = string.Empty; Settings.Default.Save(); MessageBox.Show("Selected file is not an SQLite database. A database is require for program operation. Program will now exit.", "Failed to Create Database", MessageBoxButton.OK, MessageBoxImage.Error); Current.Shutdown(1); Environment.Exit(1); } } } if (messageResult == MessageBoxResult.No) { SaveFileDialog databaseDialog = new SaveFileDialog { Title = "Create New SQLite Database", Filter = "SQLite Database|*.sqlite3", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; databaseDialog.ShowDialog(); if (!string.IsNullOrEmpty(databaseDialog.FileName)) { SQLiteDatabaseInstaller installer = new SQLiteDatabaseInstaller { DatabaseFile = databaseDialog.FileName, ConnectionString = string.Format("Data Source={0};Version=3;", databaseDialog.FileName) }; installer.CreateNewDatabase(); Settings.Default.AttachedDatabase = databaseDialog.FileName; Settings.Default.Save(); return; } MessageBox.Show("No database filename was given. A database is require for program operation. Program will now exit.", "Failed to Create Database", MessageBoxButton.OK, MessageBoxImage.Error); Current.Shutdown(1); Environment.Exit(1); } }
public void SetUp() { temporaryDatabaseFile = Path.GetTempPath() + "temp_database.sqlite3"; installer = new SQLiteDatabaseInstaller { DatabaseFile = temporaryDatabaseFile, ConnectionString = string.Format("Data Source={0};Version=3;New=True;", temporaryDatabaseFile) }; }
public SQLiteDatabaseHelper() { string databaseFile = Path.GetTempPath() + "temp_database.sqlite3"; string connectionString = string.Format("Data Source={0};Version=3;", databaseFile); installer = new SQLiteDatabaseInstaller { DatabaseFile = databaseFile, ConnectionString = connectionString }; }
private static SQLiteStoreContext GetEmptySQLiteStore(string destination) { installer = new SQLiteDatabaseInstaller { DatabaseFile = destination, ConnectionString = string.Format("Data Source={0};Version=3;", destination) }; installer.CreateNewDatabase(); SQLiteStoreContext context = new SQLiteStoreContext(destination); return(context); }