use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat_plus by coderczp.
the class GlobalTableUtil method addColumnIfCreate.
static String addColumnIfCreate(String sql, SQLStatement statement) {
if (isCreate(statement) && sql.trim().toUpperCase().startsWith("CREATE TABLE ") && !hasGlobalColumn(statement)) {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("bigint"));
column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_MYCAT_COLUMN));
column.setComment(new SQLCharExpr("全局表保存修改时间戳的字段名"));
((SQLCreateTableStatement) statement).getTableElementList().add(column);
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.
the class DruidInsertReplaceParser method shardingValueToSting.
protected static String shardingValueToSting(SQLExpr valueExpr) throws SQLNonTransientException {
String shardingValue = null;
if (valueExpr instanceof SQLIntegerExpr) {
SQLIntegerExpr intExpr = (SQLIntegerExpr) valueExpr;
shardingValue = intExpr.getNumber() + "";
} else if (valueExpr instanceof SQLCharExpr) {
SQLCharExpr charExpr = (SQLCharExpr) valueExpr;
shardingValue = charExpr.getText();
}
if (shardingValue == null) {
throw new SQLNonTransientException("Not Supported of Sharding Value EXPR :" + valueExpr.toString());
}
return shardingValue;
}
use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.
the class ItemFuncGroupConcat method toExpression.
@Override
public SQLExpr toExpression() {
SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName());
if (hasWithDistinct()) {
aggregate.setOption(SQLAggregateOption.DISTINCT);
}
if (orders != null) {
SQLOrderBy orderBy = new SQLOrderBy();
for (Order order : orders) {
SQLSelectOrderByItem orderItem = new SQLSelectOrderByItem(order.getItem().toExpression());
orderItem.setType(order.getSortOrder());
orderBy.addItem(orderItem);
}
aggregate.putAttribute(ItemFuncKeyWord.ORDER_BY, orderBy);
}
for (Item arg : args) {
aggregate.addArgument(arg.toExpression());
}
if (seperator != null) {
SQLCharExpr sep = new SQLCharExpr(seperator);
aggregate.putAttribute(ItemFuncKeyWord.SEPARATOR, sep);
}
return aggregate;
}
use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.
the class GlobalTableUtil method createCheckColumn.
public static SQLColumnDefinition createCheckColumn() {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("bigint"));
column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_CHECK_COLUMN));
column.setComment(new SQLCharExpr("field for checking consistency"));
return column;
}
use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat-Server by MyCATApache.
the class MycatStatementParser method parseLoadDataInFile.
// 此处注释掉,以修正后端jdbc方式时,delete语句解析出错的情况
//
// public SQLSelectParser createSQLSelectParser()
// {
// return new MycatSelectParser(this.selectExprParser);
// }
@Override
protected MySqlLoadDataInFileStatement parseLoadDataInFile() {
acceptIdentifier("DATA");
LoadDataStatement stmt = new LoadDataStatement();
if (identifierEquals(LOW_PRIORITY)) {
stmt.setLowPriority(true);
lexer.nextToken();
}
if (identifierEquals("CONCURRENT")) {
stmt.setConcurrent(true);
lexer.nextToken();
}
if (identifierEquals(LOCAL)) {
stmt.setLocal(true);
lexer.nextToken();
}
acceptIdentifier("INFILE");
SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr();
stmt.setFileName(fileName);
if (lexer.token() == Token.REPLACE) {
stmt.setReplicate(true);
lexer.nextToken();
}
if (identifierEquals(IGNORE)) {
stmt.setIgnore(true);
lexer.nextToken();
}
accept(Token.INTO);
accept(Token.TABLE);
SQLName tableName = exprParser.name();
stmt.setTableName(tableName);
if (identifierEquals(CHARACTER)) {
lexer.nextToken();
accept(Token.SET);
if (lexer.token() != Token.LITERAL_CHARS) {
throw new ParserException("syntax error, illegal charset");
}
String charset = lexer.stringVal();
lexer.nextToken();
stmt.setCharset(charset);
}
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
lexer.nextToken();
if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
stmt.setColumnsTerminatedBy(new SQLCharExpr(lexer.stringVal()));
lexer.nextToken();
}
if (identifierEquals("OPTIONALLY")) {
stmt.setColumnsEnclosedOptionally(true);
lexer.nextToken();
}
if (identifierEquals("ENCLOSED")) {
lexer.nextToken();
accept(Token.BY);
stmt.setColumnsEnclosedBy(new SQLCharExpr(lexer.stringVal()));
lexer.nextToken();
}
if (identifierEquals("ESCAPED")) {
lexer.nextToken();
accept(Token.BY);
stmt.setColumnsEscaped(new SQLCharExpr(lexer.stringVal()));
lexer.nextToken();
}
}
if (identifierEquals("LINES")) {
lexer.nextToken();
if (identifierEquals("STARTING")) {
lexer.nextToken();
accept(Token.BY);
stmt.setLinesStartingBy(new SQLCharExpr(lexer.stringVal()));
lexer.nextToken();
}
if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
stmt.setLinesTerminatedBy(new SQLCharExpr(lexer.stringVal()));
lexer.nextToken();
}
}
if (identifierEquals(IGNORE)) {
lexer.nextToken();
stmt.setIgnoreLinesNumber(this.exprParser.expr());
acceptIdentifier("LINES");
}
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
this.exprParser.exprList(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}
if (lexer.token() == Token.SET) {
lexer.nextToken();
this.exprParser.exprList(stmt.getSetList(), stmt);
}
return stmt;
}
Aggregations