OracleBuilder   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 62.86%

Importance

Changes 0
Metric Value
dl 0
loc 99
ccs 22
cts 35
cp 0.6286
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A insertLob() 0 14 1
A updateLob() 0 16 1
B whereIn() 0 19 5
A runSelect() 0 12 2
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 6
    public function insertLob(array $values, array $binaries, $sequence = 'id')
18
    {
19
        /** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */
20 6
        $grammar = $this->grammar;
21 6
        $sql     = $grammar->compileInsertLob($this, $values, $binaries, $sequence);
22
23 6
        $values   = $this->cleanBindings($values);
24 6
        $binaries = $this->cleanBindings($binaries);
25
26
        /** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */
27 6
        $processor = $this->processor;
28
29 6
        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 6
    public function updateLob(array $values, array $binaries, $sequence = 'id')
41
    {
42 6
        $bindings = array_values(array_merge($values, $this->getBindings()));
43
44
        /** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */
45 6
        $grammar = $this->grammar;
46 6
        $sql     = $grammar->compileUpdateLob($this, $values, $binaries, $sequence);
47
48 6
        $values   = $this->cleanBindings($bindings);
49 6
        $binaries = $this->cleanBindings($binaries);
50
51
        /** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */
52 6
        $processor = $this->processor;
53
54 6
        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 9
    public function whereIn($column, $values, $boolean = 'and', $not = false)
69
    {
70 9
        $type = $not ? 'NotIn' : 'In';
71
72 9
        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 9
        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 27
    protected function runSelect()
94
    {
95 27
        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 27
        return $this->connection->select($this->toSql(), $this->getBindings(), ! $this->useWritePdo);
104
    }
105
}
106