public interface SqlWriter
SqlWriter
is the target to construct a SQL statement from a
parse tree. It deals with dialect differences; for example, Oracle quotes
identifiers as "scott"
, while SQL Server quotes them as
[scott]
.Modifier and Type | Interface and Description |
---|---|
static interface |
SqlWriter.Frame
A Frame is a piece of generated text which shares a common indentation
level.
|
static interface |
SqlWriter.FrameType
Frame type.
|
static class |
SqlWriter.FrameTypeEnum
Enumerates the types of frame.
|
static class |
SqlWriter.SubQueryStyle
Style of formatting sub-queries.
|
Modifier and Type | Method and Description |
---|---|
void |
dynamicParam(int index)
Prints a dynamic parameter (e.g.
|
void |
endFunCall(SqlWriter.Frame frame)
Ends a list which is a call to a function.
|
void |
endList(SqlWriter.Frame frame)
Ends a list.
|
void |
fetchOffset(SqlNode fetch,
SqlNode offset)
Prints the OFFSET/FETCH clause.
|
SqlDialect |
getDialect()
Returns the dialect of SQL.
|
int |
getIndentation()
Returns the offset for each level of indentation.
|
void |
identifier(java.lang.String name,
boolean quoted)
Prints an identifier, quoting as necessary.
|
boolean |
inQuery()
Returns whether we are currently in a query context (SELECT, INSERT,
UNION, INTERSECT, EXCEPT, and the ORDER BY operator).
|
boolean |
isAlwaysUseParentheses()
Returns whether to enclose all expressions in parentheses, even if the
operator has high enough precedence that the parentheses are not
required.
|
boolean |
isClauseStartsLine()
Returns whether this writer should start each clause (e.g.
|
boolean |
isKeywordsLowerCase()
Returns whether to output all keywords (e.g.
|
boolean |
isQuoteAllIdentifiers()
Returns whether this writer should quote all identifiers, even those
that do not contain mixed-case identifiers or punctuation.
|
boolean |
isSelectListItemsOnSeparateLines()
Returns whether the items in the SELECT clause should each be on a
separate line.
|
void |
keyword(java.lang.String s)
Prints a sequence of keywords.
|
void |
literal(java.lang.String s)
Prints a literal, exactly as provided.
|
void |
newlineAndIndent()
Prints a new line, and indents.
|
void |
print(int x)
Prints an integer.
|
void |
print(java.lang.String s)
Prints a string, preceded by whitespace if necessary.
|
void |
reset()
Resets this writer so that it can format another expression.
|
void |
resetSettings()
Resets all properties to their default values.
|
void |
sep(java.lang.String sep)
Writes a list separator, unless the separator is "," and this is the
first occurrence in the list.
|
void |
sep(java.lang.String sep,
boolean printFirst)
Writes a list separator.
|
void |
setNeedWhitespace(boolean needWhitespace)
Sets whether whitespace is needed before the next token.
|
SqlWriter.Frame |
startFunCall(java.lang.String funName)
Starts a list which is a call to a function.
|
SqlWriter.Frame |
startList(SqlWriter.FrameTypeEnum frameType)
Starts a list with no opening string.
|
SqlWriter.Frame |
startList(SqlWriter.FrameType frameType,
java.lang.String open,
java.lang.String close)
Starts a list.
|
SqlWriter.Frame |
startList(java.lang.String open,
java.lang.String close)
Starts a list.
|
SqlString |
toSqlString()
Returns the contents of this writer as a 'certified kocher' SQL string.
|
void reset()
resetSettings()
void resetSettings()
SqlDialect getDialect()
SqlString toSqlString()
void literal(java.lang.String s)
void keyword(java.lang.String s)
keyword("SELECT")
,
keyword("CHARACTER SET")
.void print(java.lang.String s)
void print(int x)
x
- Integervoid identifier(java.lang.String name, boolean quoted)
name
- The identifier namequoted
- Whether this identifier was quoted in the original sql statement,
this may not be the only factor to decide whether this identifier
should be quotedvoid dynamicParam(int index)
?
for default JDBC)void newlineAndIndent()
boolean isQuoteAllIdentifiers()
boolean isClauseStartsLine()
boolean isSelectListItemsOnSeparateLines()
boolean isKeywordsLowerCase()
SqlWriter.Frame startFunCall(java.lang.String funName)
endFunCall(Frame)
void endFunCall(SqlWriter.Frame frame)
frame
- FramestartFunCall(String)
SqlWriter.Frame startList(java.lang.String open, java.lang.String close)
SqlWriter.Frame startList(SqlWriter.FrameTypeEnum frameType)
frameType
- Type of list. For example, a SELECT list will beSqlWriter.Frame startList(SqlWriter.FrameType frameType, java.lang.String open, java.lang.String close)
frameType
- Type of list. For example, a SELECT list will be
governed according to SELECT-list formatting preferences.open
- String to start the list; typically "(" or the empty
string.close
- String to close the listvoid endList(SqlWriter.Frame frame)
frame
- The frame which was created by startList(java.lang.String, java.lang.String)
.void sep(java.lang.String sep)
sep
- List separator, typically ",".void sep(java.lang.String sep, boolean printFirst)
sep
- List separator, typically ","printFirst
- Whether to print the first occurrence of the separatorvoid setNeedWhitespace(boolean needWhitespace)
int getIndentation()
boolean isAlwaysUseParentheses()
For example, the parentheses are required in the expression (a +
b) * c
because the '*' operator has higher precedence than the '+'
operator, and so without the parentheses, the expression would be
equivalent to a + (b * c)
. The fully-parenthesized
expression, ((a + b) * c)
is unambiguous even if you don't
know the precedence of every operator.
boolean inQuery()
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.