DATE_ADD() and DATE_SUB() differ from MySQL for DATE values, month ends, and QUARTER and composite units
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 40/100
Hướng nghiên cứu
The fix belongs in the shared translation that translate_interval_arithmetic() performs, which the issue says #510 introduces, so check whether #510 has landed before starting. Run the SQL cases from the report against the plugin and compare each result with the MySQL values listed, covering return type, month-end clamping, QUARTER and composite units, and ADDDATE/SUBDATE. Done when every case in the report matches MySQL and the existing tests still pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Reproduction
CREATE TABLE s (id INT PRIMARY KEY, renews_on DATE);
INSERT INTO s VALUES (1, '2026-01-31');
-- 1. A DATE with a date-only unit returns a DATETIME.
SELECT DATE_ADD('2026-09-01', INTERVAL 7 DAY); -- '2026-09-08 00:00:00' (MySQL: '2026-09-08')
SELECT COUNT(*) FROM s WHERE DATE_ADD(renews_on, INTERVAL 7 DAY) = '2026-02-07';
-- 0 (MySQL: 1)
-- 2. Month and year arithmetic overflows instead of clamping to the last day of the month.
SELECT DATE_ADD('2024-01-31', INTERVAL 1 MONTH); -- '2024-03-02 00:00:00' (MySQL: '2024-02-29')
SELECT DATE_ADD('2024-02-29', INTERVAL 1 YEAR); -- '2025-03-01 00:00:00' (MySQL: '2025-02-28')
UPDATE s SET renews_on = DATE_ADD(renews_on, INTERVAL 1 MONTH);
-- stores '2026-03-03' (MySQL: '2026-02-28')
-- 3. QUARTER and composite units return NULL.
SELECT DATE_ADD('2026-01-15', INTERVAL 1 QUARTER); -- NULL (MySQL: '2026-04-15')
SELECT DATE_ADD('2026-01-15 10:00:00', INTERVAL '1:30' HOUR_MINUTE); -- NULL (MySQL: '2026-01-15 11:30:00')
UPDATE s SET renews_on = DATE_ADD(renews_on, INTERVAL 1 QUARTER);
-- stores NULL, even in strict mode
-- 4. ADDDATE() and SUBDATE() are not supported.
SELECT ADDDATE('2026-07-13', INTERVAL 7 DAY); -- syntax error (MySQL: '2026-07-20')
SELECT SUBDATE('2026-07-13', 7); -- no such function (MySQL: '2026-07-06')
Reproduced on trunk (5deb4d6) with PHP 8.3 and SQLite 3.45.1. The first case was found by a real query comparing a DATE column with DATE_ADD().
Impact
- Case 1 affects reads only. On write, the value is cast to the column type, so a
DATEcolumn still stores'2026-09-08'. But comparisons againstDATE_ADD()on aDATEvalue never match. - Cases 2 and 3 silently store wrong data. A monthly renewal from January 31 lands on March 3, and a quarterly one erases the date.
Notes
#510 mentions cases 1 to 3 as "worth their own change" and moves the shared translation into translate_interval_arithmetic(), so a fix would best build on it. MySQL's rules, from the date and time functions docs:
- The result is a
DATEwhen the input is aDATEand the unit isYEAR,QUARTER,MONTH,WEEK, orDAY(or a composite of them, likeYEAR_MONTH). Otherwise, it is aDATETIME. - When
MONTH,QUARTER, orYEARarithmetic produces a day that doesn't exist in the resulting month, it is adjusted to the last day of that month. ADDDATE(date, INTERVAL ...)is a synonym forDATE_ADD(), andADDDATE(date, days)adds days. The same applies toSUBDATE().
I'm happy to contribute a PR on top of #510, or separately if you prefer.
Use of AI
This report was prepared with Claude Code.
- Ngôn ngữ chính
- PHP
- Star
- 362
- Fork
- 69
- Merge trung bình
- 4 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 9
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của WordPress/sqlite-database-integration
-
MySQL-on-SQLite does not translate DATE arithmetic with INTERVAL HOURCó thể đã có người làm @samuelmbabhazi đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
WordPress/sqlite-database-integration#454 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
WordPress/sqlite-database-integration#529 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
WordPress/sqlite-database-integration#528 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 52/100
WordPress/sqlite-database-integration#527 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
WordPress/sqlite-database-integration#526 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của WordPress/sqlite-database-integration
Issue tương tự
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
scanaislop/aislop#482 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug UI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày