Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMMENT ON VIEW #1024

Merged
merged 2 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/comment/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Comment implements Statement {

private Table table;
private Column column;
private Table view;
private StringValue comment;

@Override
Expand All @@ -42,6 +43,14 @@ public void setColumn(Column column) {
this.column = column;
}

public Table getView() {
return view;
}

public void setView(Table view) {
this.view = view;
}

public StringValue getComment() {
return comment;
}
Expand All @@ -57,6 +66,8 @@ public String toString() {
sql += "TABLE " + table + " ";
} else if (column != null) {
sql += "COLUMN " + column + " ";
} else if (view != null) {
sql += "VIEW " + view + " ";
}
sql += "IS " + comment;
return sql;
Expand Down
5 changes: 5 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4822,6 +4822,7 @@ Comment Comment():
{
Comment result = new Comment();
Table table;
Table view;
Column column;
Token comment;
}
Expand All @@ -4835,6 +4836,10 @@ Comment Comment():
(
<K_COLUMN> column = Column() { result.setColumn(column); }
)
|
(
<K_VIEW> view = Table() { result.setView(view); }
)
)
<K_IS> comment=<S_CHAR_LITERAL> { result.setComment(new StringValue(comment.image)); }
{
Expand Down
19 changes: 16 additions & 3 deletions src/test/java/net/sf/jsqlparser/statement/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
*/
package net.sf.jsqlparser.statement.comment;

import static net.sf.jsqlparser.test.TestUtils.*;
import static org.assertj.core.api.Assertions.assertThat;

import static org.junit.Assert.assertEquals;

import java.io.StringReader;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CommentTest {
Expand Down Expand Up @@ -92,4 +95,14 @@ public void testCommentTableColumnDiffersIssue984_2() throws JSQLParserException
assertThat(comment.getColumn().getTable().getName()).isEqualTo("myTable");
assertThat(comment.getColumn().getTable().getSchemaName()).isEqualTo("mySchema");
}

@Test
public void testCommentOnView() throws JSQLParserException {
String statement = "COMMENT ON VIEW myschema.myView IS 'myComment'";
Comment comment = (Comment) CCJSqlParserUtil.parse(statement);
assertThat(comment.getTable()).isNull();
assertThat(comment.getColumn()).isNull();
assertThat(comment.getView().getFullyQualifiedName()).isEqualTo("myschema.myView");
assertStatementCanBeDeparsedAs(comment, statement);
}
}