Skip to content

Commit

Permalink
MONDRIAN: Rename Dialect.requiresAliasForFromItems to requiresAliasFo…
Browse files Browse the repository at this point in the history
…rFromQuery, and test it.

    Fix DialectTest for PostgreSQL 8.2.

[git-p4: depot-paths = "//open/mondrian/": change = 9290]
  • Loading branch information
julianhyde committed May 20, 2007
1 parent 0ce2358 commit e3a0d48
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
13 changes: 10 additions & 3 deletions src/main/mondrian/rolap/sql/SqlQuery.java
Expand Up @@ -1111,9 +1111,16 @@ public boolean isTeradata() {
return productName.toUpperCase().indexOf("TERADATA") >= 0;
}

// -- behaviors --
protected boolean requiresAliasForFromItems() {
return isPostgres();
/**
* Returns whether this Dialect requires subqueries in the FROM clause
* to have an alias.
*
* @see #allowsFromQuery()
*/
public boolean requiresAliasForFromQuery() {
return isMySQL() ||
isDerby() ||
isPostgres();
}

/**
Expand Down
45 changes: 28 additions & 17 deletions testsrc/main/mondrian/test/DialectTest.java
Expand Up @@ -99,7 +99,9 @@ public void testAllowsCompoundCountDistinct() {
// derby
"Syntax error: Encountered \",\" at line 1, column 36.",
// access
"\\[Microsoft\\]\\[ODBC Microsoft Access Driver\\] Syntax error \\(missing operator\\) in query expression '.*'."
"\\[Microsoft\\]\\[ODBC Microsoft Access Driver\\] Syntax error \\(missing operator\\) in query expression '.*'.",
// postgres
"ERROR: function count\\(integer, integer\\) does not exist"
};
assertQueryFails(sql, errs);
}
Expand Down Expand Up @@ -185,27 +187,36 @@ public void testAllowsFromQuery() {
dialectize("select * from (select * from [sales_fact_1997]) as [x]");
if (getDialect().allowsFromQuery()) {
assertQuerySucceeds(sql);

// As above, but no alias.
String sql2 =
dialectize("select * from (select * from [sales_fact_1997])");
if (getDialect().isMySQL() ||
getDialect().isDerby()) {
String[] errs = {
// mysql
"Every derived table must have its own alias",
// derby
"Syntax error: Encountered \"<EOF>\" at line 1, column 47."
};
assertQueryFails(sql2, errs);
} else {
assertQuerySucceeds(sql2);
}
} else {
assertQueryFails(sql, new String[] {});
}
}

public void testRequiresFromQueryAlias() {
if (getDialect().requiresAliasForFromQuery()) {
assertTrue(getDialect().allowsFromQuery());
}
if (!getDialect().allowsFromQuery()) {
return;
}

String sql =
dialectize("select * from (select * from [sales_fact_1997])");
if (getDialect().requiresAliasForFromQuery()) {
String[] errs = {
// mysql
"Every derived table must have its own alias",
// derby
"Syntax error: Encountered \"<EOF>\" at line 1, column 47.",
// postgres
"ERROR: subquery in FROM must have an alias"
};
assertQueryFails(sql, errs);
} else {
assertQuerySucceeds(sql);
}
}

public void testRequiresOrderByAlias() {
String sql =
dialectize("SELECT [unit_sales]\n" +
Expand Down

0 comments on commit e3a0d48

Please sign in to comment.