Show
Ignore:
Timestamp:
10/02/08 01:00:33 (3 months ago)
Author:
nowelium
Message:

fix:procedure & transaction scripts

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/php/misc/Hermit/src/Hermit/parameter/HermitProcedureParameter.php

    r20387 r20417  
    55 */ 
    66class HermitProcedureParameter extends HermitSqlParameterHash { 
    7     private $info; 
    8     private $dbms; 
    9     private $outParams = array(); 
     7    protected $info; 
     8    protected $dbms; 
     9    protected $outParams = array(); 
     10    protected static $pdoTypes = array( 
     11        'boolean' => PDO::PARAM_BOOL, 
     12        'NULL' => PDO::PARAM_NULL, 
     13        'integer' => PDO::PARAM_INT, 
     14        'string' => PDO::PARAM_STR 
     15    ); 
    1016    public function __construct(HermitProcedureInfo $info, $dbms){ 
    1117        $this->info = $info; 
    1218        $this->dbms = $dbms; 
    1319    } 
    14     public function replace($key, $name, $defaultValue){ 
    15         return call_user_func(array($this, 'replace_' . $this->dbms), $key, $name, $defaultValue); 
    16     } 
    17     public function replace_mysql($key, $name, $defaultValue){ 
    18         if($this->info->typeofIn($name)){ 
    19             $this->bindKeys[] = $name; 
    20             return ':' . $name; 
    21         } 
    22         if($this->info->typeofOut($name) || $this->info->typeofInOut($name)){ 
    23             $this->bindKeys[] = $name; 
    24             $this->outParams[] = $name; 
    25             return '@' . $name; 
    26         } 
    27         throw new RuntimeException('unknown "' . $name . '" parameter'); 
    28     } 
    29     public function bind(PDOStatement $stmt, $value){ 
    30         return call_user_func(array($this, 'bind_' . $this->dbms), $stmt, $value); 
    31     } 
    32  
    33     public function bind_mysql(PDOStatement $stmt, $value){ 
    34         $param = $value[0]; 
    35         foreach($this->bindKeys as $index => $key){ 
    36             $prefix = ''; 
    37             if($this->info->typeofIn($key)){ 
    38                 $stmt->bindParam(':' . $key, $param->$key); 
    39             } 
    40         } 
    41     } 
    42  
    4320    public function getOutParameters(){ 
    4421        return $this->outParams; 
    4522    } 
    46  
     23    public function replace($key, $name, $defaultValue){ 
     24        $this->bindKeys[] = $name; 
     25        if($this->info->typeofOut($name) || $this->info->typeofInOut($name)){ 
     26            $this->outParams[] = $name; 
     27        } 
     28        return ':' . $name; 
     29    } 
     30    public function bind(PDOStatement $stmt, $value){ 
     31        $param = $value[0]; 
     32        foreach($this->bindKeys as $index => $key){ 
     33            $bindKey = ':' . $key; 
     34            if($this->info->typeofIn($key)){ 
     35                $stmt->bindParam($bindKey, $param->$key); 
     36                continue; 
     37            } 
     38            $paramValue = $param->$key; 
     39            if(null === $paramValue){ 
     40                $stmt->bindParam($bindKey, null, PDO::PARAM_NULL | PDO::PARAM_INPUT_OUTPUT); 
     41                continue; 
     42            } 
     43            $gettype = gettype($paramValue); 
     44            $paramType = -1; 
     45            if(isset(self::$pdoTypes[$gettype])){ 
     46                $paramType = self::$pdoTypes[$gettype] | PDO::PARAM_INPUT_OUTPUT; 
     47            } else { 
     48                $paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT; 
     49            } 
     50            $stmt->bindParam($bindKey, $paramValue, $paramType); 
     51        } 
     52    } 
    4753    public function hasBindParameters(){ 
    48         return 'mysql' === $this->dbms && 0 < count($this->outParams); 
     54        return 0 < count($this->outParams); 
    4955    } 
    5056}