Skip to content

Commit

Permalink
Merge pull request #532 from dantesCode/master
Browse files Browse the repository at this point in the history
[6.0] Fix whereInRaw and whereNotInRaw Grammar.
  • Loading branch information
yajra committed Oct 11, 2019
2 parents 1195c47 + 4993170 commit 15a10cd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/Oci8/Query/Grammars/OracleGrammar.php
Expand Up @@ -494,4 +494,65 @@ protected function dateBasedWhere($type, Builder $query, $where)

return "extract ($type from {$this->wrap($where['column'])}) {$where['operator']} $value";
}

/**
* Compile a "where not in raw" clause.
*
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereNotInRaw(Builder $query, $where)
{
if (! empty($where['values'])) {
if (is_array($where['values']) && count($where['values']) > 1000) {
return $this->resolveClause($where['column'], $where['values'], 'not in');
} else {
return $this->wrap($where['column']).' not in ('.implode(', ', $where['values']).')';
}
}

return '1 = 1';
}

/**
* Compile a "where in raw" clause.
*
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereInRaw(Builder $query, $where)
{
if (! empty($where['values'])) {
if (is_array($where['values']) && count($where['values']) > 1000) {
return $this->resolveClause($where['column'], $where['values'], 'in');
} else {
return $this->wrap($where['column']).' in ('.implode(', ', $where['values']).')';
}
}

return '0 = 1';
}

private function resolveClause($column, $values, $type)
{
$chunks = array_chunk($values, 1000);
$whereClause = '';
$i=0;
$type = $this->wrap($column) . ' '.$type.' ';
foreach ($chunks as $ch) {
if ($i > 0) {
$type = ' or '. $this->wrap($column) . ' ' . $type . ' ';
}
$whereClause .= $type . '('.implode(', ', $ch).')';
$i++;
}

return '(' . $whereClause . ')';
}
}

0 comments on commit 15a10cd

Please sign in to comment.