Beispiel #1
0
        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 static bool TryDatabaseOperation(string connectionString, string commandText)
        {
            var match = _renameTableRegex.Match(commandText);

            if (match.Success)
            {
                var oldTableName = match.Groups["OldTableName"].Value;
                var newTableName = match.Groups["NewTableName"].Value;

                // TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context.
                AdoxWrapper.RenameTable(connectionString, oldTableName, newTableName);

                return(true);
            }

            match = _renameTableColumnRegex.Match(commandText);
            if (match.Success)
            {
                var tableName     = match.Groups["TableName"].Value;
                var oldColumnName = match.Groups["OldColumnName"].Value;
                var newColumnName = match.Groups["NewColumnName"].Value;

                // TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context.
                AdoxWrapper.RenameColumn(connectionString, tableName, oldColumnName, newColumnName);

                return(true);
            }

            return(false);
        }
        //[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 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");
        }
Beispiel #5
0
        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");
        }
        public static bool TryDatabaseOperation(string connectionString, string commandText)
        {
            Match match;


            match = _renameTableRegex.Match(commandText);
            if (match.Success)
            {
                string tableName    = match.Groups["tableName"].Value;
                string newTableName = match.Groups["newTableName"].Value;
                AdoxWrapper.RenameTable(connectionString, RemoveBrackets(tableName), RemoveBrackets(newTableName));
                return(true);
            }

            match = _renameTableColumnRegex.Match(commandText);
            if (match.Success)
            {
                string tableName     = match.Groups["tableName"].Value;
                string columnName    = match.Groups["columnName"].Value;
                string newColumnName = match.Groups["newColumnName"].Value;
                AdoxWrapper.RenameColumn(connectionString, RemoveBrackets(tableName), RemoveBrackets(columnName), RemoveBrackets(newColumnName));
                return(true);
            }

            match = _renameTableIndexRegex.Match(commandText);
            if (match.Success)
            {
                string tableName    = match.Groups["tableName"].Value;
                string indexName    = match.Groups["indexName"].Value;
                string newIndexName = match.Groups["newIndexName"].Value;
                AdoxWrapper.RenameIndex(connectionString, RemoveBrackets(tableName), RemoveBrackets(indexName), RemoveBrackets(newIndexName));
                return(true);
            }


            return(false);
        }
 public void RenameColumnAdox()
 {
     AdoxWrapper.RenameColumn(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory), "tableName", "columnName", "newColumnName");
     ReOpenConnection();
     CheckColumnExists("tableName", "newColumnName");
 }
 public void RenameTableAdox()
 {
     AdoxWrapper.RenameTable(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory), "tableName", "newTableName");
     ReOpenConnection();
     CheckTableExists("newTableName");
 }