public final class SqlParserUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SqlParserUtil.ParsedCollation
The components of a collation definition, per the SQL standard.
|
static class |
SqlParserUtil.StringAndPos
Contains a string, the offset of a token within the string, and a parser
position containing the beginning and end line number.
|
static class |
SqlParserUtil.ToTreeListItem
Class that holds a
SqlOperator and a SqlParserPos. |
| Modifier and Type | Method and Description |
|---|---|
static String |
addCarets(String sql,
int line,
int col,
int endLine,
int endCol)
Converts a string to a string with one or two carets in it.
|
static void |
checkDateFormat(String pattern)
Checks if the date/time format is valid
|
static char |
checkUnicodeEscapeChar(String s)
Checks a UESCAPE string for validity, and returns the escape character if
no exception is thrown.
|
static SqlParserUtil.StringAndPos |
findPos(String sql)
Looks for one or two carets in a SQL string, and if present, converts
them into a parser position.
|
static String |
getCharacterSet(String s) |
static String |
getTokenVal(String token) |
static int[] |
indexToLineCol(String sql,
int i)
Returns the (1-based) line and column corresponding to a particular
(0-based) offset in a string.
|
static long |
intervalToMillis(SqlIntervalLiteral.IntervalValue interval)
Converts the interval value into a millisecond representation.
|
static long |
intervalToMillis(String literal,
SqlIntervalQualifier intervalQualifier) |
static long |
intervalToMonths(SqlIntervalLiteral.IntervalValue interval)
Converts the interval value into a months representation.
|
static long |
intervalToMonths(String literal,
SqlIntervalQualifier intervalQualifier) |
static int |
lineColToIndex(String sql,
int line,
int column)
Finds the position (0-based) in a string which corresponds to a given
line and column (1-based).
|
static int |
nextLine(String sql,
int j) |
static byte[] |
parseBinaryString(String s)
Parses a Binary string.
|
static SqlParserUtil.ParsedCollation |
parseCollation(String in)
Extracts the values from a collation name.
|
static Date |
parseDate(String s)
Deprecated.
this method is not localized for Farrago standards
|
static BigDecimal |
parseDecimal(String s) |
static BigDecimal |
parseInteger(String s) |
static int |
parsePositiveInt(String value)
Parses a positive int.
|
static String |
parseString(String s)
Converts the contents of an sql quoted string literal into the
corresponding Java string representation (removing leading and trailing
quotes and unescaping internal doubled quotes).
|
static Time |
parseTime(String s)
Deprecated.
Does not parse SQL:99 milliseconds
|
static Timestamp |
parseTimestamp(String s)
Deprecated.
this method is not localized for Farrago standards
|
static <T> void |
replaceSublist(List<T> list,
int start,
int end,
T o)
Replaces a range of elements in a list with a single element.
|
static String |
rightTrim(String s,
char c) |
static String |
strip(String s,
String startQuote,
String endQuote,
String escape,
Casing casing)
Unquotes a quoted string, using different quotes for beginning and end.
|
static SqlNode[] |
toNodeArray(List<SqlNode> list) |
static SqlNode[] |
toNodeArray(SqlNodeList list) |
static String[] |
toStringArray(List<String> list) |
static SqlNode |
toTree(List<Object> list)
Converts a list of {expression, operator, expression, ...} into a tree,
taking operator precedence and associativity into account.
|
static SqlNode |
toTreeEx(List<Object> list,
int start,
int minPrec,
SqlKind stopperKind)
Converts a list of {expression, operator, expression, ...} into a tree,
taking operator precedence and associativity into account.
|
static String |
trim(String s,
String chars)
Trims a string for given characters from left and right.
|
public static String getCharacterSet(String s)
public static String parseString(String s)
public static BigDecimal parseDecimal(String s)
public static BigDecimal parseInteger(String s)
public static Date parseDate(String s)
public static Timestamp parseTimestamp(String s)
public static void checkDateFormat(String pattern)
pattern - SimpleDateFormat patternpublic static long intervalToMillis(SqlIntervalLiteral.IntervalValue interval)
interval - Intervalpublic static long intervalToMillis(String literal, SqlIntervalQualifier intervalQualifier)
public static long intervalToMonths(SqlIntervalLiteral.IntervalValue interval)
interval - Intervalpublic static long intervalToMonths(String literal, SqlIntervalQualifier intervalQualifier)
public static int parsePositiveInt(String value)
NumberFormatException - if invalid number or leading '-'Integer.parseInt(String)public static byte[] parseBinaryString(String s)
public static String strip(String s, String startQuote, String endQuote, String escape, Casing casing)
public static String trim(String s, String chars)
trim("aBaac123AabC","abBcC") returns "123A".public static SqlParserUtil.StringAndPos findPos(String sql)
Examples:
public static int[] indexToLineCol(String sql, int i)
Converse of lineColToIndex(String, int, int).
public static int nextLine(String sql, int j)
public static int lineColToIndex(String sql, int line, int column)
Converse of indexToLineCol(String, int).
public static String addCarets(String sql, int line, int col, int endLine, int endCol)
addCarets("values (foo)", 1, 9, 1, 12) yields "values
(^foo^)".public static SqlParserUtil.ParsedCollation parseCollation(String in)
Collation names are on the form charset$locale$strength.
in - The collation nameSqlParserUtil.ParsedCollationpublic static SqlNode[] toNodeArray(SqlNodeList list)
public static <T> void replaceSublist(List<T> list, int start, int end, T o)
{A, B, C, D, E} then
replaceSublist(list, X, 1, 4) returns {A, X, E}.public static SqlNode toTree(List<Object> list)
public static SqlNode toTreeEx(List<Object> list, int start, int minPrec, SqlKind stopperKind)
list - List of operands and operators. This list is modified as
expressions are reduced.start - Position of first operand in the list. Anything to the
left of this (besides the immediately preceding operand)
is ignored. Generally use value 1.minPrec - Minimum precedence to consider. If the method encounters
an operator of lower precedence, it doesn't reduce any
further.stopperKind - If not SqlKind.OTHER, stop reading the list if
we encounter a token of this kind.public static char checkUnicodeEscapeChar(String s)
s - UESCAPE string to checkCopyright © 2012–2015 The Apache Software Foundation. All rights reserved.