| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace vakata\database\driver\oracle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use \vakata\database\DBException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use \vakata\database\DriverInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use \vakata\database\StatementInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use \vakata\database\ResultInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Statement implements StatementInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     protected $statement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $driver; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     public function __construct($statement, Driver $driver) | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         $this->statement = $statement; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         $this->driver = $driver; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function execute(array $data = []) : ResultInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $data = array_values($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $lob = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $ldt = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         foreach ($data as $i => $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             switch (gettype($v)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 case 'boolean': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 case 'integer': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                     $data[$i] = (int) $v; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                     \oci_bind_by_name($this->statement, 'f'.$i, $data[$i], -1, \SQLT_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                     // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                     if (is_resource($v) && get_resource_type($v) === 'stream') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                         $ldt = $v; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                         $lob = $this->driver->lob(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                         \oci_bind_by_name($this->statement, 'f'.$i, $lob, -1, \OCI_B_BLOB); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                         continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     if (!is_string($data[$i]) && !is_null($data[$i])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                         $data[$i] = serialize($data[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                     \oci_bind_by_name($this->statement, 'f'.$i, $data[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $temp = \oci_execute($this->statement, $this->driver->isTransaction() ? \OCI_NO_AUTO_COMMIT : \OCI_COMMIT_ON_SUCCESS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (!$temp) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $err = \oci_error($this->statement); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             if (!$err) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 $err = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             throw new DBException('Could not execute query : '.implode(',', $err)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         if ($lob) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             while (!feof($ldt) && ($ltmp = fread($ldt, 8192)) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 $lob->write($ltmp); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 $lob->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $lob->free(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return new Result($this->statement); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                        
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.