1 | <?php |
||
19 | class Oci8Connection extends Connection |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $schema; |
||
25 | |||
26 | /** |
||
27 | * @var \Yajra\Oci8\Schema\Sequence |
||
28 | */ |
||
29 | protected $sequence; |
||
30 | |||
31 | /** |
||
32 | * @var \Yajra\Oci8\Schema\Trigger |
||
33 | */ |
||
34 | protected $trigger; |
||
35 | |||
36 | /** |
||
37 | * @param PDO|\Closure $pdo |
||
38 | * @param string $database |
||
39 | * @param string $tablePrefix |
||
40 | * @param array $config |
||
41 | */ |
||
42 | public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) |
||
43 | { |
||
44 | parent::__construct($pdo, $database, $tablePrefix, $config); |
||
45 | $this->sequence = new Sequence($this); |
||
46 | $this->trigger = new Trigger($this); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Get current schema. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getSchema() |
||
55 | { |
||
56 | return $this->schema; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Set current schema. |
||
61 | * |
||
62 | * @param string $schema |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function setSchema($schema) |
||
74 | |||
75 | /** |
||
76 | * Update oracle session variables. |
||
77 | * |
||
78 | * @param array $sessionVars |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function setSessionVars(array $sessionVars) |
||
82 | { |
||
83 | $vars = []; |
||
84 | foreach ($sessionVars as $option => $value) { |
||
85 | if (strtoupper($option) == 'CURRENT_SCHEMA') { |
||
86 | $vars[] = "$option = $value"; |
||
87 | } else { |
||
88 | $vars[] = "$option = '$value'"; |
||
89 | } |
||
90 | } |
||
91 | if ($vars) { |
||
|
|||
92 | $sql = 'ALTER SESSION SET ' . implode(' ', $vars); |
||
93 | $this->statement($sql); |
||
94 | } |
||
95 | |||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get sequence class. |
||
101 | * |
||
102 | * @return \Yajra\Oci8\Schema\Sequence |
||
103 | */ |
||
104 | public function getSequence() |
||
108 | |||
109 | /** |
||
110 | * Set sequence class. |
||
111 | * |
||
112 | * @param \Yajra\Oci8\Schema\Sequence $sequence |
||
113 | * @return \Yajra\Oci8\Schema\Sequence |
||
114 | */ |
||
115 | public function setSequence(Sequence $sequence) |
||
116 | { |
||
117 | return $this->sequence = $sequence; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Get oracle trigger class. |
||
122 | * |
||
123 | * @return \Yajra\Oci8\Schema\Trigger |
||
124 | */ |
||
125 | public function getTrigger() |
||
129 | |||
130 | /** |
||
131 | * Set oracle trigger class. |
||
132 | * |
||
133 | * @param \Yajra\Oci8\Schema\Trigger $trigger |
||
134 | * @return \Yajra\Oci8\Schema\Trigger |
||
135 | */ |
||
136 | public function setTrigger(Trigger $trigger) |
||
137 | { |
||
138 | return $this->trigger = $trigger; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Get a schema builder instance for the connection. |
||
143 | * |
||
144 | * @return \Yajra\Oci8\Schema\OracleBuilder |
||
145 | */ |
||
146 | public function getSchemaBuilder() |
||
154 | |||
155 | /** |
||
156 | * Begin a fluent query against a database table. |
||
157 | * |
||
158 | * @param string $table |
||
159 | * @return \Yajra\Oci8\Query\OracleBuilder |
||
160 | */ |
||
161 | public function table($table) |
||
162 | { |
||
163 | $processor = $this->getPostProcessor(); |
||
164 | |||
165 | $query = new QueryBuilder($this, $this->getQueryGrammar(), $processor); |
||
166 | |||
167 | return $query->from($table); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Set oracle session date format. |
||
172 | * |
||
173 | * @param string $format |
||
174 | * @return $this |
||
175 | */ |
||
176 | public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS') |
||
177 | { |
||
178 | $sessionVars = [ |
||
179 | 'NLS_DATE_FORMAT' => $format, |
||
180 | 'NLS_TIMESTAMP_FORMAT' => $format, |
||
181 | ]; |
||
182 | |||
183 | return $this->setSessionVars($sessionVars); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Get doctrine connection. |
||
188 | * |
||
189 | * @return \Doctrine\DBAL\Connection |
||
190 | */ |
||
191 | public function getDoctrineConnection() |
||
199 | |||
200 | /** |
||
201 | * Get doctrine driver. |
||
202 | * |
||
203 | * @return \Doctrine\DBAL\Driver\OCI8\Driver |
||
204 | */ |
||
205 | protected function getDoctrineDriver() |
||
209 | |||
210 | /** |
||
211 | * Execute a PL/SQL Function and return its value. |
||
212 | * Usage: DB::executeFunction('function_name(:binding_1,:binding_n)', [':binding_1' => 'hi', ':binding_n' => |
||
213 | * 'bye'], PDO::PARAM_LOB). |
||
214 | * |
||
215 | * @author Tylerian - [email protected] |
||
216 | * @param string $sql (mixed) |
||
217 | * @param array $bindings (kvp array) |
||
218 | * @param int $returnType (PDO::PARAM_*) |
||
219 | * @return mixed $returnType |
||
220 | */ |
||
221 | public function executeFunction($sql, array $bindings = [], $returnType = PDO::PARAM_STR) |
||
238 | |||
239 | /** |
||
240 | * Execute a PL/SQL Procedure and return its result. |
||
241 | * Usage: DB::executeProcedure($procedureName, $bindings). |
||
242 | * $bindings looks like: |
||
243 | * $bindings = [ |
||
244 | * 'p_userid' => $id |
||
245 | * ]; |
||
246 | * |
||
247 | * @param string $procedureName |
||
248 | * @param array $bindings |
||
249 | * @param mixed $returnType |
||
250 | * @return array |
||
251 | */ |
||
252 | public function executeProcedure($procedureName, $bindings, $returnType = PDO::PARAM_STMT) |
||
278 | |||
279 | /** |
||
280 | * Bind values to their parameters in the given statement. |
||
281 | * |
||
282 | * @param \PDOStatement $statement |
||
283 | * @param array $bindings |
||
284 | */ |
||
285 | public function bindValues($statement, $bindings) |
||
291 | |||
292 | /** |
||
293 | * Get the default query grammar instance. |
||
294 | * |
||
295 | * @return \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar |
||
296 | */ |
||
297 | protected function getDefaultQueryGrammar() |
||
301 | |||
302 | /** |
||
303 | * Set the table prefix and return the grammar. |
||
304 | * |
||
305 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
306 | * @return \Illuminate\Database\Grammar |
||
307 | */ |
||
308 | public function withTablePrefix(Grammar $grammar) |
||
312 | |||
313 | /** |
||
314 | * Set the schema prefix and return the grammar. |
||
315 | * |
||
316 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
317 | * @return \Illuminate\Database\Grammar |
||
318 | */ |
||
319 | public function withSchemaPrefix(Grammar $grammar) |
||
325 | |||
326 | /** |
||
327 | * Get config schema prefix. |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | protected function getConfigSchemaPrefix() |
||
335 | |||
336 | /** |
||
337 | * Get the default schema grammar instance. |
||
338 | * |
||
339 | * @return \Illuminate\Database\Grammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar |
||
340 | */ |
||
341 | protected function getDefaultSchemaGrammar() |
||
345 | |||
346 | /** |
||
347 | * Get the default post processor instance. |
||
348 | * |
||
349 | * @return \Yajra\Oci8\Query\Processors\OracleProcessor |
||
350 | */ |
||
351 | protected function getDefaultPostProcessor() |
||
355 | } |
||
356 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.