mirror of https://github.com/alibaba/druid.git
Merge 801c32ae58
into c8b12f0701
This commit is contained in:
commit
1dca9ac877
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue