Skip to content

Commit

Permalink
MONDRIAN: Fix generation of ORDER BY clause for Ingres. Contributed b…
Browse files Browse the repository at this point in the history
…y Andy Grimm. Ingres now passes the regression suite, I believe.

[git-p4: depot-paths = "//open/mondrian/": change = 8336]
  • Loading branch information
julianhyde committed Dec 13, 2006
1 parent 3a8e511 commit cb591d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/mondrian/rolap/RolapNativeTopCount.java
Expand Up @@ -54,7 +54,7 @@ protected boolean isJoinRequired() {
public void addConstraint(SqlQuery sqlQuery) {
if (orderByExpr != null) {
Dialect dialect = sqlQuery.getDialect();
if (dialect.isMySQL() || dialect.isDB2()) {
if (dialect.requiresOrderByAlias()) {
String alias = sqlQuery.nextColumnAlias();
alias = dialect.quoteIdentifier(alias);
sqlQuery.addSelect(orderByExpr, alias);
Expand Down
37 changes: 34 additions & 3 deletions src/main/mondrian/rolap/sql/SqlQuery.java
Expand Up @@ -180,7 +180,10 @@ public void setDistinct(final boolean distinct) {
private static final int DOUBLE_QUOTE_SIZE = 2 * SINGLE_QUOTE_SIZE + 1;

/**
*
* Adds a subquery to the FROM clause of this Query with a given alias.
* If the query already exists it either, depending on
* <code>failIfExists</code>, throws an exception or does not add the query
* and returns false.
*
* @param query
* @param alias (if not null, must not be zero length).
Expand Down Expand Up @@ -1051,12 +1054,14 @@ public String generateInline(
List<String[]> valueList) {
if (isOracle()) {
return generateInlineGeneric(
columnNames, columnTypes, valueList, "from dual");
columnNames, columnTypes, valueList,
"from dual");
} else if (isAccess()) {
// Fall back to using the FoodMart 'days' table, because
// Access SQL has no way to generate values not from a table.
return generateInlineGeneric(
columnNames, columnTypes, valueList, "from [days] where [day] = 1");
columnNames, columnTypes, valueList,
"from [days] where [day] = 1");
} else if (isMySQL()) {
return generateInlineGeneric(
columnNames, columnTypes, valueList, null);
Expand Down Expand Up @@ -1272,6 +1277,32 @@ public String forceNullsCollateLast(String expr) {
public boolean supportsGroupByExpressions() {
return !(isDerby() || isCloudscape());
}

/**
* Returns true if this Dialect can include expressions in the ORDER BY
* clause only by adding an expression to the SELECT clause and using
* its alias.
*
* <p>For example, in such a dialect,
* <blockquote>
* <code>SELECT x FROM t ORDER BY x + y</code>
* </blockquote>
* would be illegal, but
* <blockquote>
* <code>SELECT x, x + y AS z FROM t ORDER BY z</code>
* </blockquote>
*
* would be legal.</p>
*
* <p>MySQL, DB2 and Ingres are examples of such dialects.</p>
*
* @return Whether this Dialect can include expressions in the ORDER BY
* clause only by adding an expression to the SELECT clause and using
* its alias
*/
public boolean requiresOrderByAlias() {
return isMySQL() || isDB2() || isIngres();
}
}

/**
Expand Down

0 comments on commit cb591d0

Please sign in to comment.