/// <summary> /// Writes data toa a schema version 1 type database. /// </summary> /// <param name="dbConnection"> /// Open database connection. /// </param> private void StoreDatabaseSchemaV1(SQLiteConnection dbConnection) { SQLiteDataAccess_v1 dataAccess = new SQLiteDataAccess_v1(dbConnection); AddUpdateDeleteSorter <AttributeTypeDTO> sorter = new AddUpdateDeleteSorter <AttributeTypeDTO>(this.mAttributeDataTypes); dataAccess.AddUpdateDelete_AttributeTypes(sorter.AddedRecords, sorter.ModifiedRecords, sorter.DeletedRecords); PostSaveUpdateAndRemove(this.mAttributeDataTypes); }
/// <summary> /// Create a new database and store the data. /// </summary> /// <param name="documentFilePath"> /// Path to the output file. /// </param> private void SaveNewDocument(String documentFilePath) { // Delete existing files before creating the new file. if (File.Exists(documentFilePath)) { File.Delete(documentFilePath); } SQLiteConnection.CreateFile(documentFilePath); String connectionString = $"Data Source={documentFilePath}; Version=3;"; using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteTransaction dbTransaction = dbConnection.BeginTransaction(); try { // Create the MetaDataTable table using (SQLiteCommand createCommand = dbConnection.CreateCommand()) { createCommand.CommandText = SQLite_CreateMetaDataTable; createCommand.CommandType = CommandType.Text; createCommand.ExecuteNonQuery(); } // Create the AttributeTypes table using (SQLiteCommand createCommand = dbConnection.CreateCommand()) { createCommand.CommandText = SQLite_CreateAttributeTypes; createCommand.CommandType = CommandType.Text; createCommand.ExecuteNonQuery(); } // Store the database schema version number using (SQLiteCommand createCommand = dbConnection.CreateCommand()) { createCommand.CommandText = SQLite_Insert_MetaData_DatabaseSchemaVersion; createCommand.CommandType = CommandType.Text; createCommand.ExecuteNonQuery(); } SQLiteDataAccess_v1 writer = new SQLiteDataAccess_v1(dbConnection); List <AttributeTypeDTO> attributeTypesList = this.mAttributeDataTypes.ConvertAll <AttributeTypeDTO>(u => u.Data); writer.AddUpdateDelete_AttributeTypes(attributeTypesList, null, null); dbTransaction.Commit(); this.IsModified = false; this.mDocumentPath = documentFilePath; } catch { dbTransaction.Rollback(); throw; } } }
/// <summary> /// Reads data from a schema version 1 type database. /// </summary> /// <param name="dbConnection"> /// Open database connection. /// </param> private void ReadDatabaseSchemeV1(SQLiteConnection dbConnection) { SQLiteDataAccess_v1 dataAccess = new SQLiteDataAccess_v1(dbConnection); // Read attribute types from the database. this.mAttributeDataTypes.Clear(); foreach (AttributeTypeDTO attributeType in dataAccess.FetchAttributeTypes()) { this.mAttributeDataTypes.Add(new DataStorageItem <AttributeTypeDTO>(attributeType)); } }