public function conditionExpr($Field, $Value, $EscapeFieldSql = true, $EscapeValueSql = true)
{
// Change some variables from the old parameter style to the new one.
// THIS PART OF THE FUNCTION SHOULD EVENTUALLY BE REMOVED.
if ($EscapeFieldSql === false) {
$Field = '@' . $Field;
}
if (is_array($Value)) {
throw new Exception('Gdn_SQL->ConditionExpr(VALUE, ARRAY) is not supported.', 500);
} elseif (!$EscapeValueSql && !is_null($Value)) {
$Value = '@' . $Value;
}
// Check for a straight literal field expression.
if (!$EscapeFieldSql && !$EscapeValueSql && is_null($Value)) {
return substr($Field, 1);
// warning: might not be portable across different drivers
}
$Expr = '';
// final expression which is built up
$Op = '';
// logical operator
// Try and split an operator out of $Field.
$FieldOpRegex = "/(?:\\s*(=|<>|>|<|>=|<=)\\s*\$)|\\s+(like|not\\s+like)\\s*\$|\\s+(?:(is)\\s+(null)|(is\\s+not)\\s+(null))\\s*\$/i";
$Split = preg_split($FieldOpRegex, $Field, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
if (count($Split) > 1) {
$Field = $Split[0];
$Op = strtolower($Split[1]);
if (count($Split) > 2) {
$Value = null;
}
} else {
$Op = '=';
}
if ($Op == '=' && is_null($Value)) {
// This is a special case where the value SQL is checking for an is null operation.
$Op = 'is';
$Value = '@null';
$EscapeValueSql = false;
}
// Add the left hand side of the expression.
$Expr .= $this->_parseExpr($Field, null, $EscapeFieldSql);
// Add the expression operator.
$Expr .= ' ' . $Op . ' ';
if ($Op == 'is' || $Op == 'is not' && is_null($Value)) {
$Expr .= 'null';
} else {
// Add the right side of the expression.
$Expr .= $this->_parseExpr($Value, $Field, $EscapeValueSql);
}
return $Expr;
}