| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Yiisoft\Db\Pgsql; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Yiisoft\Db\Exception\ConvertException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use function is_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | final class CommandPDO extends AbstractCommandPDO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 1 |  |     public function insertEx(string $table, array $columns): bool|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 1 |  |         $params = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |         $sql = $this->queryBuilder()->insertEx($table, $columns, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 1 |  |         $this->setSql($sql)->bindValues($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |         $this->prepare(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         /** @var mixed $queryOne */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 1 |  |         $queryOne = $this->queryOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 1 |  |         return is_array($queryOne) ? $queryOne : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 237 |  |     public function queryBuilder(): QueryBuilderInterface | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 237 |  |         return $this->db->getQueryBuilder(); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @psalm-suppress UnusedClosureParam | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @throws \Yiisoft\Db\Exception\Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @throws Throwable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 223 |  |     protected function internalExecute(string|null $rawSql): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 223 |  |         $attempt = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 223 |  |         while (true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 if ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     ++$attempt === 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 223 |  |                     && $this->isolationLevel !== null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 223 |  |                     && $this->db->getTransaction() === null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |                     $this->db->transaction( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |                         fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |                         $this->isolationLevel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 223 |  |                     $this->pdoStatement?->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 223 |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 9 |  |             } catch (Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 9 |  |                 $rawSql = $rawSql ?: $this->getRawSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 9 |  |                 $e = (new ConvertException($e, $rawSql))->run(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 9 |  |                 if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 9 |  |                     throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.