Skip to content

Commit ade260a

Browse files
committed
Merge upstream master into PR #2906
Preserve MySQL replication visitors and PostgreSQL cursor support. Keep both sides of the overlapping grammar, visitor, and documentation changes. Validation: mvn --batch-mode --no-transfer-progress test 15,949 tests; zero failures/errors; 25 existing skips. JavaCC reports no choice conflicts.
2 parents 6d54881 + bccb1c8 commit ade260a

71 files changed

Lines changed: 11338 additions & 295 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,21 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
152152
| **PostgreSQL maintenance** | `VACUUM` · `ANALYZE` · `CLUSTER` · `CHECKPOINT` |
153153
| **MySQL locks** | `LOCK TABLES` · `UNLOCK TABLES` · `LOCK INSTANCE FOR BACKUP` · `UNLOCK INSTANCE` |
154154
| **MySQL resource groups** | `CREATE`/`ALTER`/`DROP RESOURCE GROUP` · `SET RESOURCE GROUP` |
155+
| **MySQL servers, plugins and components** | `CREATE SERVER` · `ALTER SERVER` with `OPTIONS (… PORT 3306)` · `INSTALL`/`UNINSTALL PLUGIN` · `INSTALL`/`UNINSTALL COMPONENT` |
155156
| **PostgreSQL session statements** | `DISCARD` · `LISTEN` · `UNLISTEN` · `SHOW`/`RESET TIME ZONE`/`TRANSACTION ISOLATION LEVEL`/`SESSION AUTHORIZATION` · `COPY` options from before 9.0 |
156157
| **MySQL server administration** | `FLUSH` · `KILL` · `RESET PERSIST` · `HANDLER … OPEN`/`READ`/`CLOSE` |
157158
| **MySQL replication** | `CHANGE REPLICATION SOURCE TO` · `CHANGE REPLICATION FILTER` · `START`/`STOP REPLICA` · `RESET REPLICA` · `RESET BINARY LOGS AND GTIDS` · `PURGE BINARY LOGS` |
159+
| **PostgreSQL cursors** | `DECLARE … CURSOR` · `FETCH` · `MOVE` · `CLOSE` |
158160
| **MySQL account management** | `CREATE`/`ALTER`/`RENAME USER` · `CREATE ROLE` · `SET ROLE` · `SET DEFAULT ROLE` · `SET PASSWORD` |
159161
| **Tablespaces** | MySQL and PostgreSQL `CREATE TABLESPACE` · `ALTER TABLESPACE` |
162+
| **MySQL spatial reference systems and instance** | `CREATE`/`DROP SPATIAL REFERENCE SYSTEM` · `ALTER INSTANCE` |
160163
| **PostgreSQL RLS** | `CREATE POLICY` · `ALTER TABLE … ENABLE`/`DISABLE`/`FORCE`/`NO FORCE ROW LEVEL SECURITY` |
161164
| **Routine changes** | `ALTER FUNCTION` · `ALTER PROCEDURE` · `ALTER ROUTINE` · PostgreSQL `ALTER TRIGGER` |
162-
| **MySQL metadata statements** | `SHOW [FULL] COLUMNS`/`FIELDS` · `SHOW TABLE STATUS` · `SHOW CREATE TABLE`/`VIEW`/`PROCEDURE`/`FUNCTION`/`TRIGGER`/`EVENT`/`DATABASE`/`USER` |
165+
| **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` |
163166
| **MySQL utility statements** | `EXPLAIN`/`DESCRIBE [ANALYZE] FORMAT = …` · `EXPLAIN FOR CONNECTION` · `DESCRIBE t col` · `PREPARE … FROM` · `EXECUTE … USING` · `DROP PREPARE` · `DO` |
164167
| **PostgreSQL administration** | `CREATE`/`ALTER EVENT TRIGGER` · `REINDEX` · `SECURITY LABEL` |
165168
| **PostgreSQL types and rules** | `CREATE TYPE` (shell, composite, enum, range and base types) · `ALTER TYPE` · `CREATE RULE` · `ALTER RULE` |
169+
| **PostgreSQL operators and aggregates** | `CREATE`/`ALTER OPERATOR` · `CREATE`/`ALTER OPERATOR CLASS` · `CREATE`/`ALTER OPERATOR FAMILY` · `CREATE`/`ALTER AGGREGATE` |
166170
| **Informix constraints** | `ALTER TABLE … ADD CONSTRAINT` with trailing constraint names for primary, unique, foreign and check constraints; enable with `parser.withDialect(Dialect.INFORMIX)` |
167171
| **Salesforce SOQL** | `INCLUDES` · `EXCLUDES` |
168172

‎src/main/java/net/sf/jsqlparser/parser/feature/Feature.java‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.sf.jsqlparser.statement.DeclareStatement;
2323
import net.sf.jsqlparser.statement.DescribeStatement;
2424
import net.sf.jsqlparser.statement.ExplainStatement;
25+
import net.sf.jsqlparser.statement.PluginStatement;
2526
import net.sf.jsqlparser.statement.PrepareTransactionStatement;
2627
import net.sf.jsqlparser.statement.ResetStatement;
2728
import net.sf.jsqlparser.statement.SetConstraintsStatement;
@@ -53,6 +54,9 @@
5354
import net.sf.jsqlparser.statement.create.trigger.CreateEventTrigger;
5455
import net.sf.jsqlparser.statement.create.view.AlterView;
5556
import net.sf.jsqlparser.statement.create.view.CreateView;
57+
import net.sf.jsqlparser.statement.cursor.CloseCursorStatement;
58+
import net.sf.jsqlparser.statement.cursor.DeclareCursorStatement;
59+
import net.sf.jsqlparser.statement.cursor.FetchCursorStatement;
5660
import net.sf.jsqlparser.statement.delete.Delete;
5761
import net.sf.jsqlparser.statement.drop.Drop;
5862
import net.sf.jsqlparser.statement.execute.Execute;
@@ -483,6 +487,18 @@ public enum Feature {
483487
* @see net.sf.jsqlparser.statement.alter.AlterTablespace
484488
*/
485489
alterTablespace,
490+
/**
491+
* MySQL "CREATE SPATIAL REFERENCE SYSTEM" statement is allowed
492+
*
493+
* @see net.sf.jsqlparser.statement.create.spatial.CreateSpatialReferenceSystem
494+
*/
495+
createSpatialReferenceSystem,
496+
/**
497+
* MySQL "ALTER INSTANCE" statement is allowed
498+
*
499+
* @see net.sf.jsqlparser.statement.alter.AlterInstance
500+
*/
501+
alterInstance,
486502

487503

488504
/**
@@ -816,6 +832,18 @@ public enum Feature {
816832
* @see XaStatement
817833
*/
818834
xa,
835+
/**
836+
* MySQL and MariaDB INSTALL PLUGIN and UNINSTALL PLUGIN
837+
*
838+
* @see PluginStatement
839+
*/
840+
installPlugin,
841+
/**
842+
* MySQL INSTALL COMPONENT and UNINSTALL COMPONENT
843+
*
844+
* @see PluginStatement
845+
*/
846+
installComponent,
819847
/**
820848
* SQL "LOCK TABLE" statement is allowed
821849
*
@@ -979,6 +1007,13 @@ public enum Feature {
9791007
* @see ShowCreateStatement
9801008
*/
9811009
showCreate,
1010+
/**
1011+
* The MySQL/MariaDB "SHOW" statements of server settings, state and object lists, such as "SHOW
1012+
* VARIABLES", "SHOW GRANTS" or "SHOW BINLOG EVENTS"
1013+
*
1014+
* @see MySqlShowStatement
1015+
*/
1016+
mySqlShow,
9821017
/**
9831018
* @see UseStatement
9841019
*/
@@ -1037,6 +1072,54 @@ public enum Feature {
10371072
* @see net.sf.jsqlparser.statement.alter.AlterRule
10381073
*/
10391074
alterRule,
1075+
/**
1076+
* PostgreSQL "CREATE OPERATOR" statement is allowed
1077+
*
1078+
* @see net.sf.jsqlparser.statement.create.operator.CreateOperator
1079+
*/
1080+
createOperator,
1081+
/**
1082+
* PostgreSQL "CREATE OPERATOR CLASS" statement is allowed
1083+
*
1084+
* @see net.sf.jsqlparser.statement.create.operator.CreateOperatorClass
1085+
*/
1086+
createOperatorClass,
1087+
/**
1088+
* PostgreSQL "CREATE OPERATOR FAMILY" statement is allowed
1089+
*
1090+
* @see net.sf.jsqlparser.statement.create.operator.CreateOperatorFamily
1091+
*/
1092+
createOperatorFamily,
1093+
/**
1094+
* PostgreSQL "CREATE AGGREGATE" statement is allowed
1095+
*
1096+
* @see net.sf.jsqlparser.statement.create.aggregate.CreateAggregate
1097+
*/
1098+
createAggregate,
1099+
/**
1100+
* PostgreSQL "ALTER OPERATOR" statement is allowed
1101+
*
1102+
* @see net.sf.jsqlparser.statement.alter.AlterOperator
1103+
*/
1104+
alterOperator,
1105+
/**
1106+
* PostgreSQL "ALTER OPERATOR CLASS" statement is allowed
1107+
*
1108+
* @see net.sf.jsqlparser.statement.alter.AlterOperatorClass
1109+
*/
1110+
alterOperatorClass,
1111+
/**
1112+
* PostgreSQL "ALTER OPERATOR FAMILY" statement is allowed
1113+
*
1114+
* @see net.sf.jsqlparser.statement.alter.AlterOperatorFamily
1115+
*/
1116+
alterOperatorFamily,
1117+
/**
1118+
* PostgreSQL "ALTER AGGREGATE" statement is allowed
1119+
*
1120+
* @see net.sf.jsqlparser.statement.alter.AlterAggregate
1121+
*/
1122+
alterAggregate,
10401123
/**
10411124
* SQL block starting with "BEGIN" and ends with "END" statement is allowed
10421125
*
@@ -1047,6 +1130,24 @@ public enum Feature {
10471130
* @see DeclareStatement
10481131
*/
10491132
declare,
1133+
/**
1134+
* PostgreSQL "DECLARE name CURSOR FOR query" statement is allowed
1135+
*
1136+
* @see DeclareCursorStatement
1137+
*/
1138+
declareCursor,
1139+
/**
1140+
* PostgreSQL "FETCH" and "MOVE" statements of a cursor are allowed
1141+
*
1142+
* @see FetchCursorStatement
1143+
*/
1144+
fetchCursor,
1145+
/**
1146+
* PostgreSQL "CLOSE" statement of a cursor is allowed
1147+
*
1148+
* @see CloseCursorStatement
1149+
*/
1150+
closeCursor,
10501151

10511152
/** SQL Server local table variables in queries and DML targets. */
10521153
tableVariable,
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2026 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.statement;
11+
12+
import java.io.Serializable;
13+
import java.util.Objects;
14+
import java.util.function.Consumer;
15+
import net.sf.jsqlparser.expression.Expression;
16+
17+
/**
18+
* One assignment of the {@code SET} clause of MySQL's {@code INSTALL COMPONENT}:
19+
* {@code [GLOBAL | PERSIST] variable {= | :=} value}. The value is an expression, or the word
20+
* {@code ON}, which is read as a column.
21+
*
22+
* @see PluginStatement
23+
*/
24+
public class ComponentVariable implements Serializable {
25+
private SetScope scope = SetScope.NONE;
26+
private String name;
27+
private SetStatement.AssignmentOperator operator = SetStatement.AssignmentOperator.EQUALS;
28+
private Expression value;
29+
30+
public ComponentVariable(String name, Expression value) {
31+
this.name = Objects.requireNonNull(name, "name");
32+
this.value = Objects.requireNonNull(value, "value");
33+
}
34+
35+
/** {@link SetScope#GLOBAL}, {@link SetScope#PERSIST}, or {@link SetScope#NONE} if not given. */
36+
public SetScope getScope() {
37+
return scope;
38+
}
39+
40+
/**
41+
* Sets the scope keyword; null means none.
42+
*
43+
* @throws IllegalArgumentException for a scope other than GLOBAL, PERSIST or NONE
44+
*/
45+
public void setScope(SetScope scope) {
46+
SetScope value = scope == null ? SetScope.NONE : scope;
47+
if (value != SetScope.NONE && value != SetScope.GLOBAL && value != SetScope.PERSIST) {
48+
throw new IllegalArgumentException("INSTALL COMPONENT SET does not accept " + value);
49+
}
50+
this.scope = value;
51+
}
52+
53+
public ComponentVariable withScope(SetScope scope) {
54+
setScope(scope);
55+
return this;
56+
}
57+
58+
/** The variable name as written: {@code variable} or {@code component.variable}. */
59+
public String getName() {
60+
return name;
61+
}
62+
63+
public void setName(String name) {
64+
this.name = Objects.requireNonNull(name, "name");
65+
}
66+
67+
/** {@code =} or {@code :=}. */
68+
public SetStatement.AssignmentOperator getOperator() {
69+
return operator;
70+
}
71+
72+
/**
73+
* Sets the assignment operator.
74+
*
75+
* @throws IllegalArgumentException for an operator other than EQUALS or COLON_EQUALS
76+
*/
77+
public void setOperator(SetStatement.AssignmentOperator operator) {
78+
if (operator != SetStatement.AssignmentOperator.EQUALS
79+
&& operator != SetStatement.AssignmentOperator.COLON_EQUALS) {
80+
throw new IllegalArgumentException("INSTALL COMPONENT SET assigns with = or :=");
81+
}
82+
this.operator = operator;
83+
}
84+
85+
public ComponentVariable withOperator(SetStatement.AssignmentOperator operator) {
86+
setOperator(operator);
87+
return this;
88+
}
89+
90+
public Expression getValue() {
91+
return value;
92+
}
93+
94+
public void setValue(Expression value) {
95+
this.value = Objects.requireNonNull(value, "value");
96+
}
97+
98+
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> expressionPrinter) {
99+
if (scope != SetScope.NONE) {
100+
builder.append(scope.getKeyword()).append(' ');
101+
}
102+
builder.append(name).append(' ').append(operator.getToken()).append(' ');
103+
expressionPrinter.accept(value);
104+
return builder;
105+
}
106+
107+
@Override
108+
public String toString() {
109+
StringBuilder builder = new StringBuilder();
110+
return appendTo(builder, builder::append).toString();
111+
}
112+
}

‎src/main/java/net/sf/jsqlparser/statement/DefinitionElement.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
/**
1717
* One element of a PostgreSQL definition list, {@code name [= value]}, as in
18-
* {@code CREATE TYPE name (INPUT = fn, PASSEDBYVALUE)} or
19-
* {@code ALTER TYPE name SET (SEND = NONE)}. The name keeps its spelling and quoting.
18+
* {@code CREATE TYPE name (INPUT = fn, PASSEDBYVALUE)}, {@code ALTER TYPE name SET (SEND = NONE)},
19+
* {@code CREATE OPERATOR} or {@code CREATE AGGREGATE}. The name keeps its spelling and quoting.
2020
*/
2121
public class DefinitionElement implements Serializable {
2222
private String name;
@@ -62,6 +62,18 @@ public static String toString(List<DefinitionElement> elements) {
6262
return elements.stream().map(Object::toString).collect(Collectors.joining(", ", "(", ")"));
6363
}
6464

65+
/**
66+
* Finds an element of a definition list by its name, ignoring case.
67+
*
68+
* @param elements the elements
69+
* @param name the name, such as {@code INPUT}
70+
* @return the first element of that name, or {@code null}
71+
*/
72+
public static DefinitionElement find(List<DefinitionElement> elements, String name) {
73+
return elements.stream().filter(element -> name.equalsIgnoreCase(element.getName()))
74+
.findFirst().orElse(null);
75+
}
76+
6577
@Override
6678
public String toString() {
6779
return argument == null ? name : name + " = " + argument;

0 commit comments

Comments
 (0)