Skip to content

Commit

Permalink
Merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Nov 22, 2018
2 parents f06b197 + 58d3965 commit 572a6c6
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 54 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Look here for more information and examples: https://github.com/JSQLParser/JSqlP

JSqlParser is dual licensed under **LGPL V2.1** and **Apache Software License, Version 2.0**.

## Discussion

Please provide feedback on https://github.com/JSQLParser/JSqlParser/issues/677, about removing bracket identifier quotation to support array processing.

## News
* Released version **1.3** of JSqlParser
Expand Down Expand Up @@ -51,6 +54,7 @@ Also I would like to know about needed examples or documentation stuff.

## Extensions in the latest SNAPSHOT version 1.4

* support of **substring(col from 2), position('test' in col), ..** and more (pull request #702)
* support of db2 **VALUES** syntax (issue #561)

## Extensions of JSqlParser releases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ public void visit(ExpressionList expressionList) {
}
}

@Override
public void visit(NamedExpressionList namedExpressionList) {
for (Expression expr : namedExpressionList.getExpressions()) {
expr.accept(this);
}
}


@Override
public void visit(MultiExpressionList multiExprList) {
for (ExpressionList list : multiExprList.getExprList()) {
Expand Down
32 changes: 26 additions & 6 deletions src/main/java/net/sf/jsqlparser/expression/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;

/**
Expand All @@ -31,6 +32,7 @@ public class Function extends ASTNodeAccessImpl implements Expression {

private String name;
private ExpressionList parameters;
private NamedExpressionList namedParameters;
private boolean allColumns = false;
private boolean distinct = false;
private boolean isEscaped = false;
Expand Down Expand Up @@ -95,6 +97,20 @@ public void setParameters(ExpressionList list) {
parameters = list;
}

/**
* the parameters might be named parameters, e.g. substring('foobar' from 2 for 3)
*
* @return the list of named parameters of the function (if any, else null)
*/

public NamedExpressionList getNamedParameters() {
return namedParameters;
}

public void setNamedParameters(NamedExpressionList list) {
namedParameters = list;
}

/**
* Return true if it's in the form "{fn function_body() }"
*
Expand Down Expand Up @@ -128,12 +144,16 @@ public void setKeep(KeepExpression keep) {
public String toString() {
String params;

if (parameters != null) {
params = parameters.toString();
if (isDistinct()) {
params = params.replaceFirst("\\(", "(DISTINCT ");
} else if (isAllColumns()) {
params = params.replaceFirst("\\(", "(ALL ");
if (parameters != null || namedParameters != null) {
if(parameters != null){
params = parameters.toString();
if (isDistinct()) {
params = params.replaceFirst("\\(", "(DISTINCT ");
} else if (isAllColumns()) {
params = params.replaceFirst("\\(", "(ALL ");
}
} else{
params = namedParameters.toString();
}
} else if (isAllColumns()) {
params = "(*)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public interface ItemsListVisitor {

void visit(ExpressionList expressionList);

void visit(NamedExpressionList namedExpressionList);

void visit(MultiExpressionList multiExprList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void visit(SubSelect subSelect) {

}

@Override
public void visit(NamedExpressionList namedExpressionList) {

}

@Override
public void visit(ExpressionList expressionList) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import java.util.Arrays;
import java.util.List;

import net.sf.jsqlparser.expression.Expression;

/**
* A list of named expressions, as in
* as in select substr('xyzzy' from 2 for 3)
*/
public class NamedExpressionList implements ItemsList {

private List<Expression> expressions;
private List<String> names;

public NamedExpressionList() {
}

public NamedExpressionList(List<Expression> expressions) {
this.expressions = expressions;
}

public NamedExpressionList(Expression ... expressions) {
this.expressions = Arrays.asList(expressions);
}

public List<Expression> getExpressions() {
return expressions;
}

public List<String> getNames() {
return names;
}


public void setExpressions(List<Expression> list) {
expressions = list;
}

public void setNames(List<String> list) {
names = list;
}


@Override
public void accept(ItemsListVisitor itemsListVisitor) {
itemsListVisitor.visit(this);
}

@Override
public String toString() {

StringBuilder ret = new StringBuilder();
ret.append("(");
for(int i=0; i<expressions.size(); i++){
if(i>0){
ret.append(" ");
}
if(! names.get(i).equals("")){
ret.append(names.get(i)).append(" ").append(expressions.get(i));
}else{
ret.append(expressions.get(i));
}
}
ret.append(")");

return ret.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package net.sf.jsqlparser.statement;

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.view.AlterView;
Expand All @@ -40,6 +41,8 @@

public interface StatementVisitor {

void visit(Comment comment);

void visit(Commit commit);

void visit(Delete delete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package net.sf.jsqlparser.statement;

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.view.AlterView;
Expand All @@ -40,6 +41,11 @@

public class StatementVisitorAdapter implements StatementVisitor {

@Override
public void visit(Comment comment) {

}

@Override
public void visit(Commit commit) {

Expand Down
76 changes: 76 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/comment/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2017 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.statement.comment;

import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;

public class Comment implements Statement {

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

@Override
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}

public Table getTable() {
return table;
}

public void setTable(Table table) {
this.table = table;
}

public Column getColumn() {
return column;
}

public void setColumn(Column column) {
this.column = column;
}

public StringValue getComment() {
return comment;
}

public void setComment(StringValue comment) {
this.comment = comment;
}

@Override
public String toString() {
String sql = "COMMENT ON ";
if (table != null) {
sql += "TABLE " + table + " ";
} else if (column != null) {
sql += "COLUMN " + column + " ";
}
sql += "IS " + comment;
return sql;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class AlterView implements Statement {

private Table view;
private SelectBody selectBody;
private boolean useReplace = false;
private List<String> columnNames = null;

@Override
Expand Down Expand Up @@ -74,9 +75,23 @@ public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}

public boolean isUseReplace() {
return useReplace;
}

public void setUseReplace(boolean useReplace) {
this.useReplace = useReplace;
}


@Override
public String toString() {
StringBuilder sql = new StringBuilder("ALTER ");
StringBuilder sql;
if(useReplace){
sql = new StringBuilder("REPLACE ");
}else{
sql = new StringBuilder("ALTER ");
}
sql.append("VIEW ");
sql.append(view);
if (columnNames != null) {
Expand Down
Loading

0 comments on commit 572a6c6

Please sign in to comment.