Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
| **Tablespaces** | MySQL and PostgreSQL `CREATE TABLESPACE` · `ALTER TABLESPACE` |
| **PostgreSQL RLS** | `CREATE POLICY` · `ALTER TABLE … ENABLE`/`DISABLE`/`FORCE`/`NO FORCE ROW LEVEL SECURITY` |
| **Routine changes** | `ALTER FUNCTION` · `ALTER PROCEDURE` · `ALTER ROUTINE` · PostgreSQL `ALTER TRIGGER` |
| **MySQL metadata statements** | `SHOW [FULL] COLUMNS`/`FIELDS` · `SHOW TABLE STATUS` · `SHOW CREATE TABLE`/`VIEW`/`PROCEDURE`/`FUNCTION`/`TRIGGER`/`EVENT`/`DATABASE`/`USER` |
| **MySQL metadata statements** | `SHOW [FULL] COLUMNS`/`FIELDS` · `SHOW INDEX`/`INDEXES`/`KEYS` · `SHOW TABLE STATUS` · `SHOW CREATE TABLE`/`VIEW`/`PROCEDURE`/`FUNCTION`/`TRIGGER`/`EVENT`/`DATABASE`/`USER` · `SHOW [GLOBAL | SESSION] VARIABLES`/`STATUS` · `SHOW [FULL] PROCESSLIST` · `SHOW GRANTS [FOR …]` · `SHOW WARNINGS`/`ERRORS` · `SHOW BINARY LOGS`/`BINLOG EVENTS`/`RELAYLOG EVENTS` · `SHOW ENGINE …` · `SHOW PROFILE` · `SHOW DATABASES`/`TRIGGERS`/`EVENTS`/`OPEN TABLES`/`CHARACTER SET`/`COLLATION` · `SHOW PROCEDURE`/`FUNCTION STATUS`/`CODE` · `SHOW REPLICA STATUS`/`REPLICAS` |
| **PostgreSQL administration** | `CREATE`/`ALTER EVENT TRIGGER` · `REINDEX` · `SECURITY LABEL` |
| **Informix constraints** | `ALTER TABLE … ADD CONSTRAINT` with trailing constraint names for primary, unique, foreign and check constraints; enable with `parser.withDialect(Dialect.INFORMIX)` |
| **Salesforce SOQL** | `INCLUDES` · `EXCLUDES` |
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/sf/jsqlparser/parser/feature/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,13 @@ public enum Feature {
* @see ShowCreateStatement
*/
showCreate,
/**
* The MySQL/MariaDB "SHOW" statements of server settings, state and object lists, such as "SHOW
* VARIABLES", "SHOW GRANTS" or "SHOW BINLOG EVENTS"
*
* @see MySqlShowStatement
*/
mySqlShow,
/**
* @see UseStatement
*/
Expand Down
93 changes: 69 additions & 24 deletions src/main/java/net/sf/jsqlparser/statement/ShowColumnsStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
*/
package net.sf.jsqlparser.statement;

import java.util.function.Consumer;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.show.ShowDbSelection;
import net.sf.jsqlparser.statement.show.ShowFilter;
import net.sf.jsqlparser.statement.show.ShowTablesStatement.SelectionMode;

/**
Expand All @@ -27,10 +30,8 @@ public class ShowColumnsStatement extends ASTNodeAccessImpl implements Statement
private boolean fieldsKeyword;
private SelectionMode tableSelectionMode = SelectionMode.FROM;
private Table table;
private SelectionMode dbSelectionMode = SelectionMode.FROM;
private String dbName;
private Expression likeExpression;
private Expression whereCondition;
private ShowDbSelection dbSelection;
private ShowFilter filter;

public ShowColumnsStatement() {
// empty constructor
Expand Down Expand Up @@ -97,41 +98,73 @@ public void setTableName(String tableName) {

/** The keyword before the database name, {@code FROM} unless {@code IN} was written. */
public SelectionMode getDbSelectionMode() {
return dbSelectionMode;
return dbSelection == null ? SelectionMode.FROM : dbSelection.getSelectionMode();
}

/** Sets the keyword before the database name, which is kept until the name is set. */
public void setDbSelectionMode(SelectionMode dbSelectionMode) {
this.dbSelectionMode = dbSelectionMode;
dbSelection = ShowDbSelection.updateSelectionMode(dbSelection, dbSelectionMode);
}

/** The database of the trailing {@code FROM db} or {@code IN db} clause, or null. */
public String getDbName() {
return dbName;
return ShowDbSelection.name(dbSelection);
}

public void setDbName(String dbName) {
this.dbName = dbName;
dbSelection = ShowDbSelection.updateName(dbSelection, dbName);
}

/** The trailing {@code {FROM | IN} db} clause, or null. */
public ShowDbSelection getDbSelection() {
return dbSelection;
}

public void setDbSelection(ShowDbSelection dbSelection) {
this.dbSelection = dbSelection;
}

/** The {@code LIKE} or {@code WHERE} filter, or null. */
public ShowFilter getFilter() {
return filter;
}

public void setFilter(ShowFilter filter) {
this.filter = filter;
}

public Expression getLikeExpression() {
return likeExpression;
return ShowFilter.likeExpression(filter);
}

/** Sets a {@code LIKE} filter, which replaces a {@code WHERE} filter; null removes it. */
public void setLikeExpression(Expression likeExpression) {
this.likeExpression = likeExpression;
filter = ShowFilter.replace(filter, ShowFilter.Kind.LIKE, likeExpression);
}

public Expression getWhereCondition() {
return whereCondition;
return ShowFilter.whereCondition(filter);
}

/** Sets a {@code WHERE} filter, which replaces a {@code LIKE} filter; null removes it. */
public void setWhereCondition(Expression whereCondition) {
this.whereCondition = whereCondition;
filter = ShowFilter.replace(filter, ShowFilter.Kind.WHERE, whereCondition);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder("SHOW");
/**
* The table the statement reads: {@link #getTable()}, or the table in the database of the
* trailing {@code FROM db} clause, which MySQL reads as {@code db.table}.
*/
public Table getQualifiedTable() {
if (table == null || !ShowDbSelection.isPresent(dbSelection)) {
return table;
}
return new Table(dbSelection.getName(), table.getName());
}

/** Appends the statement, printing the filter expression with the given printer. */
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> printer) {
builder.append("SHOW");
if (extended) {
builder.append(" EXTENDED");
}
Expand All @@ -141,17 +174,19 @@ public String toString() {
builder.append(fieldsKeyword ? " FIELDS " : " COLUMNS ")
.append(tableSelectionMode == null ? SelectionMode.FROM : tableSelectionMode)
.append(' ').append(table);
if (dbName != null) {
builder.append(' ')
.append(dbSelectionMode == null ? SelectionMode.FROM : dbSelectionMode)
.append(' ').append(dbName);
if (ShowDbSelection.isPresent(dbSelection)) {
builder.append(' ').append(dbSelection);
}
if (likeExpression != null) {
builder.append(" LIKE ").append(likeExpression);
} else if (whereCondition != null) {
builder.append(" WHERE ").append(whereCondition);
if (filter != null) {
filter.appendTo(builder.append(' '), printer);
}
return builder.toString();
return builder;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return appendTo(builder, builder::append).toString();
}

@Override
Expand Down Expand Up @@ -208,4 +243,14 @@ public ShowColumnsStatement withWhereCondition(Expression whereCondition) {
this.setWhereCondition(whereCondition);
return this;
}

public ShowColumnsStatement withDbSelection(ShowDbSelection dbSelection) {
this.setDbSelection(dbSelection);
return this;
}

public ShowColumnsStatement withFilter(ShowFilter filter) {
this.setFilter(filter);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import net.sf.jsqlparser.statement.select.SelectVisitorAdapter;
import net.sf.jsqlparser.statement.select.TableStatement;
import net.sf.jsqlparser.statement.select.WithItem;
import net.sf.jsqlparser.statement.show.MySqlShowStatement;
import net.sf.jsqlparser.statement.show.ShowCreateStatement;
import net.sf.jsqlparser.statement.show.ShowIndexStatement;
import net.sf.jsqlparser.statement.show.ShowTableStatusStatement;
Expand Down Expand Up @@ -1065,6 +1066,11 @@ public <S> Void visit(ShowCreateStatement showCreate, S context) {
return metadataOnly();
}

@Override
public <S> Void visit(MySqlShowStatement mySqlShow, S context) {
return metadataOnly();
}

@Override
public <S> Void visit(DescribeStatement describe, S context) {
return metadataOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import net.sf.jsqlparser.statement.reindex.Reindex;
import net.sf.jsqlparser.statement.securitylabel.SecurityLabel;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.show.MySqlShowStatement;
import net.sf.jsqlparser.statement.show.ShowCreateStatement;
import net.sf.jsqlparser.statement.show.ShowIndexStatement;
import net.sf.jsqlparser.statement.show.ShowTableStatusStatement;
Expand Down Expand Up @@ -483,6 +484,14 @@ default void visit(ShowCreateStatement showCreate) {
this.visit(showCreate, null);
}

default <S> T visit(MySqlShowStatement mySqlShow, S context) {
return null;
}

default void visit(MySqlShowStatement mySqlShow) {
this.visit(mySqlShow, null);
}

<S> T visit(Merge merge, S context);

default void visit(Merge merge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import net.sf.jsqlparser.statement.select.SelectVisitor;
import net.sf.jsqlparser.statement.select.SelectVisitorAdapter;
import net.sf.jsqlparser.statement.select.WithItem;
import net.sf.jsqlparser.statement.show.MySqlShowStatement;
import net.sf.jsqlparser.statement.show.ShowCreateStatement;
import net.sf.jsqlparser.statement.show.ShowIndexStatement;
import net.sf.jsqlparser.statement.show.ShowTableStatusStatement;
Expand Down Expand Up @@ -691,6 +692,11 @@ public <S> T visit(ShowCreateStatement showCreate, S context) {
return null;
}

@Override
public <S> T visit(MySqlShowStatement mySqlShow, S context) {
return null;
}

@Override
public <S> T visit(DeclareStatement declareStatement, S context) {
return null;
Expand Down
Loading
Loading