| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/drivers/lmbDbManipulationStatement.interface.php'); 10 lmb_require(dirname(__FILE__) . '/lmbOciStatement.class.php'); 11 lmb_require(dirname(__FILE__) . '/lmbOciClob.class.php'); 12 lmb_require(dirname(__FILE__) . '/lmbOciBlob.class.php'); 13 14 /** 15 * class lmbOciManipulationStatement. 16 * 17 * @package dbal 18 * @version $Id: lmbOciManipulationStatement.class.php 5945 2007-06-06 08:31:43Z pachanga $ 19 */ 20 class lmbOciManipulationStatement extends lmbOciStatement implements lmbDbManipulationStatement 21 { 22 protected $queryId; 23 protected $lobs = array(); 24 protected $lobDescriptors = array(); 25 26 function execute() 27 { 28 if(!$this->lobs) 29 { 30 $this->queryId = parent :: execute(); 31 return $this->queryId; 32 } 33 34 $this->connection->beginTransaction(); 35 36 $this->queryId = parent :: execute(); 37 38 if($this->_saveLobs()) 39 $this->connection->commitTransaction(); 40 else 41 $this->connection->rollbackTransaction(); 42 43 $this->_freeLobs(); 44 45 return $this->queryId; 46 } 47 48 protected function _saveLobs() 49 { 50 $result = true; 51 foreach($this->lobDescriptors as $name => $descriptor) 52 { 53 if(!$descriptor->save($this->lobs[$name]->read())) 54 { 55 $result = false; 56 break; 57 } 58 } 59 return $result; 60 } 61 62 protected function _freeLobs() 63 { 64 foreach($this->lobDescriptors as $name => $descriptor) 65 $descriptor->free(); 66 67 $this->lobs = array(); 68 $this->lobDescriptors = array(); 69 } 70 71 function setClob($name, $value) 72 { 73 $this->lobs[$name] = new lmbOciClob($value); 74 $this->hasChanged = true; 75 } 76 77 function setBlob($name, $value) 78 { 79 $this->lobs[$name] = new lmbOciBlob($value); 80 $this->hasChanged = true; 81 } 82 83 function getAffectedRowCount() 84 { 85 if(is_resource($this->queryId)) 86 return oci_num_rows($this->queryId); 87 } 88 89 protected function _handleBindVars($sql) 90 { 91 return $this->_handleBindedLobs(parent :: _handleBindVars($sql)); 92 } 93 94 protected function _handleBindedLobs($sql) 95 { 96 if(!$this->lobs) 97 return $sql; 98 99 $holder_to_field_map = array(); 100 101 foreach($this->lobs as $name => $lob) 102 { 103 if(array_key_exists($name, $this->parameters)) 104 unset($this->parameters[$name]); 105 106 if(strpos($sql, ":p_$name") !== false) 107 $holder_to_field_map[$name] = $this->_mapHolderToField($name, $sql); 108 } 109 110 $sql .= " RETURNING "; 111 112 foreach($this->lobs as $name => $lob) 113 { 114 $sql = str_replace(":p_$name", $lob->getEmptyExpression(), $sql); 115 $this->lobDescriptors[$name] = oci_new_descriptor($this->connection->getConnectionId(), 116 $lob->getDescriptorType()); 117 118 $sql .= "{$holder_to_field_map[$name]},"; 119 } 120 121 $sql = rtrim($sql, ','); 122 $sql .= " INTO "; 123 124 foreach(array_keys($this->lobs) as $name) 125 $sql .= ":p_$name,"; 126 127 return rtrim($sql, ','); 128 } 129 130 protected function _mapHolderToField($name, $sql) 131 { 132 return $name; 133 } 134 135 protected function _prepareStatement() 136 { 137 parent :: _prepareStatement(); 138 139 foreach(array_keys($this->lobDescriptors) as $name) 140 { 141 if(!oci_bind_by_name($this->statement, 142 ':p_' . $name, 143 $this->lobDescriptors[$name], 144 -1, 145 $this->lobs[$name]->getNativeType())) 146 $this->connection->_raiseError($this->statement); 147 } 148 } 149 } 150 151 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |