我想要实现的只是用 ILIKE 代替比较等于,而不是赋值语句。
IE
SELECT * FROM db WHERE SUBJECT_TYPE = 'Person';
应该替换为
SELECT * FROM db WHERE SUBJECT_TYPE ILIKE 'Person';
然而
SET session ABC.VAR = 5;
应该保持不变。
为此,我正在尝试使用前瞻性,以便在等于 (=)之前没有SET。
爪哇
String str = "SELECT * FROM db WHERE SUBJECT_TYPE = 'Person' AND PREDICATE = 'name' AND OBJECT_VALUE = 'John' AND VERSION = '0' "
final Pattern EQUALS_ILIKE_PATTERN = Pattern.compile("(?i)((^((?!SET)[^=])+?)\\s*)=");
final Matcher matcher = EQUALS_ILIKE_PATTERN .matcher(str);
while (matcher.find())
{
final String fromString = matcher.group(0);
str = matcher.replaceAll("$1 ILIKE");
}
System.out.println(str);
实际结果:
SELECT * FROM DB WHERE SUBJECT_TYPE ILIKE 'Person' AND PREDICATE = 'name' AND OBJECT_VALUE = 'John' AND VERSION = '0'
预期结果:
SELECT * FROM DB WHERE SUBJECT_TYPE ILIKE 'Person' AND PREDICATE ILIKE 'name' AND OBJECT_VALUE ILIKE 'John' AND VERSION ILIKE '0'
这里的实际结果不会替换所有必要的等号 (=)。
DIEA
相关分类