补齐旧版数据库兼容查询的字符替换层级,并增加完整表达式静态断言,避免替换参数落在函数之外。
@@ -108,20 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where user_type = '0'
and status = '0'
and (del_flag = '0' or del_flag is null)
- and replace(
- replace(
- replace(phone, ' ', ''),
- char(9), ''),
- char(10), ''),
- char(13), ''),
- '(', ''),
- ')', ''),
- '+', ''),
- '-', '') = #{normalizedPhone}
+ and replace(replace(replace(replace(replace(replace(replace(replace(phone, ' ', ''), char(9), ''), char(10), ''), char(13), ''), '(', ''), ')', ''), '+', ''), '-', '') = #{normalizedPhone}
order by user_id
limit 2
</select>
@@ -36,6 +36,9 @@ class FlashDeliveryMapperXmlTest {
assertTrue(xml.contains("char(9)"));
assertTrue(xml.contains("char(10)"));
assertTrue(xml.contains("char(13)"));
+ assertTrue(xml.contains("replace(replace(replace(replace(replace(replace(replace(replace(phone, "
+ + "' ', ''), char(9), ''), char(10), ''), char(13), ''), '(', ''), ')', ''), '+', ''), "
+ + "'-', '') = #{normalizedphone}"));
assertTrue(xml.contains("limit 2"));
}