org.eigenbase.sql
Interface SqlWriter

All Known Implementing Classes:
SqlPrettyWriter

public interface SqlWriter

A 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].

Since:
2002/8/8
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/SqlWriter.java#16 $
Author:
Julian Hyde

Nested Class Summary
static interface SqlWriter.Frame
          A Frame is a piece of generated text which shares a common indentation level.
static interface SqlWriter.FrameType
           
static class SqlWriter.FrameTypeEnum
          Enumerates the types of frame.
static class SqlWriter.SubqueryStyle
          Style of formatting subqueries.
 
Method Summary
 void endFunCall(SqlWriter.Frame frame)
          Ends a list which is a call to a function.
 void endList(SqlWriter.Frame frame)
          Ends a list.
 SqlDialect getDialect()
           
 int getIndentation()
          Returns the offset for each level of indentation.
 void identifier(String name)
          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()
           
 boolean isKeywordsLowerCase()
           
 boolean isQuoteAllIdentifiers()
           
 boolean isSelectListItemsOnSeparateLines()
           
 void keyword(String s)
          Prints a sequence of keywords.
 void literal(String s)
          Prints a literal, exactly as provided.
 void newlineAndIndent()
          Prints a new line, and indents.
 void print(int x)
           
 void print(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(String sep)
          Writes a list separator, unless the separator is "," and this is the first occurrence in the list.
 void sep(String sep, boolean printFirst)
          Writes a list separator.
 void setNeedWhitespace(boolean needWhitespace)
          Sets whether whitespace is needed before the next token.
 SqlWriter.Frame startFunCall(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, String open, String close)
          Starts a list.
 SqlWriter.Frame startList(String open, String close)
          Starts a list.
 

Method Detail

reset

void reset()
Resets this writer so that it can format another expression. Does not affect formatting preferences (see resetSettings()


resetSettings

void resetSettings()
Resets all properties to their default values.


getDialect

SqlDialect getDialect()

literal

void literal(String s)
Prints a literal, exactly as provided. Does not attempt to indent or convert to upper or lower case. Does not add quotation marks. Adds preceding whitespace if necessary.


keyword

void keyword(String s)
Prints a sequence of keywords. Must not start or end with space, but may contain a space. For example, keyword("SELECT"), keyword("CHARACTER SET").


print

void print(String s)
Prints a string, preceded by whitespace if necessary.


print

void print(int x)

identifier

void identifier(String name)
Prints an identifier, quoting as necessary.


newlineAndIndent

void newlineAndIndent()
Prints a new line, and indents.


isQuoteAllIdentifiers

boolean isQuoteAllIdentifiers()

isClauseStartsLine

boolean isClauseStartsLine()

isSelectListItemsOnSeparateLines

boolean isSelectListItemsOnSeparateLines()

isKeywordsLowerCase

boolean isKeywordsLowerCase()

startFunCall

SqlWriter.Frame startFunCall(String funName)
Starts a list which is a call to a function.

See Also:
endFunCall(Frame)

endFunCall

void endFunCall(SqlWriter.Frame frame)
Ends a list which is a call to a function.

Parameters:
frame -
See Also:
startFunCall(String)

startList

SqlWriter.Frame startList(String open,
                          String close)
Starts a list.


startList

SqlWriter.Frame startList(SqlWriter.FrameTypeEnum frameType)
Starts a list with no opening string.

Parameters:
frameType - Type of list. For example, a SELECT list will be

startList

SqlWriter.Frame startList(SqlWriter.FrameType frameType,
                          String open,
                          String close)
Starts a list.

Parameters:
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 -

endList

void endList(SqlWriter.Frame frame)
Ends a list.

Parameters:
frame - The frame which was created by startList(java.lang.String, java.lang.String).

sep

void sep(String sep)
Writes a list separator, unless the separator is "," and this is the first occurrence in the list.

Parameters:
sep - List separator, typically ",".

sep

void sep(String sep,
         boolean printFirst)
Writes a list separator.

Parameters:
sep - List separator, typically ","
printFirst - Whether to print the first occurrence of the separator

setNeedWhitespace

void setNeedWhitespace(boolean needWhitespace)
Sets whether whitespace is needed before the next token.


getIndentation

int getIndentation()
Returns the offset for each level of indentation. Default 4.


isAlwaysUseParentheses

boolean isAlwaysUseParentheses()
Returns whether to enclose all expressions in parentheses, even if the operator has high enough precedence that the parentheses are not required.

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.


inQuery

boolean inQuery()
Returns whether we are currently in a query context (SELECT, INSERT, UNION, INTERSECT, EXCEPT, and the ORDER BY operator).