diff --git a/zpa-checks/src/integrationTest/resources/expected/antlr-grammars-v4/ParsingErrorCheck.json b/zpa-checks/src/integrationTest/resources/expected/antlr-grammars-v4/ParsingErrorCheck.json index f81fb24a..c8781d9b 100644 --- a/zpa-checks/src/integrationTest/resources/expected/antlr-grammars-v4/ParsingErrorCheck.json +++ b/zpa-checks/src/integrationTest/resources/expected/antlr-grammars-v4/ParsingErrorCheck.json @@ -413,9 +413,6 @@ "examples/single_statement.sql" : [ 1 ], - "examples/to_dsinterval.sql" : [ - 3 - ], "examples/to_number.sql" : [ 6 ], @@ -425,9 +422,6 @@ "examples/to_timestamp_tz.sql" : [ 6 ], - "examples/to_yminterval.sql" : [ - 3 - ], "examples/truncate_cluster.sql" : [ 1 ], 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 41d98919..13630a5d 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 @@ -2858,9 +2858,6 @@ "sqlrf/Syntax-for-Schema-Objects-and-Parts-in-SQL-Statements-4.sql" : [ 3 ], - "sqlrf/TO_DSINTERVAL-2.sql" : [ - 3 - ], "sqlrf/TO_NUMBER-2.sql" : [ 2 ], diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt index 0812a03c..7b59f8d0 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt @@ -519,6 +519,7 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa TO_BINARY_FLOAT("to_binary_float"), TO_BOOLEAN("to_boolean"), TO_DATE("to_date"), + TO_DSINTERVAL("to_dsinterval"), TRAILING("trailing"), TRANSACTION("transaction"), TREAT("treat"), 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 c4124293..55a9f081 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 @@ -132,6 +132,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { TO_BINARY_FLOAT_EXPRESSION, TO_BOOLEAN_EXPRESSION, TO_DATE_EXPRESSION, + TO_DSINTERVAL_EXPRESSION, TRIM_EXPRESSION, TABLE_EXPRESSION, THE_EXPRESSION, @@ -187,6 +188,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { TO_BINARY_FLOAT_EXPRESSION, TO_BOOLEAN_EXPRESSION, TO_DATE_EXPRESSION, + TO_DSINTERVAL_EXPRESSION, TRIM_EXPRESSION, TABLE_EXPRESSION, THE_EXPRESSION, @@ -257,6 +259,13 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { RPARENTHESIS ) + b.rule(TO_DSINTERVAL_EXPRESSION).define( + TO_DSINTERVAL, LPARENTHESIS, + EXPRESSION, + b.optional(DEFAULT_ON_ERROR_CLAUSE), + RPARENTHESIS + ) + b.rule(TABLE_EXPRESSION).define( TABLE, LPARENTHESIS, b.firstOf(DmlGrammar.SELECT_EXPRESSION, EXPRESSION), diff --git a/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/expressions/ToDsintervalExpressionTest.kt b/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/expressions/ToDsintervalExpressionTest.kt new file mode 100644 index 00000000..24450530 --- /dev/null +++ b/zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/expressions/ToDsintervalExpressionTest.kt @@ -0,0 +1,45 @@ +/** + * Z PL/SQL Analyzer + * Copyright (C) 2015-2024 Felipe Zorzo + * mailto:felipe AT felipezorzo DOT com DOT br + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.plugins.plsqlopen.api.expressions + +import com.felipebz.flr.tests.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.sonar.plugins.plsqlopen.api.PlSqlGrammar +import org.sonar.plugins.plsqlopen.api.RuleTest + +class ToDsintervalExpressionTest : RuleTest() { + + @BeforeEach + fun init() { + setRootRule(PlSqlGrammar.EXPRESSION) + } + + @Test + fun matchesSimple() { + assertThat(p).matches("to_dsinterval(foo)") + } + + @Test + fun matchesDefaultClause() { + assertThat(p).matches("to_dsinterval(foo default false on conversion error)") + } + +}