File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
java/net/sf/jsqlparser/statement/comment
jjtree/net/sf/jsqlparser/parser Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public class Comment implements Statement {
1919
2020 private Table table ;
2121 private Column column ;
22+ private Table view ;
2223 private StringValue comment ;
2324
2425 @ Override
@@ -42,6 +43,14 @@ public void setColumn(Column column) {
4243 this .column = column ;
4344 }
4445
46+ public Table getView () {
47+ return view ;
48+ }
49+
50+ public void setView (Table view ) {
51+ this .view = view ;
52+ }
53+
4554 public StringValue getComment () {
4655 return comment ;
4756 }
@@ -57,6 +66,8 @@ public String toString() {
5766 sql += "TABLE " + table + " " ;
5867 } else if (column != null ) {
5968 sql += "COLUMN " + column + " " ;
69+ } else if (view != null ) {
70+ sql += "VIEW " + view + " " ;
6071 }
6172 sql += "IS " + comment ;
6273 return sql ;
Original file line number Diff line number Diff line change @@ -4822,6 +4822,7 @@ Comment Comment():
48224822{
48234823 Comment result = new Comment();
48244824 Table table;
4825+ Table view;
48254826 Column column;
48264827 Token comment;
48274828}
@@ -4835,6 +4836,10 @@ Comment Comment():
48354836 (
48364837 <K_COLUMN> column = Column() { result.setColumn(column); }
48374838 )
4839+ |
4840+ (
4841+ <K_VIEW> view = Table() { result.setView(view); }
4842+ )
48384843 )
48394844 <K_IS> comment=<S_CHAR_LITERAL> { result.setComment(new StringValue(comment.image)); }
48404845 {
Original file line number Diff line number Diff line change 99 */
1010package net .sf .jsqlparser .statement .comment ;
1111
12+ import static net .sf .jsqlparser .test .TestUtils .*;
13+ import static org .assertj .core .api .Assertions .assertThat ;
14+
15+ import static org .junit .Assert .assertEquals ;
16+
1217import java .io .StringReader ;
18+
1319import net .sf .jsqlparser .JSQLParserException ;
1420import net .sf .jsqlparser .parser .CCJSqlParserUtil ;
1521import net .sf .jsqlparser .schema .Column ;
1622import net .sf .jsqlparser .schema .Table ;
17- import static net .sf .jsqlparser .test .TestUtils .assertSqlCanBeParsedAndDeparsed ;
18- import static org .assertj .core .api .Assertions .assertThat ;
19- import static org .junit .Assert .assertEquals ;
2023import org .junit .Test ;
2124
2225public class CommentTest {
@@ -92,4 +95,14 @@ public void testCommentTableColumnDiffersIssue984_2() throws JSQLParserException
9295 assertThat (comment .getColumn ().getTable ().getName ()).isEqualTo ("myTable" );
9396 assertThat (comment .getColumn ().getTable ().getSchemaName ()).isEqualTo ("mySchema" );
9497 }
98+
99+ @ Test
100+ public void testCommentOnView () throws JSQLParserException {
101+ String statement = "COMMENT ON VIEW myschema.myView IS 'myComment'" ;
102+ Comment comment = (Comment ) CCJSqlParserUtil .parse (statement );
103+ assertThat (comment .getTable ()).isNull ();
104+ assertThat (comment .getColumn ()).isNull ();
105+ assertThat (comment .getView ().getFullyQualifiedName ()).isEqualTo ("myschema.myView" );
106+ assertStatementCanBeDeparsedAs (comment , statement );
107+ }
95108}
You can’t perform that action at this time.
0 commit comments