Creates a boolean expression of the form
bFunc(x1) AND bFunc(x2)
AND ... AND bFunc(xn)
. This function can be used to create SQL queries where
many table fields have to be checked in the same way for some criterion (see
example).
hsSqlExAnd(x, bFunc)
x | vector of strings, e.g. representing table field names. |
---|---|
bFunc | name of a boolean function to be “applied” to each element of x. |
## Build SQL query finding records in table t in which all ## of the table fields f1 to f100 are NULL. sql <- sprintf("SELECT * FROM t WHERE %s", hsSqlExAnd(paste("f", 1:100, sep = ""), "isNull")) ## Show the SQL string sql#> [1] "SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND isNull(f2) AND isNull(f3) AND isNull(f4) AND isNull(f5) AND isNull(f6) AND isNull(f7) AND isNull(f8) AND isNull(f9) AND isNull(f10) AND isNull(f11) AND isNull(f12) AND isNull(f13) AND isNull(f14) AND isNull(f15) AND isNull(f16) AND isNull(f17) AND isNull(f18) AND isNull(f19) AND isNull(f20) AND isNull(f21) AND isNull(f22) AND isNull(f23) AND isNull(f24) AND isNull(f25) AND isNull(f26) AND isNull(f27) AND isNull(f28) AND isNull(f29) AND isNull(f30) AND isNull(f31) AND isNull(f32) AND isNull(f33) AND isNull(f34) AND isNull(f35) AND isNull(f36) AND isNull(f37) AND isNull(f38) AND isNull(f39) AND isNull(f40) AND isNull(f41) AND isNull(f42) AND isNull(f43) AND isNull(f44) AND isNull(f45) AND isNull(f46) AND isNull(f47) AND isNull(f48) AND isNull(f49) AND isNull(f50) AND isNull(f51) AND isNull(f52) AND isNull(f53) AND isNull(f54) AND isNull(f55) AND isNull(f56) AND isNull(f57) AND isNull(f58) AND isNull(f59) AND isNull(f60) AND isNull(f61) AND isNull(f62) AND isNull(f63) AND isNull(f64) AND isNull(f65) AND isNull(f66) AND isNull(f67) AND isNull(f68) AND isNull(f69) AND isNull(f70) AND isNull(f71) AND isNull(f72) AND isNull(f73) AND isNull(f74) AND isNull(f75) AND isNull(f76) AND isNull(f77) AND isNull(f78) AND isNull(f79) AND isNull(f80) AND isNull(f81) AND isNull(f82) AND isNull(f83) AND isNull(f84) AND isNull(f85) AND isNull(f86) AND isNull(f87) AND isNull(f88) AND isNull(f89) AND isNull(f90) AND isNull(f91) AND isNull(f92) AND isNull(f93) AND isNull(f94) AND isNull(f95) AND isNull(f96) AND isNull(f97) AND isNull(f98) AND isNull(f99) AND isNull(f100)"## Output (middle part omitted): # SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND # isNull(f2) AND isNull(f3) AND ... AND isNull(f100)