Repository navigation
Commit cec9fb8
authored
fix: reuse table constraints for ALTER TABLE ADD in every dialect (#2847)
* fix: reuse table constraints for ALTER TABLE ADD in every dialect
ALTER TABLE ADD parsed table constraints with the shared CREATE TABLE
production only for the MySQL and PostgreSQL dialects (#2612, #2654).
Without one of them, the generic ALTER branches rejected forms that
CREATE TABLE accepts in every dialect: an unnamed CHECK (c > 0),
NOT VALID, DEFERRABLE INITIALLY DEFERRED, an unnamed FOREIGN KEY with
attributes and EXCLUDE.
Route an ADD to the shared production in every dialect when it uses a
form that only that production accepts: an unnamed CHECK, FOREIGN KEY,
EXCLUDE, or INITIALLY IMMEDIATE|DEFERRED, NOT VALID or ENFORCED outside
a CHECK before the end of the action. Forms that already parsed keep
their generic representation, accessors and output; the PostgreSQL-only
UNIQUE USING INDEX and NOT NULL constraints still need that dialect.
The scan lives in the package-private AlterConstraintLookahead, like
RoutineBodyBoundary, because the generated CCJSqlParser class is close
to the size JaCoCo can still instrument.
Signed-off-by: minleejae <mmj9808@gmail.com>
* fix: parse VALIDATE CONSTRAINT as a structured action in every dialect
ALTER TABLE t VALIDATE CONSTRAINT ck was a structured RelationAlterAction
only with the PostgreSQL dialect. Elsewhere the remaining text became
an UNSPECIFIC expression, so the constraint name could not be read and
the action could not follow an ADD that now parses in every dialect.
VALIDATE CONSTRAINT starts no other ALTER TABLE action, so recognise it
in every dialect. Its output is unchanged.
Signed-off-by: minleejae <mmj9808@gmail.com>
* refactor: keep the ALTER constraint lookahead in the grammar
Move AlterConstraintLookahead from its own file into the grammar as a
private nested class, as done for TokenNesting in #2849. Split
needsSharedTableConstraint into a check for the forms only the shared
production accepts and a scan for constraint attributes. Codacy's PMD
reported an NPath complexity of 440 for the combined method; the
largest part is now 14. The nested class keeps its branches out of
CCJSqlParser.class. Behaviour does not change.
Signed-off-by: minleejae <mmj9808@gmail.com>
---------
Signed-off-by: minleejae <mmj9808@gmail.com>1 parent 220d0ed commit cec9fb8
3 files changed
Lines changed: 229 additions & 2 deletions
File tree
- src
- main/jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser/statement/alter
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2544 | 2544 | | |
2545 | 2545 | | |
2546 | 2546 | | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
2547 | 2626 | | |
2548 | 2627 | | |
2549 | 2628 | | |
| |||
3064 | 3143 | | |
3065 | 3144 | | |
3066 | 3145 | | |
| 3146 | + | |
| 3147 | + | |
3067 | 3148 | | |
3068 | 3149 | | |
3069 | 3150 | | |
| |||
21081 | 21162 | | |
21082 | 21163 | | |
21083 | 21164 | | |
21084 | | - | |
| 21165 | + | |
21085 | 21166 | | |
21086 | 21167 | | |
21087 | 21168 | | |
21088 | 21169 | | |
21089 | 21170 | | |
21090 | | - | |
| 21171 | + | |
| 21172 | + | |
21091 | 21173 | | |
21092 | 21174 | | |
21093 | 21175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
232 | 249 | | |
233 | 250 | | |
234 | 251 | | |
| |||
0 commit comments