Skip to content

Commit

Permalink
feat: improve String representation of Table and Column
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Jul 5, 2024
1 parent 6a36b3f commit f3268e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jsqlparser/schema/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {

@Override
public String toString() {
return getFullyQualifiedName(true);
return getFullyQualifiedName(true)
+ (commentText != null ? " /* " + commentText + "*/ " : "");
}

public Column withTable(Table table) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/sf/jsqlparser/schema/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ private String getIndex(int idx) {
public String getFullyQualifiedName() {
StringBuilder fqn = new StringBuilder();

// remove any leading empty items
// only middle items can be suppressed (e.g. dbo..MY_TABLE )
while (!partItems.isEmpty() && (partItems.get(partItems.size() - 1) == null
|| partItems.get(partItems.size() - 1).isEmpty())) {
partItems.remove(partItems.size() - 1);
}


for (int i = partItems.size() - 1; i >= 0; i--) {
String part = partItems.get(i);
if (part == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,11 @@ public <S> StringBuilder visit(Column tableColumn, S context) {
if (tableColumn.getArrayConstructor() != null) {
tableColumn.getArrayConstructor().accept(this, context);
}

if (tableColumn.getCommentText() != null) {
buffer.append(" /* ").append(tableColumn.getCommentText()).append("*/ ");
}

return buffer;
}

Expand Down

0 comments on commit f3268e7

Please sign in to comment.