@param null|string $operator
@param $value

@throws SqlException

@return string
172767
private function prepareOperator(?string $operator, $value): string
    {
        $operator = strtoupper($operator);

        if (!$operator) {
            $operator = is_array($value) ? 'IN' : '=';
        }

        if ($operator === 'IN' and !is_array($value)) {
            $operator = '=';
        }

        if ($operator !== 'IN' and is_array($value)) {
            throw new SqlException('Value could not be an array in condition for operator `' . $operator . '`.');
        }

        return $operator;
    }
457809
protected function replaceOperatorForNulLValue(OperatorInterface $Operator, $value)
    {
        if ($value === null) {
            if ($Operator->getType() === Equal::TYPE_NAME) {
                $className = CriteriaBuilder::getOperatorClassNameBySqlOperator(Is::TYPE_AS_SQL);
                $Operator = $this->getFactoryWorker()->buildCriteriaOperator($className);
            } elseif ($Operator->getType() === NotEqual::TYPE_NAME) {
                $className = CriteriaBuilder::getOperatorClassNameBySqlOperator(NotIs::TYPE_AS_SQL);
                $Operator = $this->getFactoryWorker()->buildCriteriaOperator($className);
            }
        }

        return $Operator;
    }
43589
public function OrderBy($Value = NULL) {
      if ($Value === NULL)
         return $this->_OrderBy;

      if (is_string($Value))
         $Value = array($Value);

      if (is_array($Value)) {
         // Set the order of this object.
         $OrderBy = array();

         foreach($Value as $Part) {
            if (StringEndsWith($Part, ' desc', TRUE))
               $OrderBy[] = array(substr($Part, 0, -5), 'desc');
            elseif (StringEndsWith($Part, ' asc', TRUE))
               $OrderBy[] = array(substr($Part, 0, -4), 'asc');
            else
               $OrderBy[] = array($Part, 'asc');
         }
         $this->_OrderBy = $OrderBy;
      } elseif (is_a($Value, 'Gdn_SQLDriver')) {
         // Set the order of the given sql.
         foreach ($this->_OrderBy as $Parts) {
            $Value->OrderBy($Parts[0], $Parts[1]);
         }
      }
   }
150702
public function where($field, $operator = null, $value = null)
    {
        $this->query->where($field, $operator, $value);

        return $this;
    }
373490
public function esc(?string $value): string
    {
        if ($value === null) {
            return 'NULL';
        }

        $value = substr($this->pdo->quote($value), 1, -1);

        return $value;
    }
1138271
protected function normalize($property, $operator = null, $value = null)
    {
        if ($operator !== null && $value === null) {
            $value = $operator;
            $operator = '=';
        }

        $operator = $operator === null ? null : strtolower($operator);

        return [$property, $operator, $value];
    }
830785
public function orWhere($column, $operator = null, $value = null)
    {
        [$value, $operator] = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() === 2
        );

        return $this->where($column, $operator, $value, 'or');
    }
155352
public function query($sql, $values = null, $connection = null)
  {
    if ($this->isDebug()) {
      $i = $this->getQueriesCount();
      $t = microtime(true);

      $this->queries[$i] = array('query' => $sql, 'values' => $values);
    }

    $pdo = $this->getConnection($connection);

    if ($sql instanceof Query) {
      $values = $values ?: $sql->getBindedValues();
      $sql    = $sql->asStatement();
    }

    $stmt = $pdo->prepare($sql);
    $res = $stmt->execute($values);

    if ($this->isDebug()) {
      $this->queries[$i]['time'] = microtime(true) - $t;
    }

    if (!$res) {
      Exception::ThrowError(Exception::QUERY, $stmt->errorInfo());
    }

    return $stmt;
  }
1276690
public function filter($column, $operator = null, $value = null)
	{
		if( !isset($this->valid_columns[$column]) )
		{
			throw new InvalidArgumentException("Column '{$column}' not used");
		}

		$this->wheres[] = [ $this->valid_columns[$column], $operator, $value ];
		return $this;
	}
993472
public function where($val1, $val2 = null, string $operator = null, bool $bind = null, string $join = null){
		$operator = $operator !== null ? strtoupper(trim($operator)) : '=';
		$bind     = $bind ?? true;

		$join = strtoupper(trim($join));
		$join = in_array($join, $this->joinArgs, true) ? $join : 'AND';

		if(in_array($operator, $this->operators, true)){
			$where = [
				is_array($val1)
					? strtoupper($val1[1]).'('.$this->dialect->quote($val1[0]).')'
					: $this->dialect->quote($val1)
			];

			if(in_array($operator, ['IN', 'NOT IN', 'ANY', 'SOME',], true)){

				if(is_array($val2)){

					if($bind){
						$where[] = $operator.'('.implode(',', array_fill(0, count($val2), '?')).')';
						$this->bindValues = array_merge($this->bindValues, $val2);
					}
					else{
						$where[] = $operator.'('.implode(',', array_map([$this->db, 'escape'], $val2)).')'; // @todo: quote
					}

				}
				else if($val2 instanceof Statement){
					$where[] = $operator.'('.$val2->sql().')';
					$this->bindValues = array_merge($this->bindValues, $val2->bindValues());
				}

			}
//			else if(in_array($operator, ['BETWEEN', 'NOT BETWEEN'], true)){
				// @todo
//			}
			else{
				$where[] = $operator;

				if($val2 instanceof Statement){
					$where[] = '('.$val2->sql().')';
					$this->bindValues = array_merge($this->bindValues, $val2->bindValues());
				}
				elseif(is_null($val2)){
					$where[] = 'NULL';
				}
				elseif(is_bool($val2)){
					$where[] = $val2 ? 'TRUE' : 'FALSE';
				}
				elseif(in_array(strtolower($val2), ['null', 'false', 'true', 'unknown'], true)){
					$where[] = strtoupper($val2);
				}
				else {

					if($bind){
						$where[] = '?';
						$this->bindValues[] = $val2;
					}
					else{
						if(!empty($val2)){
							$where[] = $val2;
						}
					}

				}

			}

			$this->where[] = [
				'join' => $join,
				'stmt' => implode(' ', $where),
			];

		}

		return $this;
	}
360741
function prepValueForDB($value) {
		if(!$this->nullifyEmpty && $value === '') {
			return DB::getConn()->prepStringForDB($value);
		} else {
			return parent::prepValueForDB($value);
		}
	}
542271
public function where($column, $operator, $value = null)
    {
        if (count($this->wheres) > 0) {
            $this->andWhere($column, $operator, $value);
        }

        $this->wheres[] = new Where($column, $operator, $value);

        return $this;
    }
1020861
private static function serializeValue( $value ) {
		try {
			return serialize( $value );
		} catch ( \Exception $ex ) {
			self::$logger->error( 'Value serialization failed: ' . $ex->getMessage() );
			return null;
		}
	}
294260
protected function match($operator, $pattern, $value)
    {
        $value   = strtolower($value);
        $pattern = strtolower($pattern);
        switch ($operator) {
            case '=':
                return $value === $pattern;
            case '!=':
                return $value !== $pattern;
            case '^=':
                return preg_match('/^'.preg_quote($pattern, '/').'/', $value);
            case '$=':
                return preg_match('/'.preg_quote($pattern, '/').'$/', $value);
            case '*=':
                if ($pattern[0] == '/') {
                    return preg_match($pattern, $value);
                }

                return preg_match("/".$pattern."/i", $value);
        }

        return false;
    }
210036
protected function addCondition($value, string $operator, bool $isColumn = false): WhereStatement
    {
        if ($isColumn && is_string($value)) {
            $value = function (Expression $expr) use ($value) {
                $expr->column($value);
            };
        }
        $this->sql->addWhereCondition($this->column, $value, $operator, $this->separator);
        return $this->statement;
    }
870929
public function orWhereJsonLength($column, $operator, $value = null)
    {
        [$value, $operator] = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() === 2
        );

        return $this->whereJsonLength($column, $operator, $value, 'or');
    }
4258
public function convertQueryCondition($value)
    {
        // First fetch the type
        if (null === $value) {
            return 0;
        }

        if (!is_array($value)) {
            $value = [$value];
        }

        $hasOperator = false;

        // FIXME Sorry for this
        if (!Misc::isIndexed($value)) {
            // We have an operator.
            $operator = array_keys($value)[0];
            $values = $value[$operator][0];
            $hasOperator = true;
        } else {
            $values = $value;
        }

        foreach ($values as $key => $type) {
            if (null === $type) {
                $values[$key] = 0;
            } else if ($typeId = $this->getTypeId($type, false)) {
                $values[$key] = $typeId;
            } else {
                unset($values[$key]);
            }
        }

        if (empty($values)) {
            // It should not have been empty, this is an impossible
            // condition
            $values = [-1];
        }

        if ($hasOperator) {
            return [$operator => $values];
        } else {
            return $values;
        }
    }