public class SqlDialect extends Object
SqlDialect encapsulates the differences between dialects of SQL.
It is used by classes such as SqlWriter and
SqlBuilder.
| Modifier and Type | Class and Description |
|---|---|
static class |
SqlDialect.DatabaseProduct
Rough list of flavors of database.
|
static class |
SqlDialect.FakeUtil
A few utility functions copied from org.apache.calcite.util.Util.
|
| Modifier and Type | Field and Description |
|---|---|
static SqlDialect |
CALCITE
A dialect useful for generating SQL which can be parsed by the
Calcite parser, in particular quoting literals and identifiers.
|
static SqlDialect |
DUMMY
A dialect useful for generating generic SQL.
|
| Constructor and Description |
|---|
SqlDialect(SqlDialect.DatabaseProduct databaseProduct,
String databaseProductName,
String identifierQuoteString)
Creates a SqlDialect.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
allowsAs() |
static SqlDialect |
create(DatabaseMetaData databaseMetaData)
Creates a
SqlDialect from a DatabaseMetaData. |
SqlDialect.DatabaseProduct |
getDatabaseProduct()
Returns the database this dialect belongs to,
SqlDialect.DatabaseProduct.UNKNOWN if not known, never null. |
static SqlDialect.DatabaseProduct |
getProduct(String productName,
String productVersion)
Converts a product name and version (per the JDBC driver) into a product
enumeration.
|
boolean |
identifierNeedsToBeQuoted(String val)
Returns whether a given identifier needs to be quoted.
|
String |
quoteIdentifier(String val)
Encloses an identifier in quotation marks appropriate for the current SQL
dialect.
|
StringBuilder |
quoteIdentifier(StringBuilder buf,
List<String> identifiers)
Quotes a multi-part identifier.
|
StringBuilder |
quoteIdentifier(StringBuilder buf,
String val)
Encloses an identifier in quotation marks appropriate for the current SQL
dialect, writing the result to a
StringBuilder. |
String |
quoteStringLiteral(String val)
Converts a string into a string literal.
|
void |
quoteStringLiteralUnicode(StringBuilder buf,
String val)
Converts a string into a unicode string literal.
|
String |
quoteTimestampLiteral(Timestamp timestamp)
Converts a timestamp to a SQL timestamp literal, e.g.
|
protected boolean |
requiresAliasForFromItems() |
boolean |
supportsCharSet()
Returns whether the dialect supports character set names as part of a
data type, for instance
VARCHAR(30) CHARACTER SET `ISO-8859-1`. |
String |
unquoteStringLiteral(String val)
Converts a string literal back into a string.
|
public static final SqlDialect DUMMY
public static final SqlDialect CALCITE
public SqlDialect(SqlDialect.DatabaseProduct databaseProduct, String databaseProductName, String identifierQuoteString)
databaseProduct - Database product; may be UNKNOWN, never nulldatabaseProductName - Database product name from JDBC driveridentifierQuoteString - String to quote identifiers. Null if quoting
is not supported. If "[", close quote is
deemed to be "]".public static SqlDialect create(DatabaseMetaData databaseMetaData)
SqlDialect from a DatabaseMetaData.
Does not maintain a reference to the DatabaseMetaData -- or, more
importantly, to its Connection -- after this call has
returned.
databaseMetaData - used to determine which dialect of SQL to
generatepublic static SqlDialect.DatabaseProduct getProduct(String productName, String productVersion)
productName - Product nameproductVersion - Product versionpublic String quoteIdentifier(String val)
For example, quoteIdentifier("emp") yields a string
containing "emp" in Oracle, and a string containing
[emp] in Access.
val - Identifier to quotepublic StringBuilder quoteIdentifier(StringBuilder buf, String val)
StringBuilder.
For example, quoteIdentifier("emp") yields a string
containing "emp" in Oracle, and a string containing
[emp] in Access.
buf - Bufferval - Identifier to quotepublic StringBuilder quoteIdentifier(StringBuilder buf, List<String> identifiers)
buf - Bufferidentifiers - List of parts of the identifier to quotepublic boolean identifierNeedsToBeQuoted(String val)
public String quoteStringLiteral(String val)
can't
run becomes 'can''t run'.public void quoteStringLiteralUnicode(StringBuilder buf, String val)
can't{tab}run\ becomes u'can''t\0009run\\'.public String unquoteStringLiteral(String val)
'can''t
run' becomes can't run.protected boolean allowsAs()
protected boolean requiresAliasForFromItems()
public String quoteTimestampLiteral(Timestamp timestamp)
TIMESTAMP '2009-12-17 12:34:56'.
Timestamp values do not have a time zone. We therefore interpret them as the number of milliseconds after the UTC epoch, and the formatted value is that time in UTC.
In particular,
quoteTimestampLiteral(new Timestamp(0));
returns TIMESTAMP '1970-01-01 00:00:00', regardless of the JVM's
timezone.timestamp - Timestamppublic SqlDialect.DatabaseProduct getDatabaseProduct()
SqlDialect.DatabaseProduct.UNKNOWN if not known, never null.public boolean supportsCharSet()
VARCHAR(30) CHARACTER SET `ISO-8859-1`.Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.