From 27c4fb88fad9c5c40ade6edf3cd54bc4c89b65b4 Mon Sep 17 00:00:00 2001 From: Felipe Zorzo Date: Sun, 29 Sep 2024 22:41:47 -0300 Subject: [PATCH] fix(grammar): Support more datatypes in JSON_RETURNING_CLAUSE, JSON_VALUE_RETURN_TYPE and JSON_TRANSFORM_RETURNING_CLAUSE The Oracle documentation shows only "VARCHAR2" but "VARCHAR" and "CHAR" are supported too, for example --- .../CharacterDatatypeUsageCheck.json | 3 ++ .../oracle-database_23/ParsingErrorCheck.json | 3 -- .../SelectAllColumnsCheck.json | 3 ++ .../UnnecessaryAliasInQueryCheck.json | 3 ++ .../api/SingleRowSqlFunctionsGrammar.kt | 31 +++---------------- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/CharacterDatatypeUsageCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/CharacterDatatypeUsageCheck.json index 9494229a..11892669 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/CharacterDatatypeUsageCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/CharacterDatatypeUsageCheck.json @@ -1,4 +1,7 @@ { + "adjsn/function-JSON_TABLE-3.sql" : [ + 12 + ], "adjsn/generation-26.sql" : [ 5 ], diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json index ae7ecc40..f38112b1 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/ParsingErrorCheck.json @@ -26,9 +26,6 @@ "adjsn/function-JSON_TABLE-23.sql" : [ 3 ], - "adjsn/function-JSON_TABLE-3.sql" : [ - 12 - ], "adjsn/function-JSON_VALUE-3.sql" : [ 4 ], diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/SelectAllColumnsCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/SelectAllColumnsCheck.json index e883446a..b5c09601 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/SelectAllColumnsCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/SelectAllColumnsCheck.json @@ -17,6 +17,9 @@ "adjsn/function-JSON_TABLE-22.sql" : [ 3 ], + "adjsn/function-JSON_TABLE-3.sql" : [ + 2 + ], "adjsn/function-JSON_TABLE-8.sql" : [ 2 ], diff --git a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/UnnecessaryAliasInQueryCheck.json b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/UnnecessaryAliasInQueryCheck.json index f0ca4016..4492bbe8 100644 --- a/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/UnnecessaryAliasInQueryCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/oracle-database_23/UnnecessaryAliasInQueryCheck.json @@ -31,6 +31,9 @@ "adjsn/function-JSON_TABLE-22.sql" : [ 4 ], + "adjsn/function-JSON_TABLE-3.sql" : [ + 3 + ], "adjsn/generation-36.sql" : [ 7, 9 diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt index a41927bb..08952d91 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt @@ -517,8 +517,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { RETURNING, b.firstOf( b.sequence( - VARCHAR2, - b.optional(LPARENTHESIS, PlSqlTokenType.INTEGER_LITERAL, b.optional(b.firstOf(CHAR, BYTE)), RPARENTHESIS), + CHARACTER_DATAYPE, b.optional(WITH, TYPENAME) ), b.sequence( @@ -798,25 +797,11 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { b.rule(JSON_VALUE_RETURN_TYPE).define( b.firstOf( b.sequence( - VARCHAR2, - b.optional( - LPARENTHESIS, - PlSqlTokenType.INTEGER_LITERAL, - b.optional(b.firstOf(CHAR, BYTE)), - RPARENTHESIS - ), + CHARACTER_DATAYPE, b.optional(TRUNCATE) ), CLOB, - b.sequence( - NUMBER, - b.optional( - LPARENTHESIS, - PlSqlTokenType.INTEGER_LITERAL, - b.optional(COMMA, PlSqlTokenType.INTEGER_LITERAL), - RPARENTHESIS - ) - ), + NUMERIC_DATATYPE, b.sequence(b.firstOf(ALLOW, DISALLOW), b.optional(BOOLEAN), TO, NUMBER, b.optional(CONVERSION)), b.sequence(DATE, b.optional(b.firstOf(TRUNCATE, PRESERVE), TIME)), b.sequence(TIMESTAMP, b.optional(WITH, TIME, ZONE)), @@ -897,15 +882,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { b.rule(JSON_TRANSFORM_RETURNING_CLAUSE).define( RETURNING, b.firstOf( - b.sequence( - VARCHAR2, - b.optional( - LPARENTHESIS, - PlSqlTokenType.INTEGER_LITERAL, - b.optional(b.firstOf(CHAR, BYTE)), - RPARENTHESIS - ) - ), + CHARACTER_DATAYPE, b.sequence( b.firstOf(CLOB, BLOB), b.optional(b.firstOf(REFERENCE, VALUE))