InConditionBuilder.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\sqlite\conditions;
  8. use yii\base\NotSupportedException;
  9. /**
  10. * {@inheritdoc}
  11. *
  12. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  13. * @since 2.0.14
  14. */
  15. class InConditionBuilder extends \yii\db\conditions\InConditionBuilder
  16. {
  17. /**
  18. * {@inheritdoc}
  19. * @throws NotSupportedException if `$columns` is an array
  20. */
  21. protected function buildSubqueryInCondition($operator, $columns, $values, &$params)
  22. {
  23. if (is_array($columns)) {
  24. throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
  25. }
  26. return parent::buildSubqueryInCondition($operator, $columns, $values, $params);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. protected function buildCompositeInCondition($operator, $columns, $values, &$params)
  32. {
  33. $quotedColumns = [];
  34. foreach ($columns as $i => $column) {
  35. $quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column;
  36. }
  37. $vss = [];
  38. foreach ($values as $value) {
  39. $vs = [];
  40. foreach ($columns as $i => $column) {
  41. if (isset($value[$column])) {
  42. $phName = $this->queryBuilder->bindParam($value[$column], $params);
  43. $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName;
  44. } else {
  45. $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL';
  46. }
  47. }
  48. $vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')';
  49. }
  50. return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')';
  51. }
  52. }