Commit 9cb9ede
committed
Handle NO_AUTO_VALUE_ON_ZERO in the INSERT translator
By default, MySQL treats a literal 0 in an AUTO_INCREMENT column the
same as NULL and generates the next sequence value. This behavior is
suppressed by the NO_AUTO_VALUE_ON_ZERO SQL mode, which is not part of
the default modes.
To emulate this on SQLite, rewrite the value to NULL via
NULLIF(CAST(... AS INTEGER), 0). The explicit CAST is required because
SQLite compares storage classes strictly, so NULLIF('0', 0) returns
'0', not NULL — and WordPress 1.0 emits the string form.
Also exclude AUTO_INCREMENT columns from the non-strict IMPLICIT
DEFAULT COALESCE wrapping, so a NULL (original or rewritten from 0)
always advances the sequence.
See: https://dev.mysql.com/doc/refman/8.4/en/sql-mode.html#sqlmode_no_auto_value_on_zero1 parent 3a3baf7 commit 9cb9ede
2 files changed
Lines changed: 98 additions & 4 deletions
File tree
- packages/mysql-on-sqlite
- src/sqlite
- tests
Lines changed: 27 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5132 | 5132 | | |
5133 | 5133 | | |
5134 | 5134 | | |
5135 | | - | |
5136 | | - | |
5137 | | - | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
| 5140 | + | |
| 5141 | + | |
| 5142 | + | |
| 5143 | + | |
| 5144 | + | |
| 5145 | + | |
| 5146 | + | |
| 5147 | + | |
| 5148 | + | |
| 5149 | + | |
| 5150 | + | |
| 5151 | + | |
| 5152 | + | |
5138 | 5153 | | |
5139 | 5154 | | |
5140 | 5155 | | |
5141 | 5156 | | |
5142 | 5157 | | |
5143 | 5158 | | |
5144 | 5159 | | |
| 5160 | + | |
| 5161 | + | |
| 5162 | + | |
5145 | 5163 | | |
5146 | 5164 | | |
5147 | | - | |
| 5165 | + | |
| 5166 | + | |
| 5167 | + | |
| 5168 | + | |
| 5169 | + | |
| 5170 | + | |
5148 | 5171 | | |
5149 | 5172 | | |
5150 | 5173 | | |
| |||
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2671 | 2671 | | |
2672 | 2672 | | |
2673 | 2673 | | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
2674 | 2745 | | |
2675 | 2746 | | |
2676 | 2747 | | |
| |||
0 commit comments