felipebz / zpa

Parser and static code analysis tool for PL/SQL and Oracle SQL.
https://zpa.felipebz.com
GNU Lesser General Public License v3.0
211 stars 77 forks source link

schemaValidation check #175

Open csrvsk opened 10 months ago

csrvsk commented 10 months ago

Hi felipe,

I am trying to find a way to validate schema names (supplied list) using SQL operations like

private static final List<String> SQL_OPERATIONS = Arrays.asList(
    "CREATE TABLE", "ALTER TABLE", "DROP TABLE",
    "CREATE INDEX", "ALTER INDEX", "DROP INDEX",
    "CREATE VIEW", "ALTER VIEW", "DROP VIEW",
    "CREATE PROCEDURE", "ALTER PROCEDURE", "DROP PROCEDURE",
    "CREATE FUNCTION", "ALTER FUNCTION", "DROP FUNCTION",
    "CREATE TRIGGER", "ALTER TRIGGER", "DROP TRIGGER",
    "CREATE SEQUENCE", "ALTER SEQUENCE", "DROP SEQUENCE",
    "CREATE SYNONYM", "DROP SYNONYM",
    "CREATE PACKAGE", "ALTER PACKAGE", "DROP PACKAGE",
    "CREATE TYPE", "ALTER TYPE", "DROP TYPE"
);

Please guide me how to achieve this...

Goal is to make sure that usage of above SQL operations in the code must comply with schemaName standards or conditions as specified.

I am able to find a way to validate schema (with the format of schemaName.tableName) name while using CREATE_TABLE and also ALTER_TABLE from DdlGrammar.

Right now I am unable to figure out the right constant for DROP TABLE. Not sure about other other SQL operations. Please advise on other operations as well.

Or If you have a more direct and straight forward approach for schemaValidation, please guide me how to implement a check.

Just FYI, I have also tried ZPA parser tool to check for DROP TABLE

image

Looking at that I subscribed to DROP_COMMAND, but it doesn't work either.

Thanks vsk