mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
insert语句增加default values支持
example: insert into test01 DEFAULT VALUES
This commit is contained in:
+10
-1
@@ -29,6 +29,7 @@ public class PGInsertStatement extends SQLInsertStatement implements PGSQLStatem
|
||||
private PGWithClause with;
|
||||
private List<ValuesClause> valuesList = new ArrayList<ValuesClause>();
|
||||
private SQLExpr returning;
|
||||
private boolean defaultValues = false;
|
||||
|
||||
public SQLExpr getReturning() {
|
||||
return returning;
|
||||
@@ -70,7 +71,15 @@ public class PGInsertStatement extends SQLInsertStatement implements PGSQLStatem
|
||||
valuesList.add(valueClause);
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
public boolean isDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
public void setDefaultValues(boolean defaultValues) {
|
||||
this.defaultValues = defaultValues;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -100,6 +100,12 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DEFAULT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.VALUES);
|
||||
stmt.setDefaultValues(true);
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.PGTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
@@ -51,5 +52,15 @@ public class PGInsertTest0 extends PGTest {
|
||||
// Assert.assertTrue(visitor.getFields().contains(new TableStat.Column("films", "producer_id")));
|
||||
}
|
||||
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user