• R/O
  • SSH
  • HTTPS

dbviewer: コミット


コミットメタ情報

リビジョン243 (tree)
日時2010-10-08 16:48:11
作者zigen

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_2.java (nonexistent)
+++ SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_2.java (revision 243)
@@ -0,0 +1,85 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.sql.parser;
7+
8+import junit.framework.TestCase;
9+import kry.sql.format.SqlFormatRule;
10+import zigen.sql.parser.ASTVisitorToString;
11+import zigen.sql.parser.INode;
12+import zigen.sql.parser.ISqlParser;
13+import zigen.sql.parser.Node;
14+import zigen.sql.parser.SqlParser;
15+import zigen.sql.parser.exception.ParserException;
16+
17+public class TestWithForDB2_2 extends TestCase {
18+ private void check(String in, String out) {
19+ try {
20+
21+ ISqlParser parser = new SqlParser(in, new SqlFormatRule());
22+ INode node = new Node("root");
23+ parser.parse(node);
24+
25+ ASTVisitorToString visitor = new ASTVisitorToString();
26+ node.accept(visitor, null);
27+ visitor.print();
28+ FileUtil.writeXml(getClass().getName(), parser.dumpXml(node));
29+ assertEquals(out, parser.dump(node));
30+ } catch (ParserException e) {
31+ e.printStackTrace();
32+ fail();
33+ }
34+ }
35+
36+ public void test1() {
37+ StringBuffer in = new StringBuffer();
38+ in.append("SELECT count(1) FROM syscat.SCHEMATA s JOIN syscat.tables t ON s.SCHEMANAME = t.TABSCHEMA ");
39+ in.append("WHERE s.SCHEMANAME = 'SYSCAT '");
40+
41+
42+ StringBuffer sb = new StringBuffer();
43+ sb.append("<Node text=\"root\">").append("\r\n");
44+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
45+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
46+ sb.append(" <ASTFunction text=\"count\">").append("\r\n");
47+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
48+ sb.append(" <ASTValue text=\"1\" />").append("\r\n");
49+ sb.append(" </ASTParentheses>").append("\r\n");
50+ sb.append(" </ASTFunction>").append("\r\n");
51+ sb.append(" </ASTSelect>").append("\r\n");
52+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
53+ sb.append(" <ASTTable text=\"syscat.SCHEMATA AS s\">").append("\r\n");
54+ sb.append(" <ASTInnerAlias text=\"s\" />").append("\r\n");
55+ sb.append(" </ASTTable>").append("\r\n");
56+ sb.append(" <ASTJoin text=\"JOIN\" />").append("\r\n");
57+ sb.append(" <ASTTable text=\"syscat.tables AS t\">").append("\r\n");
58+ sb.append(" <ASTInnerAlias text=\"t\" />").append("\r\n");
59+ sb.append(" </ASTTable>").append("\r\n");
60+ sb.append(" <ASTOn text=\"ON\" />").append("\r\n");
61+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
62+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
63+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
64+ sb.append(" <ASTColumn text=\"t.TABSCHEMA\" />").append("\r\n");
65+ sb.append(" </ASTOperator>").append("\r\n");
66+ sb.append(" </ASTExpression>").append("\r\n");
67+ sb.append(" </ASTFrom>").append("\r\n");
68+ sb.append(" <ASTWhere text=\"where\">").append("\r\n");
69+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
70+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
71+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
72+ sb.append(" <ASTValue text=\"'SYSCAT '\" />").append("\r\n");
73+ sb.append(" </ASTOperator>").append("\r\n");
74+ sb.append(" </ASTExpression>").append("\r\n");
75+ sb.append(" </ASTWhere>").append("\r\n");
76+ sb.append(" </ASTSelectStatement>").append("\r\n");
77+ sb.append("</Node>").append("\r\n");
78+
79+ check(in.toString(), sb.toString());
80+
81+ }
82+
83+
84+
85+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- SQL Parser/trunk/src/test/java/zigen/sql/parser/TestBind.java (revision 242)
+++ SQL Parser/trunk/src/test/java/zigen/sql/parser/TestBind.java (revision 243)
@@ -87,5 +87,49 @@
8787
8888 check(in.toString(), sb.toString());
8989
90+ }
91+
92+ private void check2(String in, String out) {
93+ try {
94+
95+ ISqlParser parser = new SqlParser(in, new SqlFormatRule());
96+ INode node = new Node("root");
97+ parser.parse(node);
98+ ASTVisitorToBind visitor = new ASTVisitorToBind();
99+ node.accept(visitor, null);
100+ visitor.print();
101+
102+ } catch (ParserException e) {
103+ e.printStackTrace();
104+ fail();
105+ }
106+ }
107+
108+ public void test3() {
109+ StringBuffer in = new StringBuffer();
110+ in.append(" SELECT :P1 FROM :P2 WHERE COL1 = :P3");
111+
112+ StringBuffer sb = new StringBuffer();
113+ sb.append("<Node text=\"root\">\r\n");
114+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">\r\n");
115+ sb.append(" <ASTSelect text=\"select\">\r\n");
116+ sb.append(" <ASTBind text=\":P1\" />\r\n");
117+ sb.append(" </ASTSelect>\r\n");
118+ sb.append(" <ASTFrom text=\"from\">\r\n");
119+ sb.append(" <ASTBind text=\":P2\" />\r\n");
120+ sb.append(" </ASTFrom>\r\n");
121+ sb.append(" <ASTWhere text=\"where\">\r\n");
122+ sb.append(" <ASTExpression text=\"expression\">\r\n");
123+ sb.append(" <ASTOperator text=\"=\">\r\n");
124+ sb.append(" <ASTColumn text=\"COL1\" />\r\n");
125+ sb.append(" <ASTBind text=\":P3\" />\r\n");
126+ sb.append(" </ASTOperator>\r\n");
127+ sb.append(" </ASTExpression>\r\n");
128+ sb.append(" </ASTWhere>\r\n");
129+ sb.append(" </ASTSelectStatement>\r\n");
130+ sb.append("</Node>\r\n");
131+
132+ check2(in.toString(), sb.toString());
133+
90134 }
91135 }
--- SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_1.java (nonexistent)
+++ SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_1.java (revision 243)
@@ -0,0 +1,120 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.sql.parser;
7+
8+import junit.framework.TestCase;
9+import kry.sql.format.SqlFormatRule;
10+import zigen.sql.parser.ASTVisitorToString;
11+import zigen.sql.parser.INode;
12+import zigen.sql.parser.ISqlParser;
13+import zigen.sql.parser.Node;
14+import zigen.sql.parser.SqlParser;
15+import zigen.sql.parser.exception.ParserException;
16+
17+public class TestWithForDB2_1 extends TestCase {
18+ private void check(String in, String out) {
19+ try {
20+
21+ ISqlParser parser = new SqlParser(in, new SqlFormatRule());
22+ INode node = new Node("root");
23+ parser.parse(node);
24+
25+ ASTVisitorToString visitor = new ASTVisitorToString();
26+ node.accept(visitor, null);
27+ visitor.print();
28+ FileUtil.writeXml(getClass().getName(), parser.dumpXml(node));
29+ assertEquals(out, parser.dump(node));
30+ } catch (ParserException e) {
31+ e.printStackTrace();
32+ fail();
33+ }
34+ }
35+
36+ public void test1() {
37+ StringBuffer in = new StringBuffer();
38+ // in.append("with tmp_table as (");
39+ in.append("SELECT");
40+ in.append(" CASE");
41+ in.append(" WHEN (");
42+ // in.append(" 1 = (2)");
43+ in.append(" 1 = (");
44+ in.append(" SELECT 1 FROM syscat.SCHEMATA s JOIN syscat.tables t ON s.SCHEMANAME = t.TABSCHEMA ");
45+ in.append(" WHERE s.SCHEMANAME = 'SYSCAT '");
46+ in.append(" )");
47+ in.append(" ) THEN 'A' ");
48+ in.append(" ELSE 'B' ");
49+ in.append(" END AS dummy_value");
50+ in.append(" FROM");
51+ in.append(" syscat.SCHEMATA");
52+ // in.append(")");
53+ // in.append("select * from tmp_table");
54+
55+ StringBuffer sb = new StringBuffer();
56+ sb.append("<Node text=\"root\">").append("\r\n");
57+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
58+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
59+ sb.append(" <ASTCaseCause text=\"dummy_value\">").append("\r\n");
60+ sb.append(" <ASTCase text=\"case\" />").append("\r\n");
61+ sb.append(" <ASTWhen text=\"when\">").append("\r\n");
62+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
63+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
64+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
65+ sb.append(" <ASTValue text=\"1\" />").append("\r\n");
66+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
67+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
68+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
69+ sb.append(" <ASTValue text=\"1\" />").append("\r\n");
70+ sb.append(" </ASTSelect>").append("\r\n");
71+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
72+ sb.append(" <ASTTable text=\"syscat.SCHEMATA AS s\">").append("\r\n");
73+ sb.append(" <ASTInnerAlias text=\"s\" />").append("\r\n");
74+ sb.append(" </ASTTable>").append("\r\n");
75+ sb.append(" <ASTJoin text=\"JOIN\" />").append("\r\n");
76+ sb.append(" <ASTTable text=\"syscat.tables AS t\">").append("\r\n");
77+ sb.append(" <ASTInnerAlias text=\"t\" />").append("\r\n");
78+ sb.append(" </ASTTable>").append("\r\n");
79+ sb.append(" <ASTOn text=\"ON\" />").append("\r\n");
80+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
81+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
82+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
83+ sb.append(" <ASTColumn text=\"t.TABSCHEMA\" />").append("\r\n");
84+ sb.append(" </ASTOperator>").append("\r\n");
85+ sb.append(" </ASTExpression>").append("\r\n");
86+ sb.append(" </ASTFrom>").append("\r\n");
87+ sb.append(" <ASTWhere text=\"where\">").append("\r\n");
88+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
89+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
90+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
91+ sb.append(" <ASTValue text=\"'SYSCAT '\" />").append("\r\n");
92+ sb.append(" </ASTOperator>").append("\r\n");
93+ sb.append(" </ASTExpression>").append("\r\n");
94+ sb.append(" </ASTWhere>").append("\r\n");
95+ sb.append(" </ASTSelectStatement>").append("\r\n");
96+ sb.append(" </ASTParentheses>").append("\r\n");
97+ sb.append(" </ASTOperator>").append("\r\n");
98+ sb.append(" </ASTExpression>").append("\r\n");
99+ sb.append(" </ASTParentheses>").append("\r\n");
100+ sb.append(" </ASTWhen>").append("\r\n");
101+ sb.append(" <ASTThen text=\"then\">").append("\r\n");
102+ sb.append(" <ASTValue text=\"'A'\" />").append("\r\n");
103+ sb.append(" </ASTThen>").append("\r\n");
104+ sb.append(" <ASTElse text=\"else\">").append("\r\n");
105+ sb.append(" <ASTValue text=\"'B'\" />").append("\r\n");
106+ sb.append(" </ASTElse>").append("\r\n");
107+ sb.append(" <ASTInnerAlias text=\"dummy_value\" />").append("\r\n");
108+ sb.append(" </ASTCaseCause>").append("\r\n");
109+ sb.append(" </ASTSelect>").append("\r\n");
110+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
111+ sb.append(" <ASTTable text=\"syscat.SCHEMATA\" />").append("\r\n");
112+ sb.append(" </ASTFrom>").append("\r\n");
113+ sb.append(" </ASTSelectStatement>").append("\r\n");
114+ sb.append("</Node>").append("\r\n");
115+
116+ check(in.toString(), sb.toString());
117+
118+ }
119+
120+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_3.java (nonexistent)
+++ SQL Parser/trunk/src/test/java/zigen/sql/parser/TestWithForDB2_3.java (revision 243)
@@ -0,0 +1,131 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.sql.parser;
7+
8+import junit.framework.TestCase;
9+import kry.sql.format.SqlFormatRule;
10+import zigen.sql.parser.ASTVisitorToString;
11+import zigen.sql.parser.INode;
12+import zigen.sql.parser.ISqlParser;
13+import zigen.sql.parser.Node;
14+import zigen.sql.parser.SqlParser;
15+import zigen.sql.parser.exception.ParserException;
16+
17+public class TestWithForDB2_3 extends TestCase {
18+ private void check(String in, String out) {
19+ try {
20+
21+ ISqlParser parser = new SqlParser(in, new SqlFormatRule());
22+ INode node = new Node("root");
23+ parser.parse(node);
24+
25+ ASTVisitorToString visitor = new ASTVisitorToString();
26+ node.accept(visitor, null);
27+ visitor.print();
28+ FileUtil.writeXml(getClass().getName(), parser.dumpXml(node));
29+ assertEquals(out, parser.dump(node));
30+ } catch (ParserException e) {
31+ e.printStackTrace();
32+ fail();
33+ }
34+ }
35+
36+ public void test1() {
37+ StringBuffer in = new StringBuffer();
38+ in.append("with tmp_table as (");
39+ in.append("SELECT");
40+ in.append(" CASE");
41+ in.append(" WHEN (");
42+ in.append(" 1 = (");
43+ in.append(" SELECT 1 FROM syscat.SCHEMATA s JOIN syscat.tables t ON s.SCHEMANAME = t.TABSCHEMA ");
44+ in.append(" WHERE s.SCHEMANAME = 'SYSCAT '");
45+ in.append(" )");
46+ in.append(" ) THEN 'A' ");
47+ in.append(" ELSE 'B' ");
48+ in.append(" END AS dummy_value");
49+ in.append(" FROM");
50+ in.append(" syscat.SCHEMATA");
51+ in.append(")");
52+ in.append("select * from tmp_table");
53+
54+ StringBuffer sb = new StringBuffer();
55+ sb.append("<Node text=\"root\">").append("\r\n");
56+ sb.append(" <ASTKeyword text=\"with\" />").append("\r\n");
57+ sb.append(" <ASTColumn text=\"tmp_table\" />").append("\r\n");
58+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
59+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
60+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
61+ sb.append(" <ASTCaseCause text=\"dummy_value\">").append("\r\n");
62+ sb.append(" <ASTCase text=\"case\" />").append("\r\n");
63+ sb.append(" <ASTWhen text=\"when\">").append("\r\n");
64+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
65+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
66+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
67+ sb.append(" <ASTValue text=\"1\" />").append("\r\n");
68+ sb.append(" <ASTParentheses text=\"\">").append("\r\n");
69+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
70+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
71+ sb.append(" <ASTValue text=\"1\" />").append("\r\n");
72+ sb.append(" </ASTSelect>").append("\r\n");
73+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
74+ sb.append(" <ASTTable text=\"syscat.SCHEMATA AS s\">").append("\r\n");
75+ sb.append(" <ASTInnerAlias text=\"s\" />").append("\r\n");
76+ sb.append(" </ASTTable>").append("\r\n");
77+ sb.append(" <ASTJoin text=\"JOIN\" />").append("\r\n");
78+ sb.append(" <ASTTable text=\"syscat.tables AS t\">").append("\r\n");
79+ sb.append(" <ASTInnerAlias text=\"t\" />").append("\r\n");
80+ sb.append(" </ASTTable>").append("\r\n");
81+ sb.append(" <ASTOn text=\"ON\" />").append("\r\n");
82+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
83+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
84+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
85+ sb.append(" <ASTColumn text=\"t.TABSCHEMA\" />").append("\r\n");
86+ sb.append(" </ASTOperator>").append("\r\n");
87+ sb.append(" </ASTExpression>").append("\r\n");
88+ sb.append(" </ASTFrom>").append("\r\n");
89+ sb.append(" <ASTWhere text=\"where\">").append("\r\n");
90+ sb.append(" <ASTExpression text=\"expression\">").append("\r\n");
91+ sb.append(" <ASTOperator text=\"=\">").append("\r\n");
92+ sb.append(" <ASTColumn text=\"s.SCHEMANAME\" />").append("\r\n");
93+ sb.append(" <ASTValue text=\"'SYSCAT '\" />").append("\r\n");
94+ sb.append(" </ASTOperator>").append("\r\n");
95+ sb.append(" </ASTExpression>").append("\r\n");
96+ sb.append(" </ASTWhere>").append("\r\n");
97+ sb.append(" </ASTSelectStatement>").append("\r\n");
98+ sb.append(" </ASTParentheses>").append("\r\n");
99+ sb.append(" </ASTOperator>").append("\r\n");
100+ sb.append(" </ASTExpression>").append("\r\n");
101+ sb.append(" </ASTParentheses>").append("\r\n");
102+ sb.append(" </ASTWhen>").append("\r\n");
103+ sb.append(" <ASTThen text=\"then\">").append("\r\n");
104+ sb.append(" <ASTValue text=\"'A'\" />").append("\r\n");
105+ sb.append(" </ASTThen>").append("\r\n");
106+ sb.append(" <ASTElse text=\"else\">").append("\r\n");
107+ sb.append(" <ASTValue text=\"'B'\" />").append("\r\n");
108+ sb.append(" </ASTElse>").append("\r\n");
109+ sb.append(" <ASTInnerAlias text=\"dummy_value\" />").append("\r\n");
110+ sb.append(" </ASTCaseCause>").append("\r\n");
111+ sb.append(" </ASTSelect>").append("\r\n");
112+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
113+ sb.append(" <ASTTable text=\"syscat.SCHEMATA\" />").append("\r\n");
114+ sb.append(" </ASTFrom>").append("\r\n");
115+ sb.append(" </ASTSelectStatement>").append("\r\n");
116+ sb.append(" </ASTParentheses>").append("\r\n");
117+ sb.append(" <ASTSelectStatement text=\"SelectStatement\">").append("\r\n");
118+ sb.append(" <ASTSelect text=\"select\">").append("\r\n");
119+ sb.append(" <ASTColumn text=\"*\" />").append("\r\n");
120+ sb.append(" </ASTSelect>").append("\r\n");
121+ sb.append(" <ASTFrom text=\"from\">").append("\r\n");
122+ sb.append(" <ASTTable text=\"tmp_table\" />").append("\r\n");
123+ sb.append(" </ASTFrom>").append("\r\n");
124+ sb.append(" </ASTSelectStatement>").append("\r\n");
125+ sb.append("</Node>").append("\r\n");
126+
127+ check(in.toString(), sb.toString());
128+
129+ }
130+
131+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorToString.java (revision 242)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorToString.java (revision 243)
@@ -80,7 +80,7 @@
8080 } else if (node instanceof ASTOperator) {
8181
8282 ASTOperator ope = (ASTOperator) node;
83- if (ope.hasReftChild()) {
83+ if (ope.hasRightChild()) {
8484
8585 node.getChild(0).accept(this, null);
8686 sb.append(node.getName() + " ");
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorPrint.java (revision 242)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorPrint.java (revision 243)
@@ -72,7 +72,7 @@
7272 } else if (node instanceof ASTOperator) {
7373
7474 ASTOperator ope = (ASTOperator) node;
75- if (ope.hasReftChild()) {
75+ if (ope.hasRightChild()) {
7676
7777 node.getChild(0).accept(this, null);
7878 sb.append(node.getName() + " ");
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/Node.java (revision 242)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/Node.java (revision 243)
@@ -306,7 +306,11 @@
306306
307307 private ASTExpression getASTExpression(INode node) throws ParserException {
308308 if (node instanceof ASTExpression) {
309- return (ASTExpression) node;
309+ return (ASTExpression) node;
310+// <-- do not get over Statement
311+ } else if(node instanceof ASTStatement){
312+ return null;
313+// -->
310314 } else {
311315 if (node.getParent() != null) {
312316 return getASTExpression(node.getParent());
@@ -322,7 +326,7 @@
322326
323327 private ASTAlias getASTAlias(INode node) throws ParserException {
324328 if (node instanceof ASTAlias) {
325- return (ASTAlias) node;
329+ return (ASTAlias) node;
326330 } else {
327331 if (node.getParent() != null) {
328332 return getASTAlias(node.getParent());
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/ast/ASTWith.java (nonexistent)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/ast/ASTWith.java (revision 243)
@@ -0,0 +1,21 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.sql.parser.ast;
7+
8+import zigen.sql.parser.ASTVisitor;
9+
10+
11+
12+public class ASTWith extends ASTKeyword {
13+
14+ public ASTWith(int offset, int length, int scope) {
15+ super("with", offset, length, scope);
16+ }
17+
18+ public Object accept(ASTVisitor visitor, Object data) {
19+ return visitor.visit(this, data);
20+ }
21+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/ast/ASTOperator.java (revision 242)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/ast/ASTOperator.java (revision 243)
@@ -64,7 +64,7 @@
6464 children = new ArrayList();
6565 }
6666
67- if (hasReftChild()) {
67+ if (hasRightChild()) {
6868
6969 System.err.println(n.getName() + ", " + n.getClass().getName());
7070
@@ -83,7 +83,7 @@
8383 return (children != null && children.size() >= 1);
8484 }
8585
86- public boolean hasReftChild() {
86+ public boolean hasRightChild() {
8787 return (children != null && children.size() == 2);
8888 }
8989
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorToBind.java (nonexistent)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/ASTVisitorToBind.java (revision 243)
@@ -0,0 +1,79 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.sql.parser;
7+
8+import java.util.ArrayList;
9+import java.util.Iterator;
10+import java.util.List;
11+
12+import zigen.sql.parser.ast.ASTAlias;
13+import zigen.sql.parser.ast.ASTBind;
14+import zigen.sql.parser.ast.ASTCaseCause;
15+import zigen.sql.parser.ast.ASTExpression;
16+import zigen.sql.parser.ast.ASTFunction;
17+import zigen.sql.parser.ast.ASTInnerAlias;
18+import zigen.sql.parser.ast.ASTOperator;
19+import zigen.sql.parser.ast.ASTOutfile;
20+import zigen.sql.parser.ast.ASTParentheses;
21+import zigen.sql.parser.ast.ASTRoot;
22+import zigen.sql.parser.ast.ASTSelectStatement;
23+import zigen.sql.parser.ast.ASTTable;
24+
25+public class ASTVisitorToBind implements IVisitor {
26+
27+ List list = null;
28+
29+ boolean isShowAs = false;
30+
31+ public ASTVisitorToBind(){
32+ }
33+
34+
35+ public INode findNode(int offset) {
36+ throw new UnsupportedOperationException("UnSupported Method");
37+ }
38+
39+ public int getIndex() {
40+ throw new UnsupportedOperationException("UnSupported Method");
41+ }
42+
43+
44+ public Object visit(INode node, Object data) {
45+ if (node instanceof ASTBind) {
46+ if(list == null){
47+ list = new ArrayList();
48+ }
49+ list.add(node);
50+ }
51+ node.childrenAccept(this, data);
52+ return data;
53+ }
54+
55+ public String toString() {
56+ StringBuffer sb = new StringBuffer();
57+ if(list != null){
58+ int i = 0;
59+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
60+ ASTBind bind = (ASTBind) iterator.next();
61+ if(i > 0){
62+ sb.append(", ");
63+ }
64+ sb.append(bind.toString());
65+ i++;
66+ }
67+ }
68+ return sb.toString();
69+ }
70+
71+ public void print(){
72+ if(list != null){
73+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
74+ ASTBind bind = (ASTBind) iterator.next();
75+ System.out.println(bind.toString());
76+ }
77+ }
78+ }
79+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- SQL Parser/trunk/src/main/java/zigen/sql/parser/SqlParser.java (revision 242)
+++ SQL Parser/trunk/src/main/java/zigen/sql/parser/SqlParser.java (revision 243)
@@ -55,6 +55,7 @@
5555 import zigen.sql.parser.ast.ASTValues;
5656 import zigen.sql.parser.ast.ASTWhen;
5757 import zigen.sql.parser.ast.ASTWhere;
58+import zigen.sql.parser.ast.ASTWith;
5859 import zigen.sql.parser.exception.LoopException;
5960 import zigen.sql.parser.exception.ParserException;
6061 import zigen.sql.parser.exception.UnexpectedTokenException;
@@ -216,6 +217,14 @@
216217 parseFromClause(from);
217218 return;
218219
220+ // Support With for DB2
221+// } else if("with".equalsIgnoreCase(getToken())){
222+// //INode last = node.getLastChild();
223+// ASTWith with = new ASTWith(offset, length, scope);
224+// node.addChildToStatement(with);
225+// parseWithClause(with);
226+// return;
227+
219228 } else if ("order by".equalsIgnoreCase(getToken())) {
220229 scope = SCOPE_BY;
221230
@@ -329,9 +338,15 @@
329338 scope = SCOPE_FROM;
330339 node.addChild(new ASTJoin(getToken(), offset, length, scope));
331340
341+ } else if ("JOIN".equalsIgnoreCase(getToken())) {
342+ scope = SCOPE_FROM;
343+ node.addChild(new ASTJoin(getToken(), offset, length, scope));
344+
345+
332346 } else if ("on".equalsIgnoreCase(getToken())) {
333- scope = SCOPE_WHERE;
334- node.addChild(new ASTOn(getToken(), offset, length, scope));
347+ //scope = SCOPE_WHERE;
348+ ASTOn on = new ASTOn(getToken(), offset, length, scope);
349+ node.addChild(on);
335350
336351
337352 } else if("over".equalsIgnoreCase(getToken())){
@@ -340,6 +355,7 @@
340355 node.addChild(over);
341356 parse(over);
342357
358+
343359 } else {
344360 if (node instanceof ASTOperator) {
345361 tokenizer.pushBack();
@@ -600,7 +616,6 @@
600616 break;
601617
602618 } else {
603- // �֐��̏ꍇ��l������
604619 if (token.getSubType() == TokenUtil.SUBTYPE_KEYWORD_FUNCTION) {
605620 ASTFunction col = new ASTFunction(getToken(), offset, length, scope);
606621 node.addChild(col);
@@ -617,6 +632,89 @@
617632
618633 }
619634
635+ protected void parseWithClause(ASTWith node) throws ParserException {
636+ for (;;) {
637+ if(isCanceled()) return;
638+
639+ switch (nextToken()) {
640+ case TokenUtil.TYPE_END_SQL:
641+ return;
642+
643+ case TokenUtil.TYPE_SYMBOL:
644+ if (")".equals(getToken())) {
645+ ASTParentheses begin = node.getASTParentheses();
646+ begin.setEndOffset(offset);
647+ scope = begin.getScope();
648+ parse(begin.getParent());
649+ return;
650+ } else if ("(".equals(getToken())) {
651+ ASTParentheses p = new ASTParentheses(offset, length, scope);
652+ node.addChild(p);
653+ parse(p);
654+ break;
655+ } else if (",".equals(getToken())) {
656+ node.addChild(new ASTComma(offset, length, scope));
657+ }
658+ break;
659+
660+ case TokenUtil.TYPE_NAME:
661+ INode lastNode = node.getLastChild();
662+ if (lastNode instanceof ASTAlias) {
663+ ((ASTAlias) lastNode).setAliasName(getToken(), offset, length);
664+ } else {
665+ ASTTable table = new ASTTable(getToken(), offset, length, scope);
666+ node.addChild(table);
667+ }
668+ break;
669+
670+ case TokenUtil.TYPE_VALUE:
671+ INode lastNode2 = node.getLastChild();
672+ if (lastNode2 instanceof ASTAlias) {
673+ ((ASTAlias) lastNode2).setAliasName(getToken(), offset, length);
674+ } else {
675+ parseValue(node);
676+ }
677+
678+ break;
679+
680+ case TokenUtil.TYPE_KEYWORD:
681+ if("as".equalsIgnoreCase(getToken())){
682+ node.addChild(new ASTKeyword("as", offset, length, scope));
683+ break;
684+
685+ }else if("select".equalsIgnoreCase(getToken())){
686+ scope = SCOPE_SELECT;
687+
688+ INode last = node.getLastChild();
689+ if (last instanceof ASTUnion) {
690+ ASTSelectStatement ss = new ASTSelectStatement(offset, length, scope);
691+ ASTSelect select = new ASTSelect(offset, length, scope);
692+ ss.addChild(select);
693+ last.getParent().addChild(ss);
694+ parseSelectStatement(select);
695+ break;
696+ } else {
697+
698+ ASTSelectStatement ss = new ASTSelectStatement(offset, length, scope);
699+ ASTSelect select = new ASTSelect(offset, length, scope);
700+ ss.addChild(select);
701+ node.addChild(ss);
702+ parseSelectStatement(select);
703+ break;
704+ }
705+ } else {
706+ tokenizer.pushBack();
707+ parse(node);
708+ return;
709+ }
710+ default:
711+ break;
712+ }
713+ }
714+
715+ }
716+
717+
620718 protected void parseFromClause(ASTFrom node) throws ParserException {
621719 for (;;) {
622720 if(isCanceled()) return;
@@ -1337,6 +1435,7 @@
13371435
13381436 protected String getToken() {
13391437 // return token.getOriginal();
1438+ System.out.println(token.getCustom());
13401439 return token.getCustom();
13411440 }
13421441
@@ -1419,7 +1518,7 @@
14191518 parseExpression(node);
14201519 return;
14211520
1422- } else {
1521+ } else {
14231522 ASTExpression exp1 = node.getASTExpression();
14241523 if (exp1 != null) {
14251524 tokenizer.pushBack();
@@ -1434,7 +1533,7 @@
14341533 case TokenUtil.TYPE_NAME:
14351534 if (node instanceof ASTOperator) {
14361535 ASTOperator ope = (ASTOperator) node;
1437- if (ope.hasReftChild()) {
1536+ if (ope.hasRightChild()) {
14381537 ASTExpression exp = ope.getASTExpression();
14391538 exp.setAliasName(getToken(), offset, length);
14401539 parse(exp.getParent());
@@ -1458,6 +1557,7 @@
14581557
14591558 case TokenUtil.TYPE_OPERATOR:
14601559 ASTOperator ope = new ASTOperator(getToken(), offset, length, scope);
1560+
14611561 INode lastNode = node.getLastChild();
14621562 if (lastNode instanceof ASTCase || lastNode instanceof ASTWhen || lastNode instanceof ASTThen || lastNode instanceof ASTElse) {
14631563 tokenizer.pushBack();
@@ -1477,6 +1577,11 @@
14771577 parseExpression(changeNode(p.getASTFunction(), ope));
14781578
14791579 } else if (lastNode instanceof ASTColumn || lastNode instanceof ASTValue || lastNode instanceof ASTFunction || lastNode instanceof ASTParentheses) {
1580+
1581+ if(node.getParent() instanceof ASTExpression){
1582+
1583+ }
1584+
14801585 ASTExpression exp = node.getASTExpression();
14811586 if (exp == null) {
14821587 exp = new ASTExpression(offset, length, scope);
旧リポジトリブラウザで表示