9
9
*/
10
10
package net .sf .jsqlparser .parser ;
11
11
12
+ import java .io .ByteArrayInputStream ;
13
+ import java .io .StringReader ;
14
+ import java .nio .charset .StandardCharsets ;
15
+ import java .util .ArrayList ;
16
+ import java .util .List ;
12
17
import net .sf .jsqlparser .JSQLParserException ;
13
18
import net .sf .jsqlparser .expression .Expression ;
14
19
import net .sf .jsqlparser .expression .LongValue ;
15
20
import net .sf .jsqlparser .expression .Parenthesis ;
16
21
import net .sf .jsqlparser .expression .operators .arithmetic .Addition ;
17
22
import net .sf .jsqlparser .expression .operators .arithmetic .Multiplication ;
18
23
import net .sf .jsqlparser .schema .Column ;
24
+ import net .sf .jsqlparser .statement .Statement ;
19
25
import net .sf .jsqlparser .statement .Statements ;
20
26
import org .junit .After ;
21
27
import org .junit .AfterClass ;
22
28
import static org .junit .Assert .*;
23
-
24
- import java .io .ByteArrayInputStream ;
25
- import java .io .StringReader ;
26
- import java .nio .charset .StandardCharsets ;
27
-
28
29
import org .junit .Before ;
29
30
import org .junit .BeforeClass ;
30
31
import org .junit .Test ;
@@ -81,12 +82,12 @@ public void testParseExpressionNonPartial() throws Exception {
81
82
82
83
@ Test (expected = JSQLParserException .class )
83
84
public void testParseExpressionFromStringFail () throws Exception {
84
- CCJSqlParserUtil .parse ("whatever$" );
85
+ CCJSqlParserUtil .parse ("whatever$" );
85
86
}
86
87
87
88
@ Test (expected = JSQLParserException .class )
88
89
public void testParseExpressionFromRaderFail () throws Exception {
89
- CCJSqlParserUtil .parse (new StringReader ("whatever$" ));
90
+ CCJSqlParserUtil .parse (new StringReader ("whatever$" ));
90
91
}
91
92
92
93
@ Test
@@ -103,19 +104,19 @@ public void testParseCondExpression() throws Exception {
103
104
104
105
@ Test (expected = JSQLParserException .class )
105
106
public void testParseCondExpressionFail () throws Exception {
106
- CCJSqlParserUtil .parseCondExpression (";" );
107
+ CCJSqlParserUtil .parseCondExpression (";" );
107
108
108
109
}
109
110
110
111
@ Test (expected = JSQLParserException .class )
111
112
public void testParseFromStreamFail () throws Exception {
112
- CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )));
113
+ CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )));
113
114
114
115
}
115
116
116
117
@ Test (expected = JSQLParserException .class )
117
118
public void testParseFromStreamWithEncodingFail () throws Exception {
118
- CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )), StandardCharsets .UTF_8 .name ());
119
+ CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )), StandardCharsets .UTF_8 .name ());
119
120
120
121
}
121
122
@@ -160,14 +161,36 @@ public void testParseStatementsIssue691() throws Exception {
160
161
+ "SELECT * FROM dual;\n " , result .toString ());
161
162
}
162
163
164
+ @ Test
165
+ public void testStreamStatementsIssue777 () throws Exception {
166
+ final List <Statement > list = new ArrayList <>();
167
+
168
+ CCJSqlParserUtil .streamStatements (new StatementListener () {
169
+ @ Override
170
+ public void accept (Statement statement ) {
171
+ list .add (statement );
172
+ }
173
+ }, new ByteArrayInputStream (("select * from dual;\n "
174
+ + "select\n "
175
+ + "*\n "
176
+ + "from\n "
177
+ + "dual;\n "
178
+ + "\n "
179
+ + "-- some comment\n "
180
+ + "select *\n "
181
+ + "from dual;" ).getBytes (StandardCharsets .UTF_8 )), "UTF-8" );
182
+
183
+ assertEquals (list .size (), 3 );
184
+ }
185
+
163
186
@ Test (expected = JSQLParserException .class )
164
187
public void testParseStatementsFail () throws Exception {
165
- CCJSqlParserUtil .parseStatements ("select * from dual;WHATEVER!!" );
188
+ CCJSqlParserUtil .parseStatements ("select * from dual;WHATEVER!!" );
166
189
}
167
190
168
191
@ Test (expected = JSQLParserException .class )
169
192
public void testParseASTFail () throws Exception {
170
- CCJSqlParserUtil .parseAST ("select * from dual;WHATEVER!!" );
193
+ CCJSqlParserUtil .parseAST ("select * from dual;WHATEVER!!" );
171
194
}
172
195
173
196
@ Test
@@ -180,14 +203,14 @@ public void testParseStatementsIssue691_2() throws Exception {
180
203
181
204
@ Test
182
205
public void testParseStatementIssue742 () throws Exception {
183
- Statements result = CCJSqlParserUtil .parseStatements ("CREATE TABLE `table_name` (\n " +
184
- " `id` bigint(20) NOT NULL AUTO_INCREMENT,\n " +
185
- " `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n " +
186
- " PRIMARY KEY (`id`),\n " +
187
- " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n " +
188
- ")" );
189
- assertEquals ("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` " +
190
- "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` " +
191
- "(`another_column_id`));\n " , result .toString ());
206
+ Statements result = CCJSqlParserUtil .parseStatements ("CREATE TABLE `table_name` (\n "
207
+ + " `id` bigint(20) NOT NULL AUTO_INCREMENT,\n "
208
+ + " `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n "
209
+ + " PRIMARY KEY (`id`),\n "
210
+ + " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n "
211
+ + ")" );
212
+ assertEquals ("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` "
213
+ + "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` "
214
+ + "(`another_column_id`));\n " , result .toString ());
192
215
}
193
216
}
0 commit comments