Skip to content

Commit

Permalink
feat: methods for returning unquoted names and identifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <[email protected]>
Signed-off-by: manticore-projects <[email protected]>
  • Loading branch information
manticore-projects committed Aug 19, 2024
1 parent 728b286 commit 7e7acba
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/Alias.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Objects;
import java.util.Optional;

import net.sf.jsqlparser.schema.MultiPartName;
import net.sf.jsqlparser.statement.create.table.ColDataType;

public class Alias implements Serializable {
Expand All @@ -38,6 +39,10 @@ public String getName() {
return name;
}

public String getUnquotedName() {
return MultiPartName.unquote(name);
}

public void setName(String name) {
this.name = name;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jsqlparser/schema/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public String getColumnName() {
}

public String getUnquotedColumnName() {
return unquote(columnName);
return MultiPartName.unquote(columnName);
}

public void setColumnName(String string) {
Expand All @@ -123,7 +123,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(columnName);
return MultiPartName.unquote(columnName);
}

public String getFullyQualifiedName(boolean aliases) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/schema/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(databaseName);
return MultiPartName.unquote(databaseName);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/schema/MultiPartName.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface MultiPartName {
* @param quotedIdentifier the quoted identifier
* @return the pure identifier without quotes
*/
default String unquote(String quotedIdentifier) {
static String unquote(String quotedIdentifier) {
return quotedIdentifier != null
? LEADING_TRAILING_QUOTES_PATTERN.matcher(quotedIdentifier).replaceAll("")
: null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/schema/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(partItems.get(NAME_IDX));
return MultiPartName.unquote(partItems.get(NAME_IDX));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/schema/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(serverName);
return MultiPartName.unquote(serverName);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/schema/Synonym.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(partItems.get(NAME_IDX));
return MultiPartName.unquote(partItems.get(NAME_IDX));
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jsqlparser/schema/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getDatabaseName() {
}

public String getUnquotedDatabaseName() {
return unquote(getDatabaseName());
return MultiPartName.unquote(getDatabaseName());
}

public void setDatabase(Database database) {
Expand All @@ -133,7 +133,7 @@ public String getSchemaName() {
}

public String getUnquotedSchemaName() {
return unquote(getSchemaName());
return MultiPartName.unquote(getSchemaName());
}

public Table setSchemaName(String schemaName) {
Expand Down Expand Up @@ -236,7 +236,7 @@ public String getFullyQualifiedName() {

@Override
public String getUnquotedName() {
return unquote(getName());
return MultiPartName.unquote(getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public Alias getAlias() {
return alias;
}

public String getAliasName() {
return alias != null ? alias.getName() : null;
}

public String getUnquotedAliasName() {
return alias != null ? alias.getUnquotedName() : null;
}

public void setAlias(Alias alias) {
this.alias = alias;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/sf/jsqlparser/statement/select/WithItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public Alias getAlias() {
return alias;
}

public String getAliasName() {
return alias != null ? alias.getName() : null;
}

public String getUnquotedAliasName() {
return alias != null ? alias.getUnquotedName() : null;
}

public void setAlias(Alias alias) {
this.alias = alias;
}
Expand Down Expand Up @@ -98,8 +106,6 @@ public String toString() {
builder.append(withItemList.get(i)).append(i < size - 1 ? "," : "");
}
builder.append(")");
} else {
builder.append("");
}
builder.append(" AS ");
builder.append(statement);
Expand Down

0 comments on commit 7e7acba

Please sign in to comment.