Skip to content

Commit

Permalink
MONDRIAN: Sybase support.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 2779]
  • Loading branch information
julianhyde committed Oct 20, 2004
1 parent 252aac9 commit e2a0798
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
51 changes: 37 additions & 14 deletions src/main/mondrian/rolap/SqlMemberSource.java
Expand Up @@ -189,36 +189,58 @@ private String makeLevelMemberCountSql(RolapLevel level,
return sqlQuery.toString();
}
if (!sqlQuery.allowsFromQuery()) {
// "select count(distinct c1, c2) from table"
String columnList = "";
int columnCount = 0;
for (int i = levelDepth; i >= 0; i--) {
RolapLevel level2 = levels[i];
if (level2.isAll()) {
continue;
}
if (columnList.length() > 0) {
// for databases where both SELECT-in-FROM and COUNT DISTINCT do not work,
// we do not generate any count and do the count distinct "manually".
if (!sqlQuery.allowsCompoundCountDistinct())
if (columnCount > 0) {
if (sqlQuery.allowsCompoundCountDistinct()) {
columnList += ", ";
} else if (true) {
// for databases where both SELECT-in-FROM and
// COUNT DISTINCT do not work, we do not
// generate any count and do the count
// distinct "manually".
mustCount[0] = true;
/*
if (!sqlQuery.allowsCompoundCountDistinct()) {
// I don't know know of a database where this would
// happen. MySQL does not allow SELECT-in-FROM, but it
// does allow compound COUNT DISTINCT.
} else if (sqlQuery.isSybase()) {
// "select count(distinct convert(varchar, c1) +
// convert(varchar, c2)) from table"
if (columnCount == 1) {
// Conversion to varchar is expensive, so we only
// do it when we know we are dealing with a
// compound key.
columnList = "convert(varchar, " + columnList + ")";
}
columnList += " + ";
} else {
// Apparently this database allows neither
// SELECT-in-FROM nor compound COUNT DISTINCT. I don't
// know any database where this happens. If you receive
// this error, try a workaround similar to the Sybase
// workaround above.
throw Util.newInternal(
"Cannot generate query to count members of level '" +
level.getUniqueName() +
"': database supports neither SELECT-in-FROM nor compound COUNT DISTINCT");
}
*/
columnList += ", ";
}
hierarchy.addToFrom(sqlQuery, level2.keyExp, null);
columnList += level2.keyExp.getExpression(sqlQuery);

String keyExp = level2.keyExp.getExpression(sqlQuery);
if (columnCount > 0 &&
!sqlQuery.allowsCompoundCountDistinct() &&
sqlQuery.isSybase()) {
keyExp = "convert(varchar, " + columnList + ")";
}
columnList += keyExp;

if (level2.unique) {
break; // no further qualification needed
}
++columnCount;
}
if (mustCount[0]) {
sqlQuery.addSelect(columnList);
Expand Down Expand Up @@ -660,7 +682,8 @@ public void getMemberChildren(RolapMember parentMember, List children)
}
}

private void getMemberChildren(RolapMember parentMember, List children, Connection jdbcConnection) {
private void getMemberChildren(RolapMember parentMember, List children,
Connection jdbcConnection) {
String sql;
boolean parentChild;
final RolapLevel parentLevel = (RolapLevel) parentMember.getLevel();
Expand Down
26 changes: 14 additions & 12 deletions src/main/mondrian/rolap/sql/SqlQuery.java
Expand Up @@ -197,6 +197,9 @@ private String getProductVersion() {
}


public boolean isAccess() {
return getProduct().equals("ACCESS");
}
public boolean isDB2() {
// DB2 on NT returns "DB2/NT"
return getProduct().startsWith("DB2");
Expand Down Expand Up @@ -227,40 +230,39 @@ public boolean isOldAS400() {
}


public boolean isOracle() {
return getProduct().equals("Oracle");
public boolean isInformix() {
return getProduct().startsWith("Informix");
}
public boolean isMSSql() {
return getProduct().equalsIgnoreCase("Microsoft SQL Server");
}
public boolean isAccess() {
return getProduct().equals("ACCESS");
public boolean isMSSQL() {
return getProduct().toUpperCase().indexOf("SQL SERVER") >= 0;
}
public boolean isOracle() {
return getProduct().equals("Oracle");
}
public boolean isPostgres() {
return getProduct().toUpperCase().indexOf("POSTGRE") >= 0;
}
public boolean isMSSQL() {
return getProduct().toUpperCase().indexOf("SQL SERVER") >= 0;
}
public boolean isMySQL() {
return getProduct().toUpperCase().equals("MYSQL");
}
public boolean isInformix() {
return getProduct().startsWith("Informix");
public boolean isSybase() {
return getProduct().toUpperCase().indexOf("SYBASE") >= 0;
}


// -- behaviors --
protected boolean requiresAliasForFromItems() {
return isPostgres();
}
protected boolean allowsAs() {
return !isOracle();
return !isOracle() && !isSybase();
}
/** Whether "select * from (select * from t)" is OK. **/
public boolean allowsFromQuery() {
// older versions of AS400 do not allow FROM subqueries
return !(isMySQL() || isOldAS400() || isInformix());
return !isMySQL() && !isOldAS400() && !isInformix() && !isSybase();
}
/** Whether "select count(distinct x, y) from t" is OK. **/
public boolean allowsCompoundCountDistinct() {
Expand Down

0 comments on commit e2a0798

Please sign in to comment.