use of com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr in project druid by alibaba.
the class MySqlSelectParser method parseInto.
protected void parseInto(SQLSelectQueryBlock queryBlock) {
if (lexer.token() == (Token.INTO)) {
lexer.nextToken();
if (identifierEquals("OUTFILE")) {
lexer.nextToken();
MySqlOutFileExpr outFile = new MySqlOutFileExpr();
outFile.setFile(expr());
queryBlock.setInto(outFile);
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
lexer.nextToken();
if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
}
outFile.setColumnsTerminatedBy(expr());
if (identifierEquals("OPTIONALLY")) {
lexer.nextToken();
outFile.setColumnsEnclosedOptionally(true);
}
if (identifierEquals("ENCLOSED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
}
if (identifierEquals("ESCAPED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
}
}
if (identifierEquals("LINES")) {
lexer.nextToken();
if (identifierEquals("STARTING")) {
lexer.nextToken();
accept(Token.BY);
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
} else {
identifierEquals("TERMINATED");
lexer.nextToken();
accept(Token.BY);
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
}
}
} else {
queryBlock.setInto(this.exprParser.name());
}
}
}
use of com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr in project druid by alibaba.
the class MySqlExprParser method primary.
public SQLExpr primary() {
final Token tok = lexer.token();
if (identifierEquals("outfile")) {
lexer.nextToken();
SQLExpr file = primary();
SQLExpr expr = new MySqlOutFileExpr(file);
return primaryRest(expr);
}
switch(tok) {
case LITERAL_ALIAS:
String aliasValue = lexer.stringVal();
lexer.nextToken();
return primaryRest(new SQLCharExpr(aliasValue));
case VARIANT:
SQLVariantRefExpr varRefExpr = new SQLVariantRefExpr(lexer.stringVal());
lexer.nextToken();
if (varRefExpr.getName().equalsIgnoreCase("@@global")) {
accept(Token.DOT);
varRefExpr = new SQLVariantRefExpr(lexer.stringVal(), true);
lexer.nextToken();
} else if (varRefExpr.getName().equals("@") && lexer.token() == Token.LITERAL_CHARS) {
varRefExpr.setName("@'" + lexer.stringVal() + "'");
lexer.nextToken();
} else if (varRefExpr.getName().equals("@@") && lexer.token() == Token.LITERAL_CHARS) {
varRefExpr.setName("@@'" + lexer.stringVal() + "'");
lexer.nextToken();
}
return primaryRest(varRefExpr);
case VALUES:
lexer.nextToken();
if (lexer.token() != Token.LPAREN) {
throw new ParserException("syntax error, illegal values clause");
}
return this.methodRest(new SQLIdentifierExpr("VALUES"), true);
case BINARY:
lexer.nextToken();
if (lexer.token() == Token.COMMA || lexer.token() == Token.SEMI || lexer.token() == Token.EOF) {
return new SQLIdentifierExpr("BINARY");
} else {
SQLUnaryExpr binaryExpr = new SQLUnaryExpr(SQLUnaryOperator.BINARY, expr());
return primaryRest(binaryExpr);
}
case CACHE:
case GROUP:
lexer.nextToken();
return primaryRest(new SQLIdentifierExpr(lexer.stringVal()));
default:
return super.primary();
}
}
use of com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr in project druid by alibaba.
the class MySqlSelectIntoParser method parseInto.
protected void parseInto(SQLSelectQueryBlock queryBlock) {
if (lexer.token() == (Token.INTO)) {
lexer.nextToken();
if (identifierEquals("OUTFILE")) {
lexer.nextToken();
MySqlOutFileExpr outFile = new MySqlOutFileExpr();
outFile.setFile(expr());
queryBlock.setInto(outFile);
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
lexer.nextToken();
if (identifierEquals("TERMINATED")) {
lexer.nextToken();
accept(Token.BY);
}
outFile.setColumnsTerminatedBy((SQLLiteralExpr) expr());
if (identifierEquals("OPTIONALLY")) {
lexer.nextToken();
outFile.setColumnsEnclosedOptionally(true);
}
if (identifierEquals("ENCLOSED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
}
if (identifierEquals("ESCAPED")) {
lexer.nextToken();
accept(Token.BY);
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
}
}
if (identifierEquals("LINES")) {
lexer.nextToken();
if (identifierEquals("STARTING")) {
lexer.nextToken();
accept(Token.BY);
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
} else {
identifierEquals("TERMINATED");
lexer.nextToken();
accept(Token.BY);
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
}
}
} else {
queryBlock.setInto(this.exprParser.name());
}
}
}
use of com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr in project druid by alibaba.
the class MySqlASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
MySqlASTVisitorAdapter adapter = new MySqlASTVisitorAdapter();
new SQLBooleanExpr().accept(adapter);
new SQLLimit().accept(adapter);
new MySqlTableIndex().accept(adapter);
new MySqlKey().accept(adapter);
new MySqlPrimaryKey().accept(adapter);
new MySqlIntervalExpr().accept(adapter);
new SQLBinaryExpr().accept(adapter);
new MySqlPrepareStatement().accept(adapter);
new MySqlExecuteStatement().accept(adapter);
new MysqlDeallocatePrepareStatement().accept(adapter);
new MySqlDeleteStatement().accept(adapter);
new MySqlInsertStatement().accept(adapter);
new MySqlLoadXmlStatement().accept(adapter);
new MySqlReplaceStatement().accept(adapter);
new SQLStartTransactionStatement().accept(adapter);
new MySqlRollbackStatement().accept(adapter);
new MySqlShowColumnsStatement().accept(adapter);
new MySqlShowDatabasesStatement().accept(adapter);
new MySqlShowWarningsStatement().accept(adapter);
new MySqlShowStatusStatement().accept(adapter);
new CobarShowStatus().accept(adapter);
new MySqlKillStatement().accept(adapter);
new MySqlBinlogStatement().accept(adapter);
new MySqlResetStatement().accept(adapter);
new UserSpecification().accept(adapter);
new MySqlPartitionByKey().accept(adapter);
new MySqlOutFileExpr().accept(adapter);
new MySqlUpdateStatement().accept(adapter);
new MySqlSetTransactionStatement().accept(adapter);
new MySqlSetNamesStatement().accept(adapter);
new MySqlShowMasterLogsStatement().accept(adapter);
new MySqlSetCharSetStatement().accept(adapter);
new MySqlShowAuthorsStatement().accept(adapter);
new MySqlShowCollationStatement().accept(adapter);
new MySqlShowBinLogEventsStatement().accept(adapter);
new MySqlShowCharacterSetStatement().accept(adapter);
new MySqlShowContributorsStatement().accept(adapter);
new MySqlShowCreateDatabaseStatement().accept(adapter);
new MySqlShowCreateEventStatement().accept(adapter);
new MySqlShowCreateFunctionStatement().accept(adapter);
new MySqlShowCreateProcedureStatement().accept(adapter);
new MySqlShowCreateTableStatement().accept(adapter);
new MySqlShowCreateTriggerStatement().accept(adapter);
new MySqlShowCreateViewStatement().accept(adapter);
new MySqlShowEngineStatement().accept(adapter);
new MySqlShowEnginesStatement().accept(adapter);
new MySqlShowErrorsStatement().accept(adapter);
new MySqlShowEventsStatement().accept(adapter);
new MySqlShowFunctionCodeStatement().accept(adapter);
new MySqlShowFunctionStatusStatement().accept(adapter);
new MySqlShowGrantsStatement().accept(adapter);
new MySqlUserName().accept(adapter);
new MySqlShowIndexesStatement().accept(adapter);
new MySqlShowKeysStatement().accept(adapter);
new MySqlShowMasterStatusStatement().accept(adapter);
new MySqlShowOpenTablesStatement().accept(adapter);
new MySqlShowBinaryLogsStatement().accept(adapter);
new MySqlShowPluginsStatement().accept(adapter);
new MySqlShowPrivilegesStatement().accept(adapter);
new MySqlShowProcedureCodeStatement().accept(adapter);
new MySqlShowProcedureStatusStatement().accept(adapter);
new MySqlShowProcessListStatement().accept(adapter);
new MySqlShowProfileStatement().accept(adapter);
new MySqlShowSlaveHostsStatement().accept(adapter);
new MySqlShowRelayLogEventsStatement().accept(adapter);
new MySqlShowSlaveStatusStatement().accept(adapter);
new MySqlShowTableStatusStatement().accept(adapter);
new MySqlShowTriggersStatement().accept(adapter);
new MySqlRenameTableStatement().accept(adapter);
new MySqlUnionQuery().accept(adapter);
new MySqlUseIndexHint().accept(adapter);
new MySqlIgnoreIndexHint().accept(adapter);
new MySqlLockTableStatement().accept(adapter);
new MySqlUnlockTablesStatement().accept(adapter);
new MySqlForceIndexHint().accept(adapter);
new MySqlAlterTableChangeColumn().accept(adapter);
new MySqlAlterTableCharacter().accept(adapter);
new MySqlAlterTableOption().accept(adapter);
new MySqlCreateTableStatement().accept(adapter);
new MySqlCharExpr().accept(adapter);
new MySqlUnique().accept(adapter);
new MySqlAlterTableModifyColumn().accept(adapter);
new MySqlAlterTableDiscardTablespace().accept(adapter);
new MySqlAlterTableImportTablespace().accept(adapter);
new TableSpaceOption().accept(adapter);
}
Aggregations