Skip to content

Commit 57117d0

Browse files
committedOct 11, 2024··
fix(grammar): Support CONSTRAINTS keyword in inline and out-of-line constraints as an alternative to CONSTRAINT
Although it seems that this syntax has never been documented in the last 20 years in Oracle docs and causes parsing errors in Oracle SQL Developer, testing shows that it is still accepted by the Oracle 23.5 compiler. Ref: https://docs.oracle.com/cd/A87860_01/doc/server.817/a85397/state14a.htm (Oracle 8i docs) https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/constraint.html (Oracle 23ai docs) Based on debezium/debezium#5612
1 parent 2a75820 commit 57117d0

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed
 

‎zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/DdlGrammar.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ enum class DdlGrammar : GrammarRuleKey {
118118
)
119119

120120
b.rule(INLINE_CONSTRAINT).define(
121-
b.optional(CONSTRAINT, IDENTIFIER_NAME),
121+
b.optional(b.firstOf(CONSTRAINT, CONSTRAINTS), IDENTIFIER_NAME),
122122
b.firstOf(
123123
b.sequence(
124124
b.firstOf(
@@ -160,7 +160,7 @@ enum class DdlGrammar : GrammarRuleKey {
160160
b.zeroOrMore(INLINE_CONSTRAINT))
161161

162162
b.rule(OUT_OF_LINE_CONSTRAINT).define(
163-
b.optional(CONSTRAINT, IDENTIFIER_NAME),
163+
b.optional(b.firstOf(CONSTRAINT, CONSTRAINTS), IDENTIFIER_NAME),
164164
b.firstOf(
165165
b.sequence(
166166
b.firstOf(

‎zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa
170170
CONNECT_BY_ROOT("connect_by_root"),
171171
CONSTANT("constant"),
172172
CONSTRAINT("constraint"),
173+
CONSTRAINTS("constraints"),
173174
CONSTRUCTOR("constructor"),
174175
CONTAINER("container"),
175176
CONTENT("content"),

‎zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/ddl/InlineConstraintTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class InlineConstraintTest : RuleTest() {
8787
@Test
8888
fun matchesConstraintWithName() {
8989
assertThat(p).matches("constraint pk primary key")
90+
assertThat(p).matches("constraints pk primary key")
9091
}
9192

9293
@Test

‎zpa-core/src/test/kotlin/org/sonar/plugins/plsqlopen/api/ddl/OutOfLineConstraintTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class OutOfLineConstraintTest : RuleTest() {
7272
@Test
7373
fun matchesConstraintWithName() {
7474
assertThat(p).matches("constraint pk primary key (foo)")
75+
assertThat(p).matches("constraints pk primary key (foo)")
7576
}
7677

7778
@Test

0 commit comments

Comments
 (0)
Please sign in to comment.