示例#1
0
        private void TryCreateTestDatabaseAndTestUser()
        {
            try
            {
                CreateTestDatabaseAndTestUser();
            }
            catch (PostgresException e)
            {
                switch (e.SqlState)
                {
                // duplicate_database (see https://www.postgresql.org/docs/8.2/errcodes-appendix.html)
                case "42P04":
                    DropTestDatabaseAndTestUser();
                    CreateTestDatabaseAndTestUser();
                    break;

                // duplicate_object  (see https://www.postgresql.org/docs/8.2/errcodes-appendix.html)
                case "42710":
                    DefaultConnection.Execute(Configuration.DropTestUserCommand);
                    CreateTestDatabaseAndTestUser();
                    break;

                default:
                    throw;
                }
            }
            DefaultConnection.ChangeDatabase(Configuration.TestDatabase);
        }