mondrian.spi.impl
Class MySqlDialect

java.lang.Object
  extended by mondrian.spi.impl.JdbcDialectImpl
      extended by mondrian.spi.impl.MySqlDialect
All Implemented Interfaces:
Dialect
Direct Known Subclasses:
InfobrightDialect

public class MySqlDialect
extends JdbcDialectImpl

Implementation of Dialect for the MySQL database.

Since:
Nov 23, 2008
Version:
$Id: //open/mondrian/src/main/mondrian/spi/impl/MySqlDialect.java#12 $
Author:
jhyde

Nested Class Summary
 
Nested classes/interfaces inherited from interface mondrian.spi.Dialect
Dialect.DatabaseProduct, Dialect.Datatype, Dialect.NullCollation
 
Field Summary
static JdbcDialectFactory FACTORY
           
 
Fields inherited from class mondrian.spi.impl.JdbcDialectImpl
databaseProduct, permitsSelectNotInGroupBy, productVersion
 
Constructor Summary
MySqlDialect(java.sql.Connection connection)
          Creates a MySqlDialect.
 
Method Summary
 boolean allowsCompoundCountDistinct()
          Returns whether this Dialect allows multiple arguments to the COUNT(DISTINCT ...) aggregate function, for example SELECT COUNT(DISTINCT x, y) FROM t
 boolean allowsFromQuery()
          Returns whether this Dialect allows a subquery in the from clause, for example SELECT * FROM (SELECT * FROM t) AS x
 void appendHintsAfterFromClause(java.lang.StringBuilder buf, java.util.Map<java.lang.String,java.lang.String> hints)
          Assembles and returns a string containing any hints that should be appended after the FROM clause in a SELECT statement, based on any hints provided.
protected  java.lang.String deduceIdentifierQuoteString(java.sql.DatabaseMetaData databaseMetaData)
           
protected  java.lang.String deduceProductName(java.sql.DatabaseMetaData databaseMetaData)
           
protected  boolean deduceSupportsSelectNotInGroupBy(java.sql.Connection connection)
          Detects whether the database is configured to permit queries that include columns in the SELECT that are not also in the GROUP BY.
 java.lang.String generateInline(java.util.List<java.lang.String> columnNames, java.util.List<java.lang.String> columnTypes, java.util.List<java.lang.String[]> valueList)
          Generates a SQL statement to represent an inline dataset.
 java.lang.String generateOrderItem(java.lang.String expr, boolean nullable, boolean ascending)
          Generates an item for an ORDER BY clause, sorting in the required direction, and ensuring that NULL values collate after all non-NULL values.
 Dialect.NullCollation getNullCollation()
          Returns the rule which determines whether NULL values appear first or last when sorted using ORDER BY.
static boolean isInfobright(java.sql.DatabaseMetaData databaseMetaData)
          Detects whether this database is Infobright.
 boolean requiresAliasForFromQuery()
          Returns whether this Dialect requires subqueries in the FROM clause to have an alias.
 boolean requiresOrderByAlias()
          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.
 boolean supportsMultiValueInExpr()
          Returns true if this dialect supports multi-value IN expressions.
 
Methods inherited from class mondrian.spi.impl.JdbcDialectImpl
allowsAs, allowsCountDistinct, allowsDdl, allowsDialectSharing, allowsMultipleCountDistinct, allowsMultipleDistinctSqlMeasures, allowsOrderByAlias, allowsSelectNotInGroupBy, caseWhenElse, deduceMaxColumnNameLength, deduceProductVersion, deduceReadOnly, deduceSupportedResultSetStyles, generateInlineForAnsi, generateInlineGeneric, getDatabaseProduct, getMaxColumnNameLength, getProduct, getQuoteIdentifierString, needsExponent, quote, quoteBooleanLiteral, quoteDateLiteral, quoteDateLiteral, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteNumericLiteral, quoteStringLiteral, quoteTimeLiteral, quoteTimestampLiteral, requiresGroupByAlias, requiresUnionOrderByExprToBeInSelectClause, requiresUnionOrderByOrdinal, supportsGroupByExpressions, supportsGroupingSets, supportsOrderByNullsLast, supportsResultSetConcurrency, supportsUnlimitedValueList, toString, toUpper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FACTORY

public static final JdbcDialectFactory FACTORY
Constructor Detail

MySqlDialect

public MySqlDialect(java.sql.Connection connection)
             throws java.sql.SQLException
Creates a MySqlDialect.

Parameters:
connection - Connection
Throws:
java.sql.SQLException
Method Detail

isInfobright

public static boolean isInfobright(java.sql.DatabaseMetaData databaseMetaData)
Detects whether this database is Infobright.

Infobright uses the MySQL driver and appears to be a MySQL instance. The only difference is the presence of the BRIGHTHOUSE engine.

Parameters:
databaseMetaData - Database metadata
Returns:
Whether this is Infobright

deduceProductName

protected java.lang.String deduceProductName(java.sql.DatabaseMetaData databaseMetaData)
Overrides:
deduceProductName in class JdbcDialectImpl

deduceIdentifierQuoteString

protected java.lang.String deduceIdentifierQuoteString(java.sql.DatabaseMetaData databaseMetaData)
Overrides:
deduceIdentifierQuoteString in class JdbcDialectImpl

deduceSupportsSelectNotInGroupBy

protected boolean deduceSupportsSelectNotInGroupBy(java.sql.Connection connection)
                                            throws java.sql.SQLException
Description copied from class: JdbcDialectImpl

Detects whether the database is configured to permit queries that include columns in the SELECT that are not also in the GROUP BY. MySQL is an example of one that does, though this is configurable.

The expectation is that this will not change while Mondrian is running, though some databases (MySQL) allow changing it on the fly.

Overrides:
deduceSupportsSelectNotInGroupBy in class JdbcDialectImpl
Parameters:
connection - The database connection
Returns:
Whether the feature is enabled.
Throws:
java.sql.SQLException

appendHintsAfterFromClause

public void appendHintsAfterFromClause(java.lang.StringBuilder buf,
                                       java.util.Map<java.lang.String,java.lang.String> hints)
Description copied from interface: Dialect
Assembles and returns a string containing any hints that should be appended after the FROM clause in a SELECT statement, based on any hints provided. Any unrecognized or unsupported hints will be ignored.

Specified by:
appendHintsAfterFromClause in interface Dialect
Overrides:
appendHintsAfterFromClause in class JdbcDialectImpl
Parameters:
buf - The Stringbuffer to which the dialect-specific syntax for any relevant table hints may be appended. Must not be null.
hints - A map of table hints provided in the schema definition

requiresAliasForFromQuery

public boolean requiresAliasForFromQuery()
Description copied from interface: Dialect
Returns whether this Dialect requires subqueries in the FROM clause to have an alias.

Specified by:
requiresAliasForFromQuery in interface Dialect
Overrides:
requiresAliasForFromQuery in class JdbcDialectImpl
Returns:
whether dialewct requires subqueries to have an alias
See Also:
Dialect.allowsFromQuery()

allowsFromQuery

public boolean allowsFromQuery()
Description copied from interface: Dialect
Returns whether this Dialect allows a subquery in the from clause, for example
SELECT * FROM (SELECT * FROM t) AS x

Specified by:
allowsFromQuery in interface Dialect
Overrides:
allowsFromQuery in class JdbcDialectImpl
Returns:
whether Dialect allows subquery in FROM clause
See Also:
Dialect.requiresAliasForFromQuery()

allowsCompoundCountDistinct

public boolean allowsCompoundCountDistinct()
Description copied from interface: Dialect
Returns whether this Dialect allows multiple arguments to the COUNT(DISTINCT ...) aggregate function, for example
SELECT COUNT(DISTINCT x, y) FROM t

Specified by:
allowsCompoundCountDistinct in interface Dialect
Overrides:
allowsCompoundCountDistinct in class JdbcDialectImpl
Returns:
whether Dialect allows multiple arguments to COUNT DISTINCT
See Also:
Dialect.allowsCountDistinct(), Dialect.allowsMultipleCountDistinct()

generateInline

public java.lang.String generateInline(java.util.List<java.lang.String> columnNames,
                                       java.util.List<java.lang.String> columnTypes,
                                       java.util.List<java.lang.String[]> valueList)
Description copied from interface: Dialect
Generates a SQL statement to represent an inline dataset.

For example, for Oracle, generates

 SELECT 1 AS FOO, 'a' AS BAR FROM dual
 UNION ALL
 SELECT 2 AS FOO, 'b' AS BAR FROM dual
 

For ANSI SQL, generates:

 VALUES (1, 'a'), (2, 'b')
 

Specified by:
generateInline in interface Dialect
Overrides:
generateInline in class JdbcDialectImpl
Parameters:
columnNames - List of column names
columnTypes - List of column types ("String" or "Numeric")
valueList - List of rows values
Returns:
SQL string

getNullCollation

public Dialect.NullCollation getNullCollation()
Description copied from interface: Dialect
Returns the rule which determines whether NULL values appear first or last when sorted using ORDER BY.

According to the SQL standard, this is implementation-specific. The default behavior is Dialect.NullCollation.POSINF.

Specified by:
getNullCollation in interface Dialect
Overrides:
getNullCollation in class JdbcDialectImpl
Returns:
Rule which determines whether NULL values collate first or last

generateOrderItem

public java.lang.String generateOrderItem(java.lang.String expr,
                                          boolean nullable,
                                          boolean ascending)
Description copied from interface: Dialect
Generates an item for an ORDER BY clause, sorting in the required direction, and ensuring that NULL values collate after all non-NULL values.

By default, generateOrderItem(expr, true) generates "expr ASC" and generateOrderItem(expr, false) generates "expr DESC". But depending on Dialect.getNullCollation() and ascending, there may need to be additional code.

For example, on Oracle, where NULLs collate higher than all other values, generateOrderItem(expr, true) generates "expr ASC" and generateOrderItem(expr, false) generates "expr DESC NULLS LAST".

On MySQL, where NULLs collate lower than all other values, generateOrderItem(expr, true) generates "ISNULL(expr), expr ASC" and generateOrderItem(expr, false) generates "expr DESC".

Specified by:
generateOrderItem in interface Dialect
Overrides:
generateOrderItem in class JdbcDialectImpl
Parameters:
expr - Expression
nullable - Whether expression may have NULL values
ascending - Whether to sort expression ascending
Returns:
Expression modified so that NULL values collate last

requiresOrderByAlias

public boolean requiresOrderByAlias()
Description copied from interface: Dialect
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.

For example, in such a dialect,

SELECT x FROM t ORDER BY x + y
would be illegal, but
SELECT x, x + y AS z FROM t ORDER BY z
would be legal.

MySQL, DB2 and Ingres are examples of such dialects.

Specified by:
requiresOrderByAlias in interface Dialect
Overrides:
requiresOrderByAlias in class JdbcDialectImpl
Returns:
Whether this Dialect can include expressions in the ORDER BY clause only by adding an expression to the SELECT clause and using its alias

supportsMultiValueInExpr

public boolean supportsMultiValueInExpr()
Description copied from interface: Dialect
Returns true if this dialect supports multi-value IN expressions. E.g., WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))

Specified by:
supportsMultiValueInExpr in interface Dialect
Overrides:
supportsMultiValueInExpr in class JdbcDialectImpl
Returns:
true if the dialect supports multi-value IN expressions

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads