File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/truncate Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 31
31
public class Truncate implements Statement {
32
32
33
33
private Table table ;
34
+ boolean cascade ; // to support TRUNCATE TABLE ... CASCADE
34
35
35
36
@ Override
36
37
public void accept (StatementVisitor statementVisitor ) {
@@ -45,8 +46,19 @@ public void setTable(Table table) {
45
46
this .table = table ;
46
47
}
47
48
49
+ public boolean getCascade (){
50
+ return cascade ;
51
+ }
52
+
53
+ public void setCascade (boolean c ){
54
+ cascade =c ;
55
+ }
56
+
48
57
@ Override
49
58
public String toString () {
59
+ if (cascade ){
60
+ return "TRUNCATE TABLE " + table +" CASCADE" ;
61
+ }
50
62
return "TRUNCATE TABLE " + table ;
51
63
}
52
64
}
Original file line number Diff line number Diff line change @@ -144,6 +144,11 @@ public void visit(Select select) {
144
144
145
145
@ Override
146
146
public void visit (Truncate truncate ) {
147
+ buffer .append ("TRUNCATE TABLE " );
148
+ buffer .append (truncate .getTable ());
149
+ if (truncate .getCascade ()){
150
+ buffer .append (" CASCADE" );
151
+ }
147
152
}
148
153
149
154
@ Override
Original file line number Diff line number Diff line change @@ -3449,7 +3449,7 @@ Truncate Truncate():
3449
3449
}
3450
3450
{
3451
3451
<K_TRUNCATE> <K_TABLE>
3452
- table=Table() { truncate.setTable(table); }
3452
+ table=Table() { truncate.setTable(table); truncate.setCascade(false); } [ <K_CASCADE> {truncate.setCascade(true);} ]
3453
3453
{
3454
3454
return truncate;
3455
3455
}
Original file line number Diff line number Diff line change 2
2
3
3
import java .io .StringReader ;
4
4
5
+ import static net .sf .jsqlparser .test .TestUtils .*;
6
+ import net .sf .jsqlparser .*;
7
+
5
8
import net .sf .jsqlparser .parser .CCJSqlParserManager ;
6
9
import static org .junit .Assert .assertEquals ;
7
10
import org .junit .Test ;
@@ -23,5 +26,20 @@ public void testTruncate() throws Exception {
23
26
truncate = (Truncate ) parserManager .parse (new StringReader (statement ));
24
27
assertEquals ("mytab" , truncate .getTable ().getName ());
25
28
assertEquals (toStringStatement .toUpperCase (), truncate .toString ().toUpperCase ());
29
+
30
+ statement = "TRUNCATE TABLE mytab CASCADE" ;
31
+ truncate = (Truncate ) parserManager .parse (new StringReader (statement ));
32
+ assertEquals (statement , truncate .toString ());
33
+ }
34
+
35
+ @ Test
36
+ public void testTruncateDeparse () throws JSQLParserException {
37
+ assertSqlCanBeParsedAndDeparsed ("TRUNCATE TABLE foo" );
26
38
}
39
+
40
+ @ Test
41
+ public void testTruncateCascadeDeparse () throws JSQLParserException {
42
+ assertSqlCanBeParsedAndDeparsed ("TRUNCATE TABLE foo CASCADE" );
43
+ }
44
+
27
45
}
You can’t perform that action at this time.
0 commit comments