fix(database/gdb): incorrect DATE field formatting in WHERE conditions #4360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在构建 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 条件构建。
不会影响现有非时间类型的查询。