MCPcopy Index your code
hub / github.com/apache/groovy / nullify

Method nullify

subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java:4696–4718  ·  view source on GitHub ↗

Hook to allow derived classes to override null handling. Default behavior is to replace ?'"? references with NULLish @param sql the SQL statement @return the modified SQL String

(String sql)

Source from the content-addressed store, hash-verified

4694 * @return the modified SQL String
4695 */
4696 protected String nullify(String sql) {
4697 /*
4698 * Some drivers (Oracle classes12.zip) have difficulty resolving data
4699 * type if setObject(null). We will modify the query to pass 'null', 'is
4700 * null', and 'is not null'
4701 */
4702 //could be more efficient by compiling expressions in advance.
4703 int firstWhere = findWhereKeyword(sql);
4704 if (firstWhere >= 0) {
4705 Pattern[] patterns = {Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
4706 Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
4707 Pattern.compile("(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),};
4708 String[] replacements = {"$1 is not $2null$3", "$1 is not $2null$3", "$1 is $2null$3",};
4709 for (int i = 0; i < patterns.length; i++) {
4710 Matcher matcher = patterns[i].matcher(sql);
4711 while (matcher.matches()) {
4712 sql = matcher.replaceAll(replacements[i]);
4713 matcher = patterns[i].matcher(sql);
4714 }
4715 }
4716 }
4717 return sql.replaceAll("\\?'\"\\?", "null");
4718 }
4719
4720 /**
4721 * Hook to allow derived classes to override where clause sniffing.

Callers 1

asSqlMethod · 0.95

Calls 4

findWhereKeywordMethod · 0.95
compileMethod · 0.65
matchesMethod · 0.65
replaceAllMethod · 0.45

Tested by

no test coverage detected