| [ 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/lmbDbStatement.interface.php'); 10 11 /** 12 * class lmbOciStatement. 13 * 14 * @package dbal 15 * @version $Id: lmbOciStatement.class.php 5945 2007-06-06 08:31:43Z pachanga $ 16 */ 17 class lmbOciStatement implements lmbDbStatement 18 { 19 protected $sql; 20 protected $statement = null; 21 protected $connection; 22 protected $modified = false; 23 protected $parameters = array(); 24 25 function __construct($connection, $sql) 26 { 27 $this->sql = $sql; 28 $this->connection = $connection; 29 } 30 31 function set($name, $value) 32 { 33 $this->parameters[$name] = $value; 34 $this->modified = true; 35 } 36 37 function import($paramList) 38 { 39 foreach($paramList as $name=>$value) 40 $this->set($name, $value); 41 } 42 43 function getSQL() 44 { 45 return $this->sql; 46 } 47 48 function getStatement() 49 { 50 if(!$this->statement || $this->hasChanged) 51 $this->_prepareStatement(); 52 return $this->statement; 53 } 54 55 protected function _prepareStatement() 56 { 57 $this->statement = oci_parse($this->connection->getConnectionId(), 58 $this->_handleBindVars($this->sql)); 59 60 if(!$this->statement) 61 { 62 $this->connection->_raiseError(); 63 return; 64 } 65 66 foreach(array_keys($this->parameters) as $name) 67 { 68 if(!oci_bind_by_name($this->statement, ':p_' . $name, $this->parameters[$name], -1)) 69 $this->connection->_raiseError($this->statement); 70 } 71 72 $this->hasChanged = false; 73 } 74 75 protected function _handleBindVars($sql) 76 { 77 $newsql = ''; 78 // Regex searches for bind vars in an SQL string 79 // It ignores ':this:' (quotes), --:this: (one type of Oracle comment) 80 // Needs to support /* this style of comment */ 81 // It's also pretty inefficient as matches "uninteresting" SQL character 82 // by character. Need a "real" parser? 83 while(preg_match('/^(\'[^\']*?\')|(--[^(\n)]*?\n)|(:(?-U)\w+:(?U))|.+/Us', $sql, $matches)) 84 { 85 if(isset($matches[3])) 86 { 87 $param = str_replace(':', '', $matches[0]); 88 89 if(!array_key_exists($param, $this->parameters)) 90 $this->parameters[$param] = null; 91 92 $newsql .= ":p_$param"; 93 } 94 else 95 $newsql .= $matches[0]; 96 97 $sql = substr($sql, strlen($matches[0])); 98 } 99 return $newsql; 100 } 101 102 function execute() 103 { 104 return $this->connection->executeStatement($this->getStatement()); 105 } 106 107 function free() 108 { 109 if($this->statement) 110 { 111 oci_free_statement($this->statement); 112 $this->statement = null; 113 } 114 } 115 116 function setNull($name) 117 { 118 $this->parameters[$name] = null; 119 $this->hasChanged = true; 120 } 121 122 function setSmallInt($name, $value) 123 { 124 $this->parameters[$name] = is_null($value) ? null : intval($value); 125 $this->hasChanged = true; 126 } 127 128 function setInteger($name, $value) 129 { 130 $this->parameters[$name] = is_null($value) ? null : intval($value); 131 $this->hasChanged = true; 132 } 133 134 function setFloat($name, $value) 135 { 136 $this->parameters[$name] = is_null($value) ? null : floatval($value); 137 $this->hasChanged = true; 138 } 139 140 function setDouble($name, $value) 141 { 142 if(is_float($value) || is_integer($value)) 143 $this->parameters[$name] = $value; 144 else if(is_string($value) && preg_match('/^(|-)\d+(|.\d+)$/', $value)) 145 $this->parameters[$name] = $value; 146 else 147 $this->parameters[$name] = null; 148 $this->hasChanged = true; 149 } 150 151 function setDecimal($name, $value) 152 { 153 if(is_float($value) || is_integer($value)) 154 $this->parameters[$name] = $value; 155 else if(is_string($value) && preg_match('/^(|-)\d+(|.\d+)$/', $value)) 156 $this->parameters[$name] = $value; 157 else 158 $this->parameters[$name] = null; 159 $this->hasChanged = true; 160 } 161 162 function setBoolean($name, $value) 163 { 164 $this->parameters[$name] = is_null($value) ? null : (($value) ? 1 : 0); 165 $this->hasChanged = true; 166 } 167 168 function setChar($name, $value) 169 { 170 $this->parameters[$name] = is_null($value) ? null : $value; 171 $this->hasChanged = true; 172 } 173 174 function setVarChar($name, $value) 175 { 176 $this->parameters[$name] = is_null($value) ? null : $value; 177 $this->hasChanged = true; 178 } 179 180 function setDate($name, $value) 181 { 182 $this->parameters[$name] = is_null($value) ? null : $value; 183 $this->hasChanged = true; 184 } 185 186 function setTime($name, $value) 187 { 188 throw new lmbDbException(__METHOD__ . ' not implemented'); 189 } 190 191 function setTimeStamp($name, $value) 192 { 193 $this->parameters[$name] = is_null($value) ? null : intval($value); 194 $this->hasChanged = true; 195 } 196 197 function setBlob($name, $value) 198 { 199 throw new lmbDbException(__METHOD__ . ' not implemented'); 200 } 201 202 function setClob($name, $value) 203 { 204 throw new lmbDbException(__METHOD__ . ' not implemented'); 205 } 206 } 207 208 ?>
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 |