Class SQLUtils
- java.lang.Object
-
- org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils
-
public final class SQLUtils extends Object
SQL utility class.
-
-
Constructor Summary
Constructors Constructor Description SQLUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringconvertLikePatternToRegex(String pattern)Convert like pattern to regex.static ExpressionSegmentcreateLiteralExpression(ASTNode astNode, int startIndex, int stopIndex, String text)Create literal expression.static StringgetExactlyExpression(String value)Get exactly SQL expression.static NumbergetExactlyNumber(String value, int radix)Get exactly number value and type.static StringgetExactlyValue(String value)Get exactly value for SQL expression.static StringgetExactlyValue(String value, String reservedCharacters)Get exactly value for SQL expression.static StringgetExpressionWithoutOutsideParentheses(String value)Get exactly SQL expression without outside parentheses.static List<SubqueryTableSegment>getSubqueryTableSegmentFromTableSegment(TableSegment tableSegment)Get subquery from tableSegment.static StringtrimComment(String sql)Trim the comment of SQL.static StringtrimSemicolon(String sql)Trim the semicolon of SQL.static StringtryGetRealContentInBackticks(String value)Try get exactly value for backticks string.
-
-
-
Method Detail
-
getExactlyNumber
public static Number getExactlyNumber(String value, int radix)
Get exactly number value and type.- Parameters:
value- string to be convertedradix- radix- Returns:
- exactly number value and type
-
getExactlyValue
public static String getExactlyValue(String value)
Get exactly value for SQL expression.remove special char for SQL expression
- Parameters:
value- SQL expression- Returns:
- exactly SQL expression
-
getExactlyValue
public static String getExactlyValue(String value, String reservedCharacters)
Get exactly value for SQL expression.remove special char for SQL expression
- Parameters:
value- SQL expressionreservedCharacters- characters to be reserved- Returns:
- exactly SQL expression
-
tryGetRealContentInBackticks
public static String tryGetRealContentInBackticks(String value)
Try get exactly value for backticks string.try get content containing backticks exactly value
- Parameters:
value- SQL expression- Returns:
- exactly SQL expression
-
getExactlyExpression
public static String getExactlyExpression(String value)
Get exactly SQL expression.remove space for SQL expression
- Parameters:
value- SQL expression- Returns:
- exactly SQL expression
-
getExpressionWithoutOutsideParentheses
public static String getExpressionWithoutOutsideParentheses(String value)
Get exactly SQL expression without outside parentheses.- Parameters:
value- SQL expression- Returns:
- exactly SQL expression
-
getSubqueryTableSegmentFromTableSegment
public static List<SubqueryTableSegment> getSubqueryTableSegmentFromTableSegment(TableSegment tableSegment)
Get subquery from tableSegment.- Parameters:
tableSegment- TableSegment- Returns:
- exactly SubqueryTableSegment list
-
createLiteralExpression
public static ExpressionSegment createLiteralExpression(ASTNode astNode, int startIndex, int stopIndex, String text)
Create literal expression.- Parameters:
astNode- AST nodestartIndex- start indexstopIndex- stop indextext- text- Returns:
- literal expression segment
-
trimSemicolon
public static String trimSemicolon(String sql)
Trim the semicolon of SQL.- Parameters:
sql- SQL to be trim- Returns:
- SQL without semicolon
-
trimComment
public static String trimComment(String sql)
Trim the comment of SQL.- Parameters:
sql- SQL to be trim- Returns:
- remove comment from SQL
-
-