Skip to content

Commit

Permalink
fix: AllColumns Replacement shall be about Columns only
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <[email protected]>
  • Loading branch information
manticore-projects committed Jun 10, 2024
1 parent 858058e commit f4b40e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

public class AllColumns extends ASTNodeAccessImpl implements Expression {
protected ExpressionList<Column> exceptColumns;
protected List<SelectItem<?>> replaceExpressions;
protected List<SelectItem<Column>> replaceExpressions;

public AllColumns(ExpressionList<Column> exceptColumns,
List<SelectItem<?>> replaceExpressions) {
List<SelectItem<Column>> replaceExpressions) {
this.exceptColumns = exceptColumns;
this.replaceExpressions = replaceExpressions;
}
Expand All @@ -49,31 +49,31 @@ public AllColumns setExceptColumns(ExpressionList<Column> exceptColumns) {
return this;
}

public List<SelectItem<?>> getReplaceExpressions() {
public List<SelectItem<Column>> getReplaceExpressions() {
return replaceExpressions;
}

public List<SelectItem<?>> addReplaceExpression(SelectItem<?> selectItem) {
public List<SelectItem<Column>> addReplaceExpression(SelectItem<Column> selectItem) {
if (replaceExpressions == null) {
replaceExpressions = new ArrayList<>();
}
replaceExpressions.add(selectItem);
return replaceExpressions;
}

public AllColumns setReplaceExpressions(List<SelectItem<?>> replaceExpressions) {
public AllColumns setReplaceExpressions(List<SelectItem<Column>> replaceExpressions) {
this.replaceExpressions = replaceExpressions;
return this;
}

public StringBuilder appendTo(StringBuilder builder) {
builder.append("*");
if (exceptColumns != null && exceptColumns.size() > 0) {
if (exceptColumns != null && !exceptColumns.isEmpty()) {
builder.append(" Except( ");
exceptColumns.appendTo(builder);
builder.append(" )");
}
if (replaceExpressions != null && replaceExpressions.size() > 0) {
if (replaceExpressions != null && !replaceExpressions.isEmpty()) {
builder.append(" Replace(");
int i = 0;
for (SelectItem<?> selectItem : replaceExpressions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AllTableColumns extends AllColumns {
private Table table;

public AllTableColumns(Table table, ExpressionList<Column> exceptColumns,
List<SelectItem<?>> replaceExpressions) {
List<SelectItem<Column>> replaceExpressions) {
super(exceptColumns, replaceExpressions);
this.table = table;
}
Expand Down
21 changes: 19 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,23 @@ WithItem WithItem() #WithItem:
}
}

List<SelectItem<Column>> ColumnSelectItemsList():
{
List<SelectItem<Column>> selectItemsList = null;
SelectItem selectItem = null;
}
{
selectItem=SelectItem() { selectItemsList = new ArrayList<SelectItem<Column>>(); selectItemsList.add(selectItem); }
(
LOOKAHEAD(2) "," selectItem=SelectItem()
{
selectItemsList.add(selectItem);
}
)*

{ return selectItemsList; }
}

List<SelectItem<?>> SelectItemsList():
{
List<SelectItem<?>> selectItemsList = null;
Expand Down Expand Up @@ -2614,12 +2631,12 @@ SelectItem SelectItem() #SelectItem:
AllColumns AllColumns():
{
ParenthesedExpressionList<Column> exceptColumns = null;
List<SelectItem<?>> replaceExpressions = null;
List<SelectItem<Column>> replaceExpressions = null;
}
{
"*"
[ LOOKAHEAD(2) <K_EXCEPT> exceptColumns = ParenthesedColumnList() ]
[ LOOKAHEAD(2) <K_REPLACE> "(" replaceExpressions = SelectItemsList() ")" ]
[ LOOKAHEAD(2) <K_REPLACE> "(" replaceExpressions = ColumnSelectItemsList() ")" ]

{
return new AllColumns(exceptColumns, replaceExpressions);
Expand Down

0 comments on commit f4b40e4

Please sign in to comment.