use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement in project druid by alibaba.
the class PGSQLStatementParser method parseWith.
public SQLStatement parseWith() {
PGWithClause with = this.parseWithClause();
if (lexer.token() == Token.INSERT) {
PGInsertStatement stmt = this.parseInsert();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.SELECT) {
PGSelectStatement stmt = this.parseSelect();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.DELETE) {
PGDeleteStatement stmt = this.parseDeleteStatement();
stmt.setWith(with);
return stmt;
}
throw new ParserException("TODO");
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement in project druid by alibaba.
the class PGInsertTest0 method test_1.
public void test_1() {
String sql = "insert into test01 DEFAULT VALUES";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
assertTrue(statemen instanceof PGInsertStatement);
PGInsertStatement insert = (PGInsertStatement) statemen;
assertTrue(insert.getTableName().getSimpleName().equalsIgnoreCase("test01"));
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement in project druid by alibaba.
the class PGSQLStatementParser method parseInsert.
public PGInsertStatement parseInsert() {
PGInsertStatement stmt = new PGInsertStatement();
if (lexer.token() == Token.INSERT) {
lexer.nextToken();
accept(Token.INTO);
SQLName tableName = this.exprParser.name();
stmt.setTableName(tableName);
if (lexer.token() == Token.IDENTIFIER) {
stmt.setAlias(lexer.stringVal());
lexer.nextToken();
}
}
if (lexer.token() == Token.DEFAULT) {
lexer.nextToken();
accept(Token.VALUES);
stmt.setDefaultValues(true);
}
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
this.exprParser.exprList(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}
if (lexer.token() == (Token.VALUES)) {
lexer.nextToken();
for (; ; ) {
accept(Token.LPAREN);
SQLInsertStatement.ValuesClause valuesCaluse = new SQLInsertStatement.ValuesClause();
this.exprParser.exprList(valuesCaluse.getValues(), valuesCaluse);
stmt.addValueCause(valuesCaluse);
accept(Token.RPAREN);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
} else if (lexer.token() == (Token.SELECT)) {
SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
stmt.setQuery(queryExpr.getSubQuery());
}
if (lexer.token() == Token.RETURNING) {
lexer.nextToken();
SQLExpr returning = this.exprParser.expr();
stmt.setReturning(returning);
}
return stmt;
}
Aggregations