-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(database/gdb): incorrect DATE field formatting in WHERE conditions #4360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… in WHERE conditions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes incorrect DATE field formatting in WHERE conditions for the GDB database package. The issue occurred when gtime.Time objects were formatted as 'YYYY-MM-DD HH:MM:SS' in WHERE clauses but as 'YYYY-MM-DD' in INSERT/UPDATE statements for DATE type fields, causing condition matching failures.
Key changes:
- Added type-aware value conversion in
formatWhereHoldermethod for time-related fields - Reuses existing
ConvertValueForFieldmethod to ensure consistent type conversion logic - Only affects WHERE conditions with YEAR/DATE/TIME fields without impacting other query types
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
问题描述
在构建 INSERT/UPDATE 语句时,gtime.Time 对象会根据 MySQL 字段类型(如 DATE)自动格式化为 'YYYY-MM-DD',但在 WHERE 条件中却会变成 'YYYY-MM-DD HH:MM:SS',导致条件匹配失败。
修复方案
在 formatWhereHolder 方法中,对 WHERE 条件的字段值进行类型感知转换,确保 DATE 类型字段的值格式与 INSERT/UPDATE 语句一致。
复用 ConvertValueForField 方法,保持类型转换逻辑统一。
影响范围
仅影响涉及 YEAR/DATE/TIME 字段的 WHERE 条件构建。
不会影响现有非时间类型的查询。