Skip to content

Commit b9c88ea

Browse files
fix: report a feature for every statement in StatementValidator (#2886)
1 parent 7123d25 commit b9c88ea

11 files changed

Lines changed: 305 additions & 91 deletions

File tree

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

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ public enum Feature {
510510
executeStatementImmediate,
511511

512512
executeUsing,
513+
/**
514+
* "PREPARE" and "DEALLOCATE" of a prepared statement are allowed
515+
*
516+
* @see net.sf.jsqlparser.statement.PrepareStatement
517+
* @see net.sf.jsqlparser.statement.DeallocateStatement
518+
*/
519+
prepare, deallocate,
513520
/**
514521
* SQL "REPLACE" statement is allowed
515522
*/
@@ -521,6 +528,12 @@ public enum Feature {
521528
* @see Drop
522529
*/
523530
drop, dropTable, dropIndex, dropView, dropSchema, dropSequence, dropTableIfExists, dropIndexIfExists, dropViewIfExists, dropSchemaIfExists, dropSequenceIfExists,
531+
/**
532+
* Oracle "PURGE" statement is allowed
533+
*
534+
* @see net.sf.jsqlparser.statement.PurgeStatement
535+
*/
536+
purge,
524537
/**
525538
* PostgreSQL "REASSIGN OWNED BY ... TO ..." statement is allowed
526539
*
@@ -540,6 +553,13 @@ public enum Feature {
540553
* @see net.sf.jsqlparser.statement.alter.database.AlterDatabase
541554
*/
542555
alterDatabase,
556+
/**
557+
* "ALTER SESSION" and "ALTER SYSTEM" statements are allowed
558+
*
559+
* @see net.sf.jsqlparser.statement.alter.AlterSession
560+
* @see net.sf.jsqlparser.statement.alter.AlterSystemStatement
561+
*/
562+
alterSession, alterSystem,
543563
/**
544564
* SQL "CREATE SCHEMA" statement is allowed
545565
*
@@ -628,6 +648,11 @@ public enum Feature {
628648
* Structured type, domain and extension statements.
629649
*/
630650
createType, alterType, createDomain, alterDomain, createExtension, alterExtension,
651+
/**
652+
* PostgreSQL "CREATE POLICY", "ALTER POLICY", "CREATE STATISTICS" and "ALTER STATISTICS"
653+
* statements are allowed
654+
*/
655+
createPolicy, alterPolicy, createStatistics, alterStatistics,
631656
/**
632657
* SQL "CREATE SYNONYM" statement is allowed
633658
*
@@ -638,6 +663,13 @@ public enum Feature {
638663
* SQL "CREATE TRIGGER" statement is allowed
639664
*/
640665
createTrigger,
666+
/**
667+
* MySQL/MariaDB "CREATE EVENT" and "ALTER EVENT" statements are allowed
668+
*
669+
* @see net.sf.jsqlparser.statement.create.event.CreateEvent
670+
* @see net.sf.jsqlparser.statement.create.event.AlterEvent
671+
*/
672+
createEvent, alterEvent,
641673
/**
642674
* PostgreSQL "CREATE EVENT TRIGGER" and "ALTER EVENT TRIGGER" statements are allowed
643675
*
@@ -664,8 +696,12 @@ public enum Feature {
664696
* @see Commit
665697
*/
666698
commit,
699+
/** SQL "ROLLBACK" statement is allowed */
700+
rollback,
667701
/** START TRANSACTION and dialect-specific BEGIN transaction statements. */
668702
startTransaction,
703+
/** SAVEPOINT statements. */
704+
savepoint,
669705
/** RELEASE [SAVEPOINT] statements. */
670706
releaseSavepoint,
671707
/** Explicit AND [NO] CHAIN transaction completion. */
@@ -676,6 +712,12 @@ public enum Feature {
676712
transactionDeferrable,
677713
/** MySQL WITH CONSISTENT SNAPSHOT transaction characteristic. */
678714
transactionConsistentSnapshot,
715+
/**
716+
* SQL "LOCK TABLE" statement is allowed
717+
*
718+
* @see net.sf.jsqlparser.statement.lock.LockStatement
719+
*/
720+
lock,
679721
/**
680722
* SQL "COMMENT ON" statement is allowed
681723
*
@@ -784,16 +826,17 @@ public enum Feature {
784826
*/
785827
grant, revoke, createRole, alterRole, alterDefaultPrivileges,
786828
/**
787-
* MySQL/MariaDB account management: "ALTER USER", "RENAME USER", "SET ROLE", "SET DEFAULT ROLE"
788-
* and "SET PASSWORD"
829+
* MySQL/MariaDB account management: "CREATE USER", "ALTER USER", "RENAME USER", "SET ROLE",
830+
* "SET DEFAULT ROLE" and "SET PASSWORD"
789831
*
832+
* @see net.sf.jsqlparser.statement.create.user.CreateUser
790833
* @see net.sf.jsqlparser.statement.alter.AlterUser
791834
* @see net.sf.jsqlparser.statement.alter.RenameUser
792835
* @see net.sf.jsqlparser.statement.SetRoleStatement
793836
* @see net.sf.jsqlparser.statement.SetDefaultRoleStatement
794837
* @see net.sf.jsqlparser.statement.SetPasswordStatement
795838
*/
796-
alterUser, renameUser, setRole, setDefaultRole, setPassword,
839+
createUser, alterUser, renameUser, setRole, setDefaultRole, setPassword,
797840
/**
798841
* @see Function
799842
*/
@@ -1041,10 +1084,38 @@ public enum Feature {
10411084
imprt,
10421085

10431086
/**
1044-
* "EXPORT"
1087+
* "EXPORT" and BigQuery "EXPORT DATA"
10451088
*/
10461089
export,
10471090

1091+
/**
1092+
* PostgreSQL and DuckDB "COPY" and BigQuery "LOAD DATA" statements are allowed
1093+
*
1094+
* @see net.sf.jsqlparser.statement.CopyStatement
1095+
* @see net.sf.jsqlparser.statement.load.LoadDataStatement
1096+
*/
1097+
copy, loadData,
1098+
1099+
/**
1100+
* DuckDB "ATTACH", "DETACH", "CONNECT", "DISCONNECT", "PRAGMA", "INSTALL", "LOAD", "CREATE
1101+
* MACRO" and "CREATE EXTENSION REPOSITORY" statements are allowed
1102+
*/
1103+
attach, detach, connect, disconnect, pragma, installExtension, loadExtension, createMacro, createExtensionRepository,
1104+
1105+
/**
1106+
* BigQuery "ASSERT" statement is allowed
1107+
*
1108+
* @see net.sf.jsqlparser.statement.AssertStatement
1109+
*/
1110+
assertStatement,
1111+
1112+
/**
1113+
* "SESSION" statement is allowed
1114+
*
1115+
* @see net.sf.jsqlparser.statement.SessionStatement
1116+
*/
1117+
session,
1118+
10481119
/**
10491120
* MySQL allows a ',' as a separator between key and value entries. We allow that by default,
10501121
* but it can be disabled here

‎src/main/java/net/sf/jsqlparser/util/validation/feature/FeaturesAllowed.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public class FeaturesAllowed implements FeatureSetValidation, ModifyableFeatureS
112112
Feature.createTableCreateOptionStrings, Feature.createTableTableOptionStrings,
113113
Feature.createTableIfNotExists, Feature.createTableRowMovement,
114114
Feature.createTableFromSelect,
115-
Feature.createTrigger, Feature.createEventTrigger,
115+
Feature.createTrigger, Feature.createEventTrigger, Feature.createEvent,
116+
Feature.createPolicy, Feature.createStatistics,
116117
Feature.createView).unmodifyable();
117118
/**
118119
* all "ALTER" {@link Feature}'s
@@ -122,7 +123,8 @@ public class FeaturesAllowed implements FeatureSetValidation, ModifyableFeatureS
122123
Feature.alterTextSearchConfiguration,
123124
Feature.alterCollation,
124125
Feature.alterTablespace,
125-
Feature.alterEventTrigger,
126+
Feature.alterEventTrigger, Feature.alterEvent,
127+
Feature.alterPolicy, Feature.alterStatistics,
126128
Feature.alterView, Feature.alterIndex, Feature.alterSchema,
127129
Feature.alterForeignDataWrapper, Feature.alterServer, Feature.alterUserMapping)
128130
.unmodifyable();

‎src/main/java/net/sf/jsqlparser/util/validation/feature/H2Version.java‎

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@
2424
*/
2525
public enum H2Version implements Version {
2626
V_1_4_200("1.4.200",
27-
EnumSet.of(
28-
// supported if used with jdbc
27+
EnumSet.of(// supported if used with jdbc
2928
Feature.jdbcParameter,
30-
Feature.jdbcNamedParameter,
31-
// expressions
32-
Feature.exprLike,
33-
// http://h2database.com/html/commands.html#select
29+
Feature.jdbcNamedParameter, // expressions
30+
Feature.exprLike, // http://h2database.com/html/commands.html#select
3431
Feature.select,
3532
Feature.selectGroupBy, Feature.function,
36-
Feature.selectHaving,
37-
// https://h2database.com/html/grammar.html?#table_expression
33+
Feature.selectHaving, // https://h2database.com/html/grammar.html?#table_expression
3834
// https://h2database.com/html/grammar.html?#join_specification
3935
Feature.join,
4036
Feature.joinSimple,
@@ -71,73 +67,54 @@ public enum H2Version implements Version {
7167
Feature.setOperationMinus,
7268

7369
// http://h2database.com/html/commands.html#create_sequence
74-
Feature.createSequence,
75-
// http://h2database.com/html/commands.html#alter_sequence
76-
Feature.alterSequence,
77-
// http://h2database.com/html/commands.html#create_schema
78-
Feature.createSchema,
79-
// http://h2database.com/html/commands.html#create_index
80-
Feature.createIndex,
81-
// http://h2database.com/html/commands.html#create_table
70+
Feature.createSequence, // http://h2database.com/html/commands.html#alter_sequence
71+
Feature.alterSequence, // http://h2database.com/html/commands.html#create_schema
72+
Feature.createSchema, // http://h2database.com/html/commands.html#create_index
73+
Feature.createIndex, // http://h2database.com/html/commands.html#create_table
8274
Feature.createTable, Feature.createTableCreateOptionStrings,
8375
Feature.createTableTableOptionStrings, Feature.createTableFromSelect,
84-
Feature.createTableIfNotExists,
85-
// http://h2database.com/html/commands.html#create_view
76+
Feature.createTableIfNotExists, // http://h2database.com/html/commands.html#create_view
8677
Feature.createView,
87-
Feature.createViewForce, Feature.createOrReplaceView,
88-
// http://h2database.com/html/commands.html#alter_view_rename
78+
Feature.createViewForce, Feature.createOrReplaceView, // http://h2database.com/html/commands.html#alter_view_rename
8979
// Feature.alterView,
9080

9181
// http://h2database.com/html/commands.html#select
92-
Feature.top,
93-
// http://www.h2database.com/html/advanced.html?search=limit#result_sets
82+
Feature.top, // http://www.h2database.com/html/advanced.html?search=limit#result_sets
9483
Feature.fetch, Feature.fetchFirst,
9584

9685
// http://www.h2database.com/html/commands.html?highlight=DISTINCT&search=SELECT#firstFound
97-
Feature.distinct,
98-
// http://www.h2database.com/html/commands.html?highlight=DISTINCT%20ON&search=SELECT#firstFound
99-
Feature.distinctOn,
100-
// http://h2database.com/html/commands.html#insert
86+
Feature.distinct, // http://www.h2database.com/html/commands.html?highlight=DISTINCT%20ON&search=SELECT#firstFound
87+
Feature.distinctOn, // http://h2database.com/html/commands.html#insert
10188
Feature.insert,
10289
Feature.insertValues,
10390
Feature.values,
104-
Feature.insertFromSelect,
105-
// http://h2database.com/html/commands.html#update
106-
Feature.update,
107-
// http://h2database.com/html/commands.html#delete
108-
Feature.delete,
109-
// http://h2database.com/html/commands.html#truncate_table
91+
Feature.insertFromSelect, // http://h2database.com/html/commands.html#update
92+
Feature.update, // http://h2database.com/html/commands.html#delete
93+
Feature.delete, // http://h2database.com/html/commands.html#truncate_table
11094
Feature.truncate,
11195

11296
// http://www.h2database.com/html/commands.html#execute_immediate
11397
Feature.executeStatementImmediate,
11498

11599
// http://h2database.com/html/commands.html#drop_table
116100
// http://h2database.com/html/commands.html#drop_index
117-
Feature.drop,
118-
// http://h2database.com/html/commands.html#drop_table
119-
Feature.dropTable,
120-
// http://h2database.com/html/commands.html#drop_index
121-
Feature.dropIndex,
122-
// http://h2database.com/html/commands.html#drop_view
123-
Feature.dropView,
124-
// http://h2database.com/html/commands.html#drop_schema
125-
Feature.dropSchema,
126-
// http://h2database.com/html/commands.html#drop_sequence
101+
Feature.drop, // http://h2database.com/html/commands.html#drop_table
102+
Feature.dropTable, // http://h2database.com/html/commands.html#drop_index
103+
Feature.dropIndex, // http://h2database.com/html/commands.html#drop_view
104+
Feature.dropView, // http://h2database.com/html/commands.html#drop_schema
105+
Feature.dropSchema, // http://h2database.com/html/commands.html#drop_sequence
127106
Feature.dropSequence,
128107
Feature.dropTableIfExists, Feature.dropIndexIfExists, Feature.dropViewIfExists,
129-
Feature.dropSchemaIfExists, Feature.dropSequenceIfExists,
130-
// http://h2database.com/html/commands.html#alter_table_add
108+
Feature.dropSchemaIfExists, Feature.dropSequenceIfExists, // http://h2database.com/html/commands.html#alter_table_add
131109
// http://h2database.com/html/commands.html#alter_table_add_constraint
132110
// ...
133-
Feature.alterTable,
134-
// http://www.h2database.com/html/commands.html#explain
135-
Feature.explain,
136-
// http://www.h2database.com/html/commands.html#grant_right
111+
Feature.alterTable, // http://www.h2database.com/html/commands.html#explain
112+
Feature.explain, // http://www.h2database.com/html/commands.html#grant_right
137113
// http://www.h2database.com/html/commands.html#grant_role
138-
Feature.grant,
139-
// http://h2database.com/html/commands.html#commit
140-
Feature.commit));
114+
Feature.grant, // http://h2database.com/html/commands.html#commit
115+
// http://h2database.com/html/commands.html#rollback
116+
// http://h2database.com/html/commands.html#savepoint
117+
Feature.commit, Feature.rollback, Feature.savepoint));
141118

142119
private Set<Feature> features;
143120
private String versionString;

‎src/main/java/net/sf/jsqlparser/util/validation/feature/MariaDbVersion.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ public enum MariaDbVersion implements Version {
8484
Feature.tableMaintenance,
8585

8686
// https://mariadb.com/kb/en/account-management-sql-statements/
87-
Feature.createRole, Feature.alterUser, Feature.renameUser, Feature.setRole,
87+
Feature.createRole, Feature.createUser, Feature.alterUser, Feature.renameUser,
88+
Feature.setRole,
8889
Feature.setDefaultRole, Feature.setPassword,
8990

9091
// https://mariadb.com/kb/en/call/
9192
Feature.execute, Feature.executeCall,
9293

94+
// https://mariadb.com/kb/en/deallocate-drop-prepare/
95+
Feature.deallocate,
96+
9397
// https://mariadb.com/kb/en/drop/
9498
Feature.drop, // https://mariadb.com/kb/en/drop-index/
9599
Feature.dropIndex, // https://mariadb.com/kb/en/drop-table/
@@ -121,6 +125,10 @@ public enum MariaDbVersion implements Version {
121125
Feature.createSchema, // https://mariadb.com/kb/en/create-trigger/
122126
Feature.createTrigger,
123127

128+
// https://mariadb.com/kb/en/create-event/
129+
// https://mariadb.com/kb/en/alter-event/
130+
Feature.createEvent, Feature.alterEvent,
131+
124132
// https://mariadb.com/kb/en/create-database/
125133
// https://mariadb.com/kb/en/alter-database/
126134
Feature.createDatabase, Feature.alterDatabase,
@@ -141,7 +149,9 @@ public enum MariaDbVersion implements Version {
141149
Feature.use, // https://mariadb.com/kb/en/grant/
142150
Feature.grant, // https://mariadb.com/kb/en/revoke/
143151
Feature.revoke, // https://mariadb.com/kb/en/commit/
144-
Feature.commit, // https://mariadb.com/kb/en/optimizer-hints/
152+
Feature.commit, // https://mariadb.com/kb/en/rollback/
153+
Feature.rollback, // https://mariadb.com/kb/en/savepoint/
154+
Feature.savepoint, // https://mariadb.com/kb/en/optimizer-hints/
145155
Feature.mySqlHintStraightJoin,
146156
Feature.mysqlSelectModifiers, Feature.mysqlCalcFoundRows,
147157
Feature.mysqlSqlCacheFlag)),

‎src/main/java/net/sf/jsqlparser/util/validation/feature/MySqlVersion.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ public enum MySqlVersion implements Version {
8080
Feature.tableMaintenance,
8181

8282
// https://dev.mysql.com/doc/refman/8.0/en/account-management-statements.html
83-
Feature.createRole, Feature.alterUser, Feature.renameUser, Feature.setRole,
83+
Feature.createRole, Feature.createUser, Feature.alterUser, Feature.renameUser,
84+
Feature.setRole,
8485
Feature.setDefaultRole, Feature.setPassword,
8586

8687
// https://dev.mysql.com/doc/refman/8.0/en/call.html
8788
Feature.execute, Feature.executeCall,
8889

90+
// https://dev.mysql.com/doc/refman/8.0/en/deallocate-prepare.html
91+
Feature.deallocate,
92+
8993
Feature.drop, // https://dev.mysql.com/doc/refman/8.0/en/drop-table.html
9094
Feature.dropTable, // https://dev.mysql.com/doc/refman/8.0/en/drop-index.html
9195
Feature.dropIndex, // https://dev.mysql.com/doc/refman/8.0/en/drop-view.html
@@ -121,6 +125,10 @@ public enum MySqlVersion implements Version {
121125
Feature.createIndex, // https://dev.mysql.com/doc/refman/8.0/en/create-trigger.html
122126
Feature.createTrigger,
123127

128+
// https://dev.mysql.com/doc/refman/8.0/en/create-event.html
129+
// https://dev.mysql.com/doc/refman/8.0/en/alter-event.html
130+
Feature.createEvent, Feature.alterEvent,
131+
124132
// https://dev.mysql.com/doc/refman/8.0/en/describe.html
125133
Feature.describe,
126134
Feature.desc, // https://dev.mysql.com/doc/refman/8.0/en/explain.html
@@ -134,7 +142,8 @@ public enum MySqlVersion implements Version {
134142
Feature.grant, // https://dev.mysql.com/doc/refman/8.0/en/revoke.html
135143
Feature.revoke, // https://dev.mysql.com/doc/refman/8.0/en/use.html
136144
Feature.use, // https://dev.mysql.com/doc/refman/8.0/en/commit.html
137-
Feature.commit, Feature.startTransaction, Feature.releaseSavepoint,
145+
Feature.commit, Feature.rollback, Feature.startTransaction,
146+
Feature.savepoint, Feature.releaseSavepoint,
138147
Feature.transactionChain, Feature.transactionConsistentSnapshot, //
139148
Feature.mySqlHintStraightJoin,
140149
Feature.mysqlSqlCacheFlag,

‎src/main/java/net/sf/jsqlparser/util/validation/feature/OracleVersion.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ public enum OracleVersion implements Version {
123123
Feature.createTrigger, // https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-SCHEMA.html
124124
Feature.createSchema,
125125

126-
Feature.commit,
126+
Feature.commit, Feature.rollback, Feature.savepoint,
127+
128+
// https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/LOCK-TABLE.html
129+
Feature.lock,
130+
131+
// https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/ALTER-SESSION.html
132+
// https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/ALTER-SYSTEM.html
133+
Feature.alterSession, Feature.alterSystem,
134+
135+
// https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/PURGE.html
136+
Feature.purge,
127137

128138
// https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/COMMENT.html
129139
Feature.comment, Feature.commentOnTable, Feature.commentOnColumn,

0 commit comments

Comments
 (0)