-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtestPlpgsql_while.java
More file actions
57 lines (48 loc) · 2.55 KB
/
Copy pathtestPlpgsql_while.java
File metadata and controls
57 lines (48 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package test.postgresql;
/*
* Date: 13-12-4
*/
import gudusoft.gsqlparser.*;
import gudusoft.gsqlparser.stmt.TLoopStmt;
import gudusoft.gsqlparser.stmt.postgresql.TPostgresqlCreateFunction;
import junit.framework.TestCase;
public class testPlpgsql_while extends TestCase {
public void test1(){
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvpostgresql);
sqlparser.sqltext = "CREATE FUNCTION get_available_flightid(date) RETURNS SETOF integer AS\n" +
"$BODY$\n" +
"BEGIN\n" +
"\n" +
"\tWHILE amount_owed > 0 AND gift_certificate_balance > 0 LOOP\n" +
"\t-- some computations here\n" +
"\t\tnull;\n" +
"\tEND LOOP;\n" +
"\t\n" +
"\tWHILE NOT done LOOP\n" +
"\t-- some computations here\n" +
"\t\tnull;\n" +
"\tEND LOOP;\n" +
"\n" +
"END\n" +
"$BODY$\n" +
"LANGUAGE plpgsql;";
assertTrue(sqlparser.parse() == 0);
TPostgresqlCreateFunction createFunction = (TPostgresqlCreateFunction)sqlparser.sqlstatements.get(0);
assertTrue(createFunction.getBodyStatements().size() == 2);
TCustomSqlStatement stmt = createFunction.getBodyStatements().get(0);
assertTrue(stmt.sqlstatementtype == ESqlStatementType.sst_loopstmt);
TLoopStmt loopStmt = (TLoopStmt)stmt;
assertTrue(loopStmt.getKind() == TLoopStmt.while_loop);
assertTrue(loopStmt.getCondition().getExpressionType() == EExpressionType.logical_and_t);
assertTrue(loopStmt.getCondition().getLeftOperand().toString().equalsIgnoreCase("amount_owed > 0"));
assertTrue(loopStmt.getCondition().getRightOperand().toString().equalsIgnoreCase("gift_certificate_balance > 0"));
assertTrue(loopStmt.getBodyStatements().size() == 1);
assertTrue(loopStmt.getBodyStatements().get(0).sqlstatementtype == ESqlStatementType.sstplsql_nullstmt);
stmt = createFunction.getBodyStatements().get(1);
assertTrue(stmt.sqlstatementtype == ESqlStatementType.sst_loopstmt);
loopStmt = (TLoopStmt)stmt;
assertTrue(loopStmt.getKind() == TLoopStmt.while_loop);
assertTrue(loopStmt.getCondition().getExpressionType() == EExpressionType.logical_not_t);
assertTrue(loopStmt.getCondition().getRightOperand().toString().equalsIgnoreCase("done"));
}
}