vendor/propel/propel/src/Propel/Runtime/ActiveQuery/Criterion/BasicCriterion.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * MIT License. This file is part of the Propel package.
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Propel\Runtime\ActiveQuery\Criterion;
  8. use Propel\Runtime\ActiveQuery\Criteria;
  9. use Propel\Runtime\ActiveQuery\Criterion\Exception\InvalidValueException;
  10. /**
  11.  * Specialized Criterion used for traditional expressions,
  12.  * e.g. table.column = ? or table.column >= ? etc.
  13.  */
  14. class BasicCriterion extends AbstractCriterion
  15. {
  16.     /**
  17.      * @var bool
  18.      */
  19.     protected $ignoreStringCase false;
  20.     /**
  21.      * Create a new instance.
  22.      *
  23.      * @param \Propel\Runtime\ActiveQuery\Criteria $outer The outer class (this is an "inner" class).
  24.      * @param string $column ignored
  25.      * @param string $value The condition to be added to the query string
  26.      * @param string $comparison One of Criteria::LIKE and Criteria::NOT_LIKE
  27.      */
  28.     public function __construct(Criteria $outer$column$value$comparison Criteria::EQUAL)
  29.     {
  30.         parent::__construct($outer$column$value$comparison);
  31.     }
  32.     /**
  33.      * Sets ignore case.
  34.      *
  35.      * @param bool $b True if case should be ignored.
  36.      *
  37.      * @return $this A modified Criterion object.
  38.      */
  39.     public function setIgnoreCase($b)
  40.     {
  41.         $this->ignoreStringCase = (bool)$b;
  42.         return $this;
  43.     }
  44.     /**
  45.      * Is ignore case on or off?
  46.      *
  47.      * @return bool True if case is ignored.
  48.      */
  49.     public function isIgnoreCase()
  50.     {
  51.         return $this->ignoreStringCase;
  52.     }
  53.     /**
  54.      * Appends a Prepared Statement representation of the Criterion onto the buffer
  55.      *
  56.      * @param string $sb The string that will receive the Prepared Statement
  57.      * @param array $params A list to which Prepared Statement parameters will be appended
  58.      *
  59.      * @throws \Propel\Runtime\ActiveQuery\Criterion\Exception\InvalidValueException
  60.      *
  61.      * @return void
  62.      */
  63.     protected function appendPsForUniqueClauseTo(&$sb, array &$params)
  64.     {
  65.         $field = ($this->table === null) ? $this->column $this->table '.' $this->column;
  66.         // NULL VALUES need special treatment because the SQL syntax is different
  67.         // i.e. table.column IS NULL rather than table.column = null
  68.         if ($this->value !== null) {
  69.             // ANSI SQL functions get inserted right into SQL (not escaped, etc.)
  70.             if ($this->value === Criteria::CURRENT_DATE || $this->value === Criteria::CURRENT_TIME || $this->value === Criteria::CURRENT_TIMESTAMP) {
  71.                 $sb .= $field $this->comparison $this->value;
  72.             } else {
  73.                 $params[] = ['table' => $this->realtable'column' => $this->column'value' => $this->value];
  74.                 // default case, it is a normal col = value expression; value
  75.                 // will be replaced w/ '?' and will be inserted later using PDO bindValue()
  76.                 if ($this->ignoreStringCase) {
  77.                     /** @var \Propel\Runtime\Adapter\SqlAdapterInterface $sqlAdapter */
  78.                     $sqlAdapter $this->getAdapter();
  79.                     $sb .= $sqlAdapter->ignoreCase($field) . $this->comparison $sqlAdapter->ignoreCase(':p' count($params));
  80.                 } else {
  81.                     $sb .= $field $this->comparison ':p' count($params);
  82.                 }
  83.             }
  84.         } else {
  85.             // value is null, which means it was either not specified or specifically
  86.             // set to null.
  87.             if ($this->comparison === Criteria::EQUAL || $this->comparison === Criteria::ISNULL) {
  88.                 $sb .= $field Criteria::ISNULL;
  89.             } elseif ($this->comparison === Criteria::NOT_EQUAL || $this->comparison === Criteria::ISNOTNULL) {
  90.                 $sb .= $field Criteria::ISNOTNULL;
  91.             } else {
  92.                 // for now throw an exception, because not sure how to interpret this
  93.                 throw new InvalidValueException(sprintf('Could not build SQL for expression: %s %s NULL'$field$this->comparison));
  94.             }
  95.         }
  96.     }
  97. }