@Override
  public boolean databaseExists(SnowflakeIdentifier database) {
    Preconditions.checkArgument(
        database.type() == SnowflakeIdentifier.Type.DATABASE,
        "databaseExists requires a DATABASE identifier, got '%s'",
        database);

    final String finalQuery = "SHOW SCHEMAS IN DATABASE IDENTIFIER(?) LIMIT 1";

    List<SnowflakeIdentifier> schemas;
    try {
      schemas =
          connectionPool.run(
              conn ->
                  queryHarness.query(
                      conn, finalQuery, SCHEMA_RESULT_SET_HANDLER, database.databaseName()));
    } catch (SQLException e) {
      if (DATABASE_NOT_FOUND_ERROR_CODES.contains(e.getErrorCode())) {
        return false;
      }
      throw new UncheckedSQLException(e, "Failed to check if database '%s' exists", database);
    } catch (InterruptedException e) {
      throw new UncheckedInterruptedException(
          e, "Interrupted while checking if database '%s' exists", database);
    }

    return !schemas.isEmpty();
  }
@Test
  public void testDatabaseDoesntExist() throws SQLException {
    when(mockResultSet.next())
        .thenThrow(new SQLException("Database does not exist", "2000", 2003, null))
        .thenThrow(
            new SQLException(
                "Database does not exist, or operation cannot be performed", "2000", 2043, null))
        .thenThrow(
            new SQLException("Database does not exist or not authorized", "2000", 2001, null));

    // Error code 2003
    assertThat(snowflakeClient.databaseExists(SnowflakeIdentifier.ofDatabase("DB_1"))).isFalse();

    // Error code 2043
    assertThat(snowflakeClient.databaseExists(SnowflakeIdentifier.ofDatabase("DB_1"))).isFalse();

    // Error code 2001
    assertThat(snowflakeClient.databaseExists(SnowflakeIdentifier.ofDatabase("DB_1"))).isFalse();
  }