| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | class HermitProcedureParameter extends HermitSqlParameterHash { |
|---|
| 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 | ); |
|---|
| 16 | public function __construct(HermitProcedureInfo $info, $dbms){ |
|---|
| 17 | $this->info = $info; |
|---|
| 18 | $this->dbms = $dbms; |
|---|
| 19 | } |
|---|
| 20 | public function getOutParameters(){ |
|---|
| 21 | return $this->outParams; |
|---|
| 22 | } |
|---|
| 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 | $param->__init__(); |
|---|
| 33 | $propertyNames = $param->getPropertyNames(); |
|---|
| 34 | |
|---|
| 35 | foreach($this->bindKeys as $index => $key){ |
|---|
| 36 | $bindKey = ':' . $key; |
|---|
| 37 | if($this->info->typeofIn($key)){ |
|---|
| 38 | if(!in_array($key, $propertyNames)){ |
|---|
| 39 | throw new InvalidArgumentException('param ' . $param . ' has not propery: ' . $key . ' instatement: ' . $stmt->queryString); |
|---|
| 40 | } |
|---|
| 41 | $stmt->bindParam($bindKey, $param->get($key)); |
|---|
| 42 | continue; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | $paramValue = null; |
|---|
| 46 | if($param->issetValue($key)){ |
|---|
| 47 | $paramValue = $param->get($key); |
|---|
| 48 | } |
|---|
| 49 | if(null === $paramValue){ |
|---|
| 50 | $stmt->bindParam($bindKey, $paramValue, PDO::PARAM_NULL | PDO::PARAM_INPUT_OUTPUT); |
|---|
| 51 | continue; |
|---|
| 52 | } |
|---|
| 53 | $gettype = gettype($paramValue); |
|---|
| 54 | $paramType = -1; |
|---|
| 55 | if(isset(self::$pdoTypes[$gettype])){ |
|---|
| 56 | $paramType = self::$pdoTypes[$gettype] | PDO::PARAM_INPUT_OUTPUT; |
|---|
| 57 | } else { |
|---|
| 58 | $paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT; |
|---|
| 59 | } |
|---|
| 60 | $stmt->bindParam($bindKey, $paramValue, $paramType); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | public function hasBindParameters(){ |
|---|
| 64 | return 0 < count($this->outParams); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|