public static bool TryDatabaseOperation(string commandText) { Match match = _regExIsCreateOrDropDatabaseCommand.Match(commandText); if (!match.Success) { return(false); } match = _regExParseCreateDatabaseCommandFromConnection.Match(commandText); if (match.Success) { AdoxWrapper.CreateEmptyDatabase(match.Groups["connectionString"].Value); return(true); } match = _regExParseCreateDatabaseCommand.Match(commandText); if (match.Success) { string fileName = match.Groups["filename"].Value; if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("Missing file name"); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString(fileName)); return(true); } match = _regExParseDropDatabaseCommandFromConnection.Match(commandText); if (match.Success) { string fileName; string connectionString = match.Groups["connectionString"].Value; fileName = ExtractFileNameFromConnectionString(connectionString); if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("Missing file name"); } DeleteFile(fileName.Trim()); return(true); } match = _regExParseDropDatabaseCommand.Match(commandText); if (match.Success) { string fileName = match.Groups["filename"].Value; if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("Missing file name"); } DeleteFile(fileName.Trim()); return(true); } throw new Exception(commandText + " is not a valid database command"); }
public void RenameColumnQuery() { try { JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); } catch (Exception e) { Console.WriteLine(e); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb")); using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb"))) { connection.Open(); CreateTable(connection); CheckColumnExists(connection, "tableName", "columnName"); connection.CreateCommand("rename column tableName.columnName to newColumnName").ExecuteNonQuery(); connection.Close(); JetConnection.ClearAllPools(); connection.Open(); CheckColumnExists(connection, "tableName", "newColumnName"); } JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); }
//[TestMethod] public void RenameIndexAdox() { try { JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); } catch (Exception e) { Console.WriteLine(e); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb")); using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb"))) { connection.Open(); CreateTable(connection); CheckIndexExists(connection, "indexName"); AdoxWrapper.RenameIndex(JetConnection.GetConnectionString("AdoxTest.accdb"), "tableName", "indexName", "newIndexName"); connection.Close(); connection.Open(); CheckIndexExists(connection, "newIndexName"); } JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); }
public void Initialize() { // ReSharper disable once AssignNullToNotNullAttribute _scriptPath = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "Northwind.sql"); JetConnection.DropDatabase(JetConnection.GetConnectionString(DatabaseName), false); AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString(DatabaseName)); _connection = new JetConnection(JetConnection.GetConnectionString(DatabaseName)); _connection.Open(); }
public void CreateDatabase() { try { JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); } catch (Exception e) { Console.WriteLine(e); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb")); JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); }