1 | <?php |
||
18 | class Oci8Connection extends Connection |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $schema; |
||
24 | |||
25 | /** |
||
26 | * @var \Yajra\Oci8\Schema\Sequence |
||
27 | */ |
||
28 | protected $sequence; |
||
29 | |||
30 | /** |
||
31 | * @var \Yajra\Oci8\Schema\Trigger |
||
32 | */ |
||
33 | protected $trigger; |
||
34 | |||
35 | /** |
||
36 | * @param PDO|\Closure $pdo |
||
37 | * @param string $database |
||
38 | * @param string $tablePrefix |
||
39 | * @param array $config |
||
40 | */ |
||
41 | public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) |
||
42 | { |
||
43 | parent::__construct($pdo, $database, $tablePrefix, $config); |
||
44 | $this->sequence = new Sequence($this); |
||
45 | $this->trigger = new Trigger($this); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get current schema. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getSchema() |
||
54 | { |
||
55 | return $this->schema; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Set current schema. |
||
60 | * |
||
61 | * @param string $schema |
||
62 | * @return $this |
||
63 | */ |
||
64 | public function setSchema($schema) |
||
65 | { |
||
66 | $this->schema = $schema; |
||
67 | $sessionVars = [ |
||
68 | 'CURRENT_SCHEMA' => $schema, |
||
69 | ]; |
||
70 | |||
71 | return $this->setSessionVars($sessionVars); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Update oracle session variables. |
||
76 | * |
||
77 | * @param array $sessionVars |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function setSessionVars(array $sessionVars) |
||
81 | { |
||
82 | $vars = []; |
||
83 | foreach ($sessionVars as $option => $value) { |
||
84 | if (strtoupper($option) == 'CURRENT_SCHEMA') { |
||
85 | $vars[] = "$option = $value"; |
||
86 | } else { |
||
87 | $vars[] = "$option = '$value'"; |
||
88 | } |
||
89 | } |
||
90 | $sql = "ALTER SESSION SET " . implode(" ", $vars); |
||
91 | $this->statement($sql); |
||
92 | |||
93 | return $this; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get sequence class. |
||
98 | * |
||
99 | * @return \Yajra\Oci8\Schema\Sequence |
||
100 | */ |
||
101 | public function getSequence() |
||
102 | { |
||
103 | return $this->sequence; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Set sequence class. |
||
108 | * |
||
109 | * @param \Yajra\Oci8\Schema\Sequence $sequence |
||
110 | * @return \Yajra\Oci8\Schema\Sequence |
||
111 | */ |
||
112 | public function setSequence(Sequence $sequence) |
||
113 | { |
||
114 | return $this->sequence = $sequence; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Get oracle trigger class. |
||
119 | * |
||
120 | * @return \Yajra\Oci8\Schema\Trigger |
||
121 | */ |
||
122 | public function getTrigger() |
||
123 | { |
||
124 | return $this->trigger; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Set oracle trigger class. |
||
129 | * |
||
130 | * @param \Yajra\Oci8\Schema\Trigger $trigger |
||
131 | * @return \Yajra\Oci8\Schema\Trigger |
||
132 | */ |
||
133 | public function setTrigger(Trigger $trigger) |
||
134 | { |
||
135 | return $this->trigger = $trigger; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Get a schema builder instance for the connection. |
||
140 | * |
||
141 | * @return \Yajra\Oci8\Schema\OracleBuilder |
||
142 | */ |
||
143 | public function getSchemaBuilder() |
||
144 | { |
||
145 | if (is_null($this->schemaGrammar)) { |
||
146 | $this->useDefaultSchemaGrammar(); |
||
147 | } |
||
148 | |||
149 | return new SchemaBuilder($this); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Begin a fluent query against a database table. |
||
154 | * |
||
155 | * @param string $table |
||
156 | * @return \Yajra\Oci8\Query\OracleBuilder |
||
157 | */ |
||
158 | public function table($table) |
||
159 | { |
||
160 | $processor = $this->getPostProcessor(); |
||
161 | |||
162 | $query = new QueryBuilder($this, $this->getQueryGrammar(), $processor); |
||
163 | |||
164 | return $query->from($table); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Set oracle session date format. |
||
169 | * |
||
170 | * @param string $format |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS') |
||
174 | { |
||
175 | $sessionVars = [ |
||
176 | 'NLS_DATE_FORMAT' => $format, |
||
177 | 'NLS_TIMESTAMP_FORMAT' => $format, |
||
178 | ]; |
||
179 | |||
180 | return $this->setSessionVars($sessionVars); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Get doctrine connection. |
||
185 | * |
||
186 | * @return \Doctrine\DBAL\Connection |
||
187 | */ |
||
188 | public function getDoctrineConnection() |
||
189 | { |
||
190 | $driver = $this->getDoctrineDriver(); |
||
191 | |||
192 | $data = ['pdo' => $this->getPdo(), 'user' => $this->getConfig('username')]; |
||
193 | |||
194 | return new DoctrineConnection($data, $driver); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Get doctrine driver. |
||
199 | * |
||
200 | * @return \Doctrine\DBAL\Driver\OCI8\Driver |
||
201 | */ |
||
202 | protected function getDoctrineDriver() |
||
203 | { |
||
204 | return new DoctrineDriver; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Get the default query grammar instance. |
||
209 | * |
||
210 | * @return \Yajra\Oci8\Query\Grammars\OracleGrammar |
||
211 | */ |
||
212 | protected function getDefaultQueryGrammar() |
||
213 | { |
||
214 | return $this->withTablePrefix(new QueryGrammar); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Set the table prefix and return the grammar. |
||
219 | * |
||
220 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
221 | * @return \Illuminate\Database\Grammar |
||
222 | */ |
||
223 | public function withTablePrefix(Grammar $grammar) |
||
224 | { |
||
225 | return $this->withSchemaPrefix(parent::withTablePrefix($grammar)); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Set the schema prefix and return the grammar. |
||
230 | * |
||
231 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
232 | * @return \Illuminate\Database\Grammar |
||
233 | */ |
||
234 | public function withSchemaPrefix(Grammar $grammar) |
||
240 | |||
241 | |||
242 | /** |
||
243 | * Execute a PL/SQL Function and return its value. |
||
244 | * Usage: DB::executeFunction('function_name(:binding_1,:binding_n)', [':binding_1' => 'hi', ':binding_n' => 'bye'], PDO::PARAM_LOB) |
||
245 | * |
||
246 | * @author Tylerian - [email protected] |
||
247 | * |
||
248 | * @param $sql (mixed) |
||
249 | * @param $bindings (kvp array) |
||
250 | * @param $returnType (PDO::PARAM_*) |
||
251 | * @return $returnType |
||
252 | */ |
||
253 | public function executeFunction($sql, array $bindings = [], $returnType = PDO::PARAM_STR) |
||
254 | { |
||
255 | $query = $this->getPdo()->prepare('begin :result := ' . $sql . '; end;'); |
||
273 | |||
274 | /** |
||
275 | * Get config schema prefix. |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | protected function getConfigSchemaPrefix() |
||
283 | |||
284 | /** |
||
285 | * Get the default schema grammar instance. |
||
286 | * |
||
287 | * @return \Yajra\Oci8\Schema\Grammars\OracleGrammar |
||
288 | */ |
||
289 | protected function getDefaultSchemaGrammar() |
||
293 | |||
294 | /** |
||
295 | * Get the default post processor instance. |
||
296 | * |
||
297 | * @return \Yajra\Oci8\Query\Processors\OracleProcessor |
||
298 | */ |
||
299 | protected function getDefaultPostProcessor() |
||
303 | } |
||
304 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.