1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Query; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Query\Builder; |
6
|
|
|
|
7
|
|
|
class OracleBuilder extends Builder |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Insert a new record and get the value of the primary key. |
11
|
|
|
* |
12
|
|
|
* @param array $values |
13
|
|
|
* @param array $binaries |
14
|
|
|
* @param string $sequence |
15
|
|
|
* @return int |
16
|
|
|
*/ |
17
|
|
|
public function insertLob(array $values, array $binaries, $sequence = 'id') |
18
|
|
|
{ |
19
|
|
|
/** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */ |
20
|
|
|
$grammar = $this->grammar; |
21
|
|
|
$sql = $grammar->compileInsertLob($this, $values, $binaries, $sequence); |
22
|
|
|
|
23
|
|
|
$values = $this->cleanBindings($values); |
24
|
|
|
$binaries = $this->cleanBindings($binaries); |
25
|
|
|
|
26
|
|
|
/** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */ |
27
|
|
|
$processor = $this->processor; |
28
|
|
|
|
29
|
|
|
return $processor->saveLob($this, $sql, $values, $binaries); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Update a new record with blob field. |
34
|
|
|
* |
35
|
|
|
* @param array $values |
36
|
|
|
* @param array $binaries |
37
|
|
|
* @param string $sequence |
38
|
|
|
* @return boolean |
39
|
|
|
*/ |
40
|
|
|
public function updateLob(array $values, array $binaries, $sequence = 'id') |
41
|
|
|
{ |
42
|
|
|
$bindings = array_values(array_merge($values, $this->getBindings())); |
43
|
|
|
|
44
|
|
|
/** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */ |
45
|
|
|
$grammar = $this->grammar; |
46
|
|
|
$sql = $grammar->compileUpdateLob($this, $values, $binaries, $sequence); |
47
|
|
|
|
48
|
|
|
$values = $this->cleanBindings($bindings); |
49
|
|
|
$binaries = $this->cleanBindings($binaries); |
50
|
|
|
|
51
|
|
|
/** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */ |
52
|
|
|
$processor = $this->processor; |
53
|
|
|
|
54
|
|
|
return $processor->saveLob($this, $sql, $values, $binaries); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Add a "where in" clause to the query. |
59
|
|
|
* Split one WHERE IN clause into multiple clauses each |
60
|
|
|
* with up to 1000 expressions to avoid ORA-01795 |
61
|
|
|
* |
62
|
|
|
* @param string $column |
63
|
|
|
* @param mixed $values |
64
|
|
|
* @param string $boolean |
65
|
|
|
* @param bool $not |
66
|
|
|
* @return \Illuminate\Database\Query\Builder|\Yajra\Oci8\Query\OracleBuilder |
67
|
|
|
*/ |
68
|
|
|
public function whereIn($column, $values, $boolean = 'and', $not = false) |
69
|
|
|
{ |
70
|
|
|
$type = $not ? 'NotIn' : 'In'; |
71
|
|
|
|
72
|
|
|
if (count($values) > 1000) { |
73
|
|
|
$chunks = array_chunk($values, 1000); |
74
|
|
|
|
75
|
|
|
return $this->where(function ($query) use ($column, $chunks, $type) { |
76
|
|
|
$firstIteration = true; |
77
|
|
|
foreach ($chunks as $ch) { |
78
|
|
|
$sqlClause = $firstIteration ? 'where' . $type : 'orWhere' . $type; |
79
|
|
|
$query->$sqlClause($column, $ch); |
80
|
|
|
$firstIteration = false; |
81
|
|
|
} |
82
|
|
|
}, null, null, $boolean); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return parent::whereIn($column, $values, $boolean, $not); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Run the query as a "select" statement against the connection. |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
protected function runSelect() |
94
|
|
|
{ |
95
|
|
|
if ($this->lock) { |
96
|
|
|
$this->connection->beginTransaction(); |
97
|
|
|
$result = $this->connection->select($this->toSql(), $this->getBindings(), ! $this->useWritePdo); |
98
|
|
|
$this->connection->commit(); |
99
|
|
|
|
100
|
|
|
return $result; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->connection->select($this->toSql(), $this->getBindings(), ! $this->useWritePdo); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|