use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.
the class DruidSelectParser method buildOrderByCols.
protected LinkedHashMap<String, Integer> buildOrderByCols(List<SQLSelectOrderByItem> orderByItems, Map<String, String> aliaColumns) {
LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
for (int i = 0; i < orderByItems.size(); i++) {
SQLOrderingSpecification type = orderByItems.get(i).getType();
//orderColumn只记录字段名称,因为返回的结果集是不带表名的。
SQLExpr expr = orderByItems.get(i).getExpr();
String col;
if (expr instanceof SQLName) {
col = ((SQLName) expr).getSimpleName();
} else {
col = expr.toString();
}
if (type == null) {
type = SQLOrderingSpecification.ASC;
}
//此步骤得到的col必须是不带.的,有别名的用别名,无别名的用字段名
col = getAliaColumn(aliaColumns, col);
map.put(col, type == SQLOrderingSpecification.ASC ? OrderCol.COL_ORDER_TYPE_ASC : OrderCol.COL_ORDER_TYPE_DESC);
}
return map;
}
use of com.alibaba.druid.sql.ast.SQLName 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;
}
use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.
the class MycatSchemaStatVisitor method visit.
public boolean visit(MySqlCreateTableStatement x) {
SQLName sqlName = x.getName();
if (sqlName != null) {
String table = sqlName.toString();
if (table.startsWith("`")) {
table = table.substring(1, table.length() - 1);
}
setCurrentTable(table);
}
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.
the class MycatSchemaStatVisitor method visit.
public boolean visit(MySqlInsertStatement x) {
SQLName sqlName = x.getTableName();
if (sqlName != null) {
String table = sqlName.toString();
if (table.startsWith("`")) {
table = table.substring(1, table.length() - 1);
}
setCurrentTable(sqlName.toString());
}
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method hasGlobalColumn.
private static boolean hasGlobalColumn(SQLStatement statement) {
for (SQLTableElement tableElement : ((SQLCreateTableStatement) statement).getTableElementList()) {
SQLName sqlName = null;
if (tableElement instanceof SQLColumnDefinition) {
sqlName = ((SQLColumnDefinition) tableElement).getName();
}
if (sqlName != null) {
String simpleName = sqlName.getSimpleName();
simpleName = StringUtil.removeBackquote(simpleName);
if (tableElement instanceof SQLColumnDefinition && GLOBAL_TABLE_MYCAT_COLUMN.equalsIgnoreCase(simpleName)) {
return true;
}
}
}
return false;
}
Aggregations