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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
| **PostgreSQL session statements** | `DISCARD` · `LISTEN` · `UNLISTEN` · `SHOW`/`RESET TIME ZONE`/`TRANSACTION ISOLATION LEVEL`/`SESSION AUTHORIZATION` · `COPY` options from before 9.0 |
| **MySQL account management** | `CREATE`/`ALTER`/`RENAME USER` · `CREATE ROLE` · `SET ROLE` · `SET DEFAULT ROLE` · `SET PASSWORD` |
| **Tablespaces** | MySQL and PostgreSQL `CREATE TABLESPACE` · `ALTER TABLESPACE` |
| **MySQL spatial reference systems and instance** | `CREATE`/`DROP SPATIAL REFERENCE SYSTEM` · `ALTER INSTANCE` |
| **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` |
Expand Down
12 changes: 12 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 @@ -477,6 +477,18 @@ public enum Feature {
* @see net.sf.jsqlparser.statement.alter.AlterTablespace
*/
alterTablespace,
/**
* MySQL "CREATE SPATIAL REFERENCE SYSTEM" statement is allowed
*
* @see net.sf.jsqlparser.statement.create.spatial.CreateSpatialReferenceSystem
*/
createSpatialReferenceSystem,
/**
* MySQL "ALTER INSTANCE" statement is allowed
*
* @see net.sf.jsqlparser.statement.alter.AlterInstance
*/
alterInstance,


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.sf.jsqlparser.statement.alter.AlterStatistics;
import net.sf.jsqlparser.statement.alter.AlterSubscription;
import net.sf.jsqlparser.statement.alter.AlterEventTrigger;
import net.sf.jsqlparser.statement.alter.AlterInstance;
import net.sf.jsqlparser.statement.alter.AlterSystemStatement;
import net.sf.jsqlparser.statement.alter.AlterTablespace;
import net.sf.jsqlparser.statement.alter.AlterTablespaceMove;
Expand Down Expand Up @@ -75,6 +76,7 @@
import net.sf.jsqlparser.statement.create.subscription.SubscriptionOption;
import net.sf.jsqlparser.statement.create.synonym.CreateSynonym;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.spatial.CreateSpatialReferenceSystem;
import net.sf.jsqlparser.statement.create.tablespace.CreateTablespace;
import net.sf.jsqlparser.statement.create.textsearch.CreateTextSearchConfiguration;
import net.sf.jsqlparser.statement.create.trigger.CreateEventTrigger;
Expand Down Expand Up @@ -1381,6 +1383,17 @@ public <S> Void visit(CreateTablespace statement, S context) {
return schemaOnly();
}

@Override
public <S> Void visit(CreateSpatialReferenceSystem statement, S context) {
return schemaOnly();
}

/** A server operation, like ALTER SYSTEM. */
@Override
public <S> Void visit(AlterInstance statement, S context) {
return sessionOnly();
}

@Override
public <S> Void visit(AlterTablespace statement, S context) {
return schemaOnly();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.AlterEventTrigger;
import net.sf.jsqlparser.statement.alter.AlterInstance;
import net.sf.jsqlparser.statement.alter.AlterSystemStatement;
import net.sf.jsqlparser.statement.alter.RenameTableStatement;
import net.sf.jsqlparser.statement.alter.AlterUser;
Expand All @@ -75,6 +76,7 @@
import net.sf.jsqlparser.statement.create.sequence.CreateSequence;
import net.sf.jsqlparser.statement.create.synonym.CreateSynonym;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.spatial.CreateSpatialReferenceSystem;
import net.sf.jsqlparser.statement.create.tablespace.CreateTablespace;
import net.sf.jsqlparser.statement.create.trigger.CreateEventTrigger;
import net.sf.jsqlparser.statement.create.trigger.CreateTrigger;
Expand Down Expand Up @@ -936,6 +938,22 @@ default void visit(CreateTablespace statement) {
visit(statement, null);
}

default <S> T visit(CreateSpatialReferenceSystem statement, S context) {
return null;
}

default void visit(CreateSpatialReferenceSystem statement) {
visit(statement, null);
}

default <S> T visit(AlterInstance statement, S context) {
return null;
}

default void visit(AlterInstance statement) {
visit(statement, null);
}

default <S> T visit(AlterTablespace statement, S context) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import net.sf.jsqlparser.statement.alter.AlterExpression;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.AlterEventTrigger;
import net.sf.jsqlparser.statement.alter.AlterInstance;
import net.sf.jsqlparser.statement.alter.AlterSystemStatement;
import net.sf.jsqlparser.statement.alter.RenameTableStatement;
import net.sf.jsqlparser.statement.alter.AlterUser;
Expand All @@ -77,6 +78,7 @@
import net.sf.jsqlparser.statement.create.sequence.CreateSequence;
import net.sf.jsqlparser.statement.create.synonym.CreateSynonym;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.spatial.CreateSpatialReferenceSystem;
import net.sf.jsqlparser.statement.create.tablespace.CreateTablespace;
import net.sf.jsqlparser.statement.create.trigger.CreateEventTrigger;
import net.sf.jsqlparser.statement.create.trigger.CreateTrigger;
Expand Down Expand Up @@ -1082,6 +1084,16 @@ public <S> T visit(CreateTablespace statement, S context) {
return null;
}

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

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

@Override
public <S> T visit(AlterTablespace statement, S context) {
statement.visitExpressions(expression -> expression.accept(expressionVisitor, context));
Expand Down
148 changes: 148 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/alter/AlterInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.alter;

import java.util.Objects;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;

/**
* MySQL {@code ALTER INSTANCE}, which acts on the server instance:
* {@code {ENABLE | DISABLE} INNODB REDO_LOG}, {@code ROTATE INNODB MASTER KEY},
* {@code ROTATE BINLOG MASTER KEY}, {@code RELOAD TLS [FOR CHANNEL channel] [NO ROLLBACK ON ERROR]}
* and {@code RELOAD KEYRING}.
*
* <p>
* MySQL reads INNODB, BINLOG and REDO_LOG as identifiers, so they may be quoted; the statement
* renders them as plain words. The channel is kept as written: MySQL's grammar takes any
* identifier, and the server accepts {@code mysql_main} and {@code mysql_admin} when it runs the
* statement.
*
* @see <a href="https://dev.mysql.com/doc/refman/8.4/en/alter-instance.html">MySQL ALTER
* INSTANCE</a>
*/
public class AlterInstance extends ASTNodeAccessImpl implements Statement {
/** The words after ALTER INSTANCE, without the options of RELOAD TLS. */
public enum Action {
ENABLE_INNODB_REDO_LOG("ENABLE INNODB REDO_LOG"), DISABLE_INNODB_REDO_LOG(
"DISABLE INNODB REDO_LOG"), ROTATE_INNODB_MASTER_KEY(
"ROTATE INNODB MASTER KEY"), ROTATE_BINLOG_MASTER_KEY(
"ROTATE BINLOG MASTER KEY"), RELOAD_TLS(
"RELOAD TLS"), RELOAD_KEYRING("RELOAD KEYRING");

private final String sql;

Action(String sql) {
this.sql = sql;
}

public String getSql() {
return sql;
}
}

private Action action;
private String channel;
private boolean noRollbackOnError;

public AlterInstance(Action action) {
this.action = Objects.requireNonNull(action, "action");
}

public Action getAction() {
return action;
}

/**
* Sets the action.
*
* @throws IllegalArgumentException if the statement has options of RELOAD TLS and the action is
* another one
*/
public void setAction(Action action) {
Objects.requireNonNull(action, "action");
if (action != Action.RELOAD_TLS && (channel != null || noRollbackOnError)) {
throw new IllegalArgumentException(
"FOR CHANNEL and NO ROLLBACK ON ERROR belong to RELOAD TLS");
}
this.action = action;
}

public AlterInstance withAction(Action action) {
setAction(action);
return this;
}

/** The identifier of {@code RELOAD TLS FOR CHANNEL channel} as written, or null. */
public String getChannel() {
return channel;
}

/**
* Sets the channel of RELOAD TLS; null removes the clause.
*
* @throws IllegalArgumentException if the action is not RELOAD TLS
*/
public void setChannel(String channel) {
if (channel != null && action != Action.RELOAD_TLS) {
throw new IllegalArgumentException("FOR CHANNEL belongs to RELOAD TLS");
}
this.channel = channel;
}

public AlterInstance withChannel(String channel) {
setChannel(channel);
return this;
}

/** Whether RELOAD TLS ends with NO ROLLBACK ON ERROR. */
public boolean isNoRollbackOnError() {
return noRollbackOnError;
}

/**
* Sets NO ROLLBACK ON ERROR.
*
* @throws IllegalArgumentException if the action is not RELOAD TLS
*/
public void setNoRollbackOnError(boolean noRollbackOnError) {
if (noRollbackOnError && action != Action.RELOAD_TLS) {
throw new IllegalArgumentException("NO ROLLBACK ON ERROR belongs to RELOAD TLS");
}
this.noRollbackOnError = noRollbackOnError;
}

public AlterInstance withNoRollbackOnError(boolean noRollbackOnError) {
setNoRollbackOnError(noRollbackOnError);
return this;
}

public StringBuilder appendTo(StringBuilder builder) {
builder.append("ALTER INSTANCE ").append(action.getSql());
if (channel != null) {
builder.append(" FOR CHANNEL ").append(channel);
}
if (noRollbackOnError) {
builder.append(" NO ROLLBACK ON ERROR");
}
return builder;
}

@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}

@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}
Loading
Loading