library/database/class.sqldriver.php
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)) {
         //$ValueStr = var_export($Value, TRUE);
         $ValueStr = 'ARRAY';
         Deprecated("Gdn_SQL->ConditionExpr(VALUE, {$ValueStr})", 'Gdn_SQL->ConditionExpr(VALUE, VALUE)');
         
         if ($EscapeValueSql)
            throw new Gdn_UserException('Invalid function call.');
         
         $FunctionCall = array_keys($Value);
         $FunctionCall = $FunctionCall[0];
         $FunctionArg = $Value[$FunctionCall];
         if($EscapeValueSql)
            $FunctionArg = '[' . $FunctionArg . ']';
         
         if(stripos($FunctionCall, '%s') === FALSE) 
            $Value = '=' . $FunctionCall . '(' . $FunctionArg . ')';
         else
            $Value = '=' . sprintf($FunctionCall, $FunctionArg);
         $EscapeValueSql = FALSE;
      } else if(!$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 = $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;
   }
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)) {
         //$ValueStr = var_export($Value, TRUE);
         $ValueStr = 'ARRAY';
         Deprecated("Gdn_SQL->ConditionExpr(VALUE, {$ValueStr})", 'Gdn_SQL->ConditionExpr(VALUE, VALUE)');
         
         if ($EscapeValueSql)
            throw new Gdn_UserException('Invalid function call.');
         
         $FunctionCall = array_keys($Value);
         $FunctionCall = $FunctionCall[0];
         $FunctionArg = $Value[$FunctionCall];
         if($EscapeValueSql)
            $FunctionArg = '[' . $FunctionArg . ']';
         
         if(stripos($FunctionCall, '%s') === FALSE) 
            $Value = '=' . $FunctionCall . '(' . $FunctionArg . ')';
         else
            $Value = '=' . sprintf($FunctionCall, $FunctionArg);
         $EscapeValueSql = FALSE;
      } else if(!$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 = $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;
   }
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 ) ) { //$ValueStr = var_export($Value, TRUE); $ ValueStr = 'ARRAY' ; Deprecated ( "Gdn_SQL->ConditionExpr(VALUE, {$ValueStr})" , 'Gdn_SQL->ConditionExpr(VALUE, VALUE)' ) ; if ( $ EscapeValueSql ) throw new Gdn_UserException ( 'Invalid function call.' ) ; $ FunctionCall = array_keys ( $ Value ) ; $ FunctionCall = $ FunctionCall [ 0 ] ; $ FunctionArg = $ Value [ $ FunctionCall ] ; if ( $ EscapeValueSql ) $ FunctionArg = '[' . $ FunctionArg . ']' ; if ( stripos ( $ FunctionCall , '%s' ) === FALSE ) $ Value = '=' . $ FunctionCall . '(' . $ FunctionArg . ')' ; else $ Value = '=' . sprintf ( $ FunctionCall , $ FunctionArg ) ; $ EscapeValueSql = FALSE ; } else if ( ! $ 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 = $ 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 ; }
Returns a single Condition Expression for use in a 'where' or an 'on' clause.

@param string $Field The name of the field on the left hand side of the expression.
If $Field ends with an operator, then it used for the comparison. Otherwise '=' will be used.
@param mixed $Value The value on the right side of the expression. This has different behaviour depending on the type.
<b>string</b>: The value will be used. If $EscapeValueSql is true then it will end up in a parameter.
<b>array</b>: DatabaseFunction => Value will be used. if DatabaseFunction contains a "%s" then sprintf will be used.
In this case Value will be assumed to be a string.

<b>New Syntax</b>
The $Field and Value expressions can begin with special characters to do certain things.
<ul>
<li><b>=</b>: This means that the argument is a function call.
If you want to pass field reference arguments into the function then enclose them in square brackets.
ex. <code>'=LEFT([u.Name], 4)'</code> will call the LEFT database function on the u.Name column.</li>
<li><b>@</b>: This means that the argument is a literal.
This is useful for passing in literal numbers.</li>
<li><b>no prefix></b>: This will treat the argument differently depending on the argument.
- <b>$Field</b> - The argument is a column reference.
- <b>$Value</b> - The argument will become a named parameter.
</li></ul>
@return string The single expression.
Returns a single Condition Expression for use in a where or an on clause .