mirror of https://github.com/alibaba/druid.git
Compare commits
3 Commits
06eac42440
...
d19aebc463
Author | SHA1 | Date |
---|---|---|
|
d19aebc463 | |
|
6024bcf122 | |
|
801c32ae58 |
|
@ -4,6 +4,7 @@ import com.alibaba.druid.DbType;
|
|||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause;
|
||||
|
@ -115,4 +116,7 @@ public class CKStatementParser extends SQLStatementParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
public void parseCreateViewAtDataType(SQLColumnDefinition column, SQLName expr) {
|
||||
column.setDataType(this.exprParser.parseDataType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -820,6 +820,45 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateFunctionStatement x) {
|
||||
boolean create = x.isCreate();
|
||||
if (create) {
|
||||
print0(ucase ? "CREATE " : "create ");
|
||||
|
||||
if (x.isOrReplace()) {
|
||||
print0(ucase ? "OR REPLACE " : "or replace ");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.isTemporary()) {
|
||||
print0(ucase ? "TEMPORARY " : "temporary ");
|
||||
}
|
||||
print0(ucase ? "FUNCTION " : "function ");
|
||||
|
||||
x.getName().accept(this);
|
||||
|
||||
int paramSize = x.getParameters().size();
|
||||
|
||||
print0(" (");
|
||||
this.indentCount++;
|
||||
|
||||
for (int i = 0; i < paramSize; ++i) {
|
||||
if (i != 0) {
|
||||
print0(","); // change: remove extra space
|
||||
println();
|
||||
}
|
||||
SQLParameter param = x.getParameters().get(i);
|
||||
param.accept(this);
|
||||
}
|
||||
|
||||
this.indentCount--;
|
||||
print(')');
|
||||
|
||||
printCreateFunctionBody(x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateUserStatement x) {
|
||||
print0(ucase ? "CREATE USER " : "create user ");
|
||||
|
|
|
@ -12513,7 +12513,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
|||
return;
|
||||
}
|
||||
println();
|
||||
println(ucase ? "AS" : "as");
|
||||
print(ucase ? "AS " : "as ");
|
||||
block.accept(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.alibaba.druid.bvt.sql.postgresql.create_function;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprStatement;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PGCreateFunctionTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
SQLCreateFunctionStatement sqlCreateFunctionStatement = new SQLCreateFunctionStatement();
|
||||
sqlCreateFunctionStatement.setDbType(DbType.postgresql);
|
||||
sqlCreateFunctionStatement.setCreate(true);
|
||||
sqlCreateFunctionStatement.setName(new SQLIdentifierExpr("func1"));
|
||||
SQLBlockStatement sqlBlockStatement = new SQLBlockStatement();
|
||||
sqlCreateFunctionStatement.setBlock(sqlBlockStatement);
|
||||
|
||||
// Set sql block statement
|
||||
SQLExprStatement sqlExprStatement = new SQLExprStatement();
|
||||
sqlExprStatement.setExpr(new SQLNullExpr());
|
||||
sqlExprStatement.setAfterSemi(true);
|
||||
sqlBlockStatement.setHaveBeginEnd(true);
|
||||
sqlBlockStatement.setIsDollarQuoted(true);
|
||||
sqlBlockStatement.setLanguage("plpgsql");
|
||||
List<SQLStatement> sqlExprStatementList = new ArrayList<>();
|
||||
sqlExprStatementList.add(sqlExprStatement);
|
||||
sqlBlockStatement.setStatementList(sqlExprStatementList);
|
||||
|
||||
String sql = sqlCreateFunctionStatement.toString();
|
||||
assertEquals("CREATE FUNCTION func1 ()\n" +
|
||||
"AS $$\n" +
|
||||
"BEGIN\n" +
|
||||
"\tNULL;\n" +
|
||||
"END;\n" +
|
||||
"$$ LANGUAGE plpgsql;", sql);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,12 @@
|
|||
create view test (a uint32) as select a from b
|
||||
--------------------
|
||||
CREATE VIEW test (
|
||||
a uint32
|
||||
)
|
||||
AS
|
||||
SELECT a
|
||||
FROM b
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select
|
||||
/*
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue