| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id$
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information, see
|
|
|
19 |
* <http://www.doctrine-project.org>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Oracle connection adapter statement class.
|
|
|
24 |
*
|
|
|
25 |
* @package Doctrine
|
|
|
26 |
* @subpackage Adapter
|
|
|
27 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
28 |
* @author vadik56
|
|
|
29 |
* @author Miloslav Kmet <adrive-nospam@hip-hop.sk>
|
|
|
30 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
31 |
* @link www.doctrine-project.org
|
|
|
32 |
* @since 1.0
|
|
|
33 |
* @version $Rev$
|
|
|
34 |
*/
|
|
|
35 |
class Doctrine_Adapter_Statement_Oracle implements Doctrine_Adapter_Statement_Interface
|
|
|
36 |
{
|
|
|
37 |
/**
|
|
|
38 |
* @var string $queryString actual query string
|
|
|
39 |
*/
|
|
|
40 |
public $queryString;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* @var resource $connection OCI connection handler
|
|
|
44 |
*/
|
|
|
45 |
protected $connection;
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* @var resource $statement OCI prepared statement
|
|
|
49 |
*/
|
|
|
50 |
protected $statement;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* @var integer $executeMode OCI statement execution mode
|
|
|
54 |
*/
|
|
|
55 |
protected $executeMode = OCI_COMMIT_ON_SUCCESS;
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* @var array $bindParams Array of parameters bounded to a statement
|
|
|
59 |
*/
|
|
|
60 |
protected $bindParams = array();
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* @var array $attributes Array of attributes
|
|
|
64 |
*/
|
|
|
65 |
protected $attributes = array();
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* @var array $ociErrors Array of errors
|
|
|
69 |
*/
|
|
|
70 |
protected $ociErrors = array();
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* the constructor
|
|
|
74 |
*
|
|
|
75 |
* @param Doctrine_Adapter_Oracle $connection
|
|
|
76 |
* @param string $query Query string to be executed
|
|
|
77 |
* @param integer $executeMode OCI execute mode
|
|
|
78 |
*/
|
|
|
79 |
public function __construct( Doctrine_Adapter_Oracle $connection, $query, $executeMode)
|
|
|
80 |
{
|
|
|
81 |
$this->connection = $connection->getConnection();
|
|
|
82 |
$this->queryString = $query;
|
|
|
83 |
$this->executeMode = $executeMode;
|
|
|
84 |
$this->attributes[Doctrine_Core::ATTR_ERRMODE] = $connection->getAttribute(Doctrine_Core::ATTR_ERRMODE);
|
|
|
85 |
|
|
|
86 |
$this->parseQuery();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Bind a column to a PHP variable
|
|
|
91 |
*
|
|
|
92 |
* @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
|
|
|
93 |
* If using the column name, be aware that the name should match
|
|
|
94 |
* the case of the column, as returned by the driver.
|
|
|
95 |
* @param string $param Name of the PHP variable to which the column will be bound.
|
|
|
96 |
* @param integer $type Data type of the parameter, specified by the Doctrine_Core::PARAM_* constants.
|
|
|
97 |
* @return boolean Returns TRUE on success or FALSE on failure
|
|
|
98 |
*/
|
|
|
99 |
public function bindColumn($column, $param, $type = null)
|
|
|
100 |
{
|
|
|
101 |
throw new Doctrine_Adapter_Exception("Unsupported");
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Binds a value to a corresponding named or question mark
|
|
|
106 |
* placeholder in the SQL statement that was use to prepare the statement.
|
|
|
107 |
*
|
|
|
108 |
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
|
109 |
* this will be a parameter name of the form :name. For a prepared statement
|
|
|
110 |
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
|
111 |
*
|
|
|
112 |
* @param mixed $value The value to bind to the parameter.
|
|
|
113 |
* @param integer $type Explicit data type for the parameter using the Doctrine_Core::PARAM_* constants.
|
|
|
114 |
*
|
|
|
115 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
116 |
*/
|
|
|
117 |
public function bindValue($param, $value, $type = null)
|
|
|
118 |
{
|
|
|
119 |
/**
|
|
|
120 |
* need to store the value internally since binding is done by reference
|
|
|
121 |
*/
|
|
|
122 |
$this->bindParams[] = $value;
|
|
|
123 |
$this->bindParam($param, $this->bindParams[count($this->bindParams) - 1], $type);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Binds a PHP variable to a corresponding named or question mark placeholder in the
|
|
|
128 |
* SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
|
|
|
129 |
* the variable is bound as a reference and will only be evaluated at the time
|
|
|
130 |
* that Doctrine_Adapter_Statement_Interface->execute() is called.
|
|
|
131 |
*
|
|
|
132 |
* Most parameters are input parameters, that is, parameters that are
|
|
|
133 |
* used in a read-only fashion to build up the query. Some drivers support the invocation
|
|
|
134 |
* of stored procedures that return data as output parameters, and some also as input/output
|
|
|
135 |
* parameters that both send in data and are updated to receive it.
|
|
|
136 |
*
|
|
|
137 |
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
|
138 |
* this will be a parameter name of the form :name. For a prepared statement
|
|
|
139 |
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
|
140 |
*
|
|
|
141 |
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
|
|
142 |
*
|
|
|
143 |
* @param integer $type Explicit data type for the parameter using the Doctrine_Core::PARAM_* constants. To return
|
|
|
144 |
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
|
|
145 |
* Doctrine_Core::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
|
|
146 |
*
|
|
|
147 |
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
|
|
148 |
* from a stored procedure, you must explicitly set the length.
|
|
|
149 |
* @param mixed $driverOptions
|
|
|
150 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
151 |
*/
|
|
|
152 |
public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array())
|
|
|
153 |
{
|
|
|
154 |
if ($driverOptions || $length ) {
|
|
|
155 |
throw new Doctrine_Adapter_Exception('Unsupported parameters:$length, $driverOptions');
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
if ($length === null) {
|
|
|
159 |
$oci_length = -1;
|
|
|
160 |
}
|
|
|
161 |
$oci_type = SQLT_CHR;
|
|
|
162 |
|
|
|
163 |
switch ($type) {
|
|
|
164 |
case Doctrine_Core::PARAM_STR:
|
|
|
165 |
$oci_type = SQLT_CHR;
|
|
|
166 |
break;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
if (is_integer($column)) {
|
|
|
170 |
$variable_name = ":oci_b_var_$column";
|
|
|
171 |
} else {
|
|
|
172 |
$variable_name = $column;
|
|
|
173 |
}
|
|
|
174 |
//print "Binding $variable to $variable_name".PHP_EOL;
|
|
|
175 |
$status = @oci_bind_by_name($this->statement, $variable_name, $variable, $oci_length, $oci_type);
|
|
|
176 |
if ($status === false) {
|
|
|
177 |
$this->handleError();
|
|
|
178 |
}
|
|
|
179 |
return $status;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
/**
|
|
|
183 |
* Closes the cursor, enabling the statement to be executed again.
|
|
|
184 |
*
|
|
|
185 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
186 |
*/
|
|
|
187 |
public function closeCursor()
|
|
|
188 |
{
|
|
|
189 |
$this->bindParams = array();
|
|
|
190 |
return oci_free_statement($this->statement);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/**
|
|
|
194 |
* Returns the number of columns in the result set
|
|
|
195 |
*
|
|
|
196 |
* @return integer Returns the number of columns in the result set represented
|
|
|
197 |
* by the Doctrine_Adapter_Statement_Interface object. If there is no result set,
|
|
|
198 |
* this method should return 0.
|
|
|
199 |
*/
|
|
|
200 |
public function columnCount()
|
|
|
201 |
{
|
|
|
202 |
return oci_num_fields ( $this->statement );
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
* Fetch the SQLSTATE associated with the last operation on the statement handle
|
|
|
207 |
*
|
|
|
208 |
* @see Doctrine_Adapter_Interface::errorCode()
|
|
|
209 |
* @return string error code string
|
|
|
210 |
*/
|
|
|
211 |
public function errorCode()
|
|
|
212 |
{
|
|
|
213 |
$oci_error = $this->getOciError();
|
|
|
214 |
return $oci_error['code'];
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
/**
|
|
|
218 |
* Fetch extended error information associated with the last operation on the statement handle
|
|
|
219 |
*
|
|
|
220 |
* @see Doctrine_Adapter_Interface::errorInfo()
|
|
|
221 |
* @return array error info array
|
|
|
222 |
*/
|
|
|
223 |
public function errorInfo()
|
|
|
224 |
{
|
|
|
225 |
$oci_error = $this->getOciError();
|
|
|
226 |
return $oci_error['message'] . " : " . $oci_error['sqltext'];
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
private function getOciError()
|
|
|
230 |
{
|
|
|
231 |
if (is_resource($this->statement)) {
|
|
|
232 |
$oci_error = oci_error ($this->statement);
|
|
|
233 |
} else {
|
|
|
234 |
$oci_error = oci_error ();
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
if ($oci_error) {
|
|
|
238 |
//store the error
|
|
|
239 |
$this->oci_errors[] = $oci_error;
|
|
|
240 |
} else if (count($this->ociErrors) > 0) {
|
|
|
241 |
$oci_error = $this->ociErrors[count($this->ociErrors)-1];
|
|
|
242 |
}
|
|
|
243 |
return $oci_error;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
/**
|
|
|
247 |
* Executes a prepared statement
|
|
|
248 |
*
|
|
|
249 |
* If the prepared statement included parameter markers, you must either:
|
|
|
250 |
* call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
|
|
|
251 |
* bound variables pass their value as input and receive the output value,
|
|
|
252 |
* if any, of their associated parameter markers or pass an array of input-only
|
|
|
253 |
* parameter values
|
|
|
254 |
*
|
|
|
255 |
*
|
|
|
256 |
* @param array $params An array of values with as many elements as there are
|
|
|
257 |
* bound parameters in the SQL statement being executed.
|
|
|
258 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
259 |
*/
|
|
|
260 |
public function execute($params = null)
|
|
|
261 |
{
|
|
|
262 |
if (is_array($params)) {
|
|
|
263 |
foreach ($params as $var => $value) {
|
|
|
264 |
$this->bindValue($var+1, $value);
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
$result = @oci_execute($this->statement , $this->executeMode );
|
|
|
269 |
|
|
|
270 |
if ($result === false) {
|
|
|
271 |
$this->handleError();
|
|
|
272 |
return false;
|
|
|
273 |
}
|
|
|
274 |
return true;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
/**
|
|
|
278 |
* fetch
|
|
|
279 |
*
|
|
|
280 |
* @see Doctrine_Core::FETCH_* constants
|
|
|
281 |
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
|
282 |
* This value must be one of the Doctrine_Core::FETCH_* constants,
|
|
|
283 |
* defaulting to Doctrine_Core::FETCH_BOTH
|
|
|
284 |
*
|
|
|
285 |
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
|
|
286 |
* this value determines which row will be returned to the caller.
|
|
|
287 |
* This value must be one of the Doctrine_Core::FETCH_ORI_* constants, defaulting to
|
|
|
288 |
* Doctrine_Core::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
|
|
289 |
* Doctrine_Adapter_Statement_Interface object,
|
|
|
290 |
* you must set the Doctrine_Core::ATTR_CURSOR attribute to Doctrine_Core::CURSOR_SCROLL when you
|
|
|
291 |
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
|
|
292 |
*
|
|
|
293 |
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
|
|
294 |
* $cursorOrientation parameter is set to Doctrine_Core::FETCH_ORI_ABS, this value specifies
|
|
|
295 |
* the absolute number of the row in the result set that shall be fetched.
|
|
|
296 |
*
|
|
|
297 |
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
|
|
298 |
* which the $cursorOrientation parameter is set to Doctrine_Core::FETCH_ORI_REL, this value
|
|
|
299 |
* specifies the row to fetch relative to the cursor position before
|
|
|
300 |
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
|
|
301 |
*
|
|
|
302 |
* @return mixed
|
|
|
303 |
*/
|
|
|
304 |
public function fetch($fetchStyle = Doctrine_Core::FETCH_BOTH, $cursorOrientation = Doctrine_Core::FETCH_ORI_NEXT, $cursorOffset = null)
|
|
|
305 |
{
|
|
|
306 |
switch ($fetchStyle) {
|
|
|
307 |
case Doctrine_Core::FETCH_BOTH :
|
|
|
308 |
return oci_fetch_array($this->statement, OCI_BOTH + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
|
|
309 |
break;
|
|
|
310 |
case Doctrine_Core::FETCH_ASSOC :
|
|
|
311 |
return oci_fetch_array($this->statement, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
|
|
312 |
break;
|
|
|
313 |
case Doctrine_Core::FETCH_NUM :
|
|
|
314 |
return oci_fetch_array($this->statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
|
|
315 |
break;
|
|
|
316 |
case Doctrine_Core::FETCH_OBJ:
|
|
|
317 |
return oci_fetch_object($this->statement, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
|
|
318 |
break;
|
|
|
319 |
default:
|
|
|
320 |
throw new Doctrine_Adapter_Exception("This type of fetch is not supported: ".$fetchStyle);
|
|
|
321 |
/*
|
|
|
322 |
case Doctrine_Core::FETCH_BOUND:
|
|
|
323 |
case Doctrine_Core::FETCH_CLASS:
|
|
|
324 |
case FETCH_CLASSTYPE:
|
|
|
325 |
case FETCH_COLUMN:
|
|
|
326 |
case FETCH_FUNC:
|
|
|
327 |
case FETCH_GROUP:
|
|
|
328 |
case FETCH_INTO:
|
|
|
329 |
case FETCH_LAZY:
|
|
|
330 |
case FETCH_NAMED:
|
|
|
331 |
case FETCH_SERIALIZE:
|
|
|
332 |
case FETCH_UNIQUE:
|
|
|
333 |
case FETCH_ORI_ABS:
|
|
|
334 |
case FETCH_ORI_FIRST:
|
|
|
335 |
case FETCH_ORI_LAST:
|
|
|
336 |
case FETCH_ORI_NEXT:
|
|
|
337 |
case FETCH_ORI_PRIOR:
|
|
|
338 |
case FETCH_ORI_REL:
|
|
|
339 |
*/
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
/**
|
|
|
344 |
* Returns an array containing all of the result set rows
|
|
|
345 |
*
|
|
|
346 |
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
|
347 |
* This value must be one of the Doctrine_Core::FETCH_* constants,
|
|
|
348 |
* defaulting to Doctrine_Core::FETCH_BOTH
|
|
|
349 |
*
|
|
|
350 |
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
|
|
351 |
* Doctrine_Core::FETCH_COLUMN. Defaults to 0.
|
|
|
352 |
*
|
|
|
353 |
* @return array
|
|
|
354 |
*/
|
|
|
355 |
public function fetchAll($fetchStyle = Doctrine_Core::FETCH_BOTH, $colnum=0)
|
|
|
356 |
{
|
|
|
357 |
$fetchColumn = false;
|
|
|
358 |
$skip = 0;
|
|
|
359 |
$maxrows = -1;
|
|
|
360 |
$data = array();
|
|
|
361 |
$flags = OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC;
|
|
|
362 |
|
|
|
363 |
$int = $fetchStyle & Doctrine_Core::FETCH_COLUMN;
|
|
|
364 |
|
|
|
365 |
if ($fetchStyle == Doctrine_Core::FETCH_BOTH) {
|
|
|
366 |
$flags = OCI_BOTH;
|
|
|
367 |
$numberOfRows = @oci_fetch_all($this->statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC + OCI_RETURN_LOBS);
|
|
|
368 |
} else if ($fetchStyle == Doctrine_Core::FETCH_ASSOC) {
|
|
|
369 |
$numberOfRows = @oci_fetch_all($this->statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC + OCI_RETURN_LOBS);
|
|
|
370 |
} else if ($fetchStyle == Doctrine_Core::FETCH_NUM) {
|
|
|
371 |
$numberOfRows = @oci_fetch_all($this->statement, $data, $skip, $maxrows, OCI_FETCHSTATEMENT_BY_ROW + OCI_NUM + OCI_RETURN_LOBS);
|
|
|
372 |
} else if ($fetchStyle == Doctrine_Core::FETCH_COLUMN) {
|
|
|
373 |
while ($row = @oci_fetch_array ($this->statement, OCI_NUM+OCI_RETURN_LOBS)) {
|
|
|
374 |
$data[] = $row[$colnum];
|
|
|
375 |
}
|
|
|
376 |
} else {
|
|
|
377 |
throw new Doctrine_Adapter_Exception("Unsupported mode: '" . $fetchStyle . "' ");
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
return $data;
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
/**
|
|
|
384 |
* Returns a single column from the next row of a
|
|
|
385 |
* result set or FALSE if there are no more rows.
|
|
|
386 |
*
|
|
|
387 |
* @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no
|
|
|
388 |
* value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn()
|
|
|
389 |
* fetches the first column.
|
|
|
390 |
*
|
|
|
391 |
* @return string returns a single column in the next row of a result set.
|
|
|
392 |
*/
|
|
|
393 |
public function fetchColumn($columnIndex = 0)
|
|
|
394 |
{
|
|
|
395 |
if ( ! is_integer($columnIndex)) {
|
|
|
396 |
$this->handleError(array('message'=>"columnIndex parameter should be numeric"));
|
|
|
397 |
|
|
|
398 |
return false;
|
|
|
399 |
}
|
|
|
400 |
$row = $this->fetch(Doctrine_Core::FETCH_NUM);
|
|
|
401 |
return isset($row[$columnIndex]) ? $row[$columnIndex] : false;
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
/**
|
|
|
405 |
* Fetches the next row and returns it as an object.
|
|
|
406 |
*
|
|
|
407 |
* Fetches the next row and returns it as an object. This function is an alternative to
|
|
|
408 |
* Doctrine_Adapter_Statement_Interface->fetch() with Doctrine_Core::FETCH_CLASS or Doctrine_Core::FETCH_OBJ style.
|
|
|
409 |
*
|
|
|
410 |
* @param string $className Name of the created class, defaults to stdClass.
|
|
|
411 |
* @param array $args Elements of this array are passed to the constructor.
|
|
|
412 |
*
|
|
|
413 |
* @return mixed an instance of the required class with property names that correspond
|
|
|
414 |
* to the column names or FALSE in case of an error.
|
|
|
415 |
*/
|
|
|
416 |
public function fetchObject($className = 'stdClass', $args = array())
|
|
|
417 |
{
|
|
|
418 |
$row = $this->fetch(Doctrine_Core::FETCH_ASSOC);
|
|
|
419 |
if ($row === false) {
|
|
|
420 |
return false;
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
$instantiation_code = "\$object = new $className(";
|
|
|
424 |
$firstParam=true;
|
|
|
425 |
foreach ($args as $index=>$value) {
|
|
|
426 |
if ( ! $firstParam ) {
|
|
|
427 |
$instantiation_code = $instantiation_code . ",";
|
|
|
428 |
} else {
|
|
|
429 |
$firstParam= false;
|
|
|
430 |
}
|
|
|
431 |
if ( is_string($index)) {
|
|
|
432 |
$instantiation_code = $instantiation_code . " \$args['$index']";
|
|
|
433 |
} else {
|
|
|
434 |
$instantiation_code = $instantiation_code . "\$args[$index]";
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
$instantiation_code = $instantiation_code . ");";
|
|
|
439 |
|
|
|
440 |
eval($instantiation_code);
|
|
|
441 |
|
|
|
442 |
//initialize instance of $className class
|
|
|
443 |
foreach ($row as $col => $value) {
|
|
|
444 |
$object->$col = $value;
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
return $object;
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
/**
|
|
|
451 |
* Returns metadata for a column in a result set
|
|
|
452 |
*
|
|
|
453 |
* @param integer $column The 0-indexed column in the result set.
|
|
|
454 |
*
|
|
|
455 |
* @return array Associative meta data array with the following structure:
|
|
|
456 |
*
|
|
|
457 |
* native_type The PHP native type used to represent the column value.
|
|
|
458 |
* driver:decl_ type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta().
|
|
|
459 |
* flags Any flags set for this column.
|
|
|
460 |
* name The name of this column as returned by the database.
|
|
|
461 |
* len The length of this column. Normally -1 for types other than floating point decimals.
|
|
|
462 |
* precision The numeric precision of this column. Normally 0 for types other than floating point decimals.
|
|
|
463 |
* pdo_type The type of this column as represented by the PDO::PARAM_* constants.
|
|
|
464 |
*/
|
|
|
465 |
public function getColumnMeta($column)
|
|
|
466 |
{
|
|
|
467 |
if (is_integer($column)) {
|
|
|
468 |
$internal_column = $column +1;
|
|
|
469 |
} else {
|
|
|
470 |
$internal_column = $column;
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
$data = array();
|
|
|
474 |
$data['native_type'] = oci_field_type($this->statement, $internal_column);
|
|
|
475 |
$data['flags'] = "";
|
|
|
476 |
$data['len'] = oci_field_size($this->statement, $internal_column);
|
|
|
477 |
$data['name'] = oci_field_name($this->statement, $internal_column);
|
|
|
478 |
$data['precision'] = oci_field_precision($this->statement, $internal_column);
|
|
|
479 |
|
|
|
480 |
return $data;
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
/**
|
|
|
484 |
* Advances to the next rowset in a multi-rowset statement handle
|
|
|
485 |
*
|
|
|
486 |
* Some database servers support stored procedures that return more than one rowset
|
|
|
487 |
* (also known as a result set). The nextRowset() method enables you to access the second
|
|
|
488 |
* and subsequent rowsets associated with a PDOStatement object. Each rowset can have a
|
|
|
489 |
* different set of columns from the preceding rowset.
|
|
|
490 |
*
|
|
|
491 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
492 |
*/
|
|
|
493 |
public function nextRowset()
|
|
|
494 |
{
|
|
|
495 |
throw new Doctrine_Adapter_Exception("Unsupported");
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
/**
|
|
|
499 |
* rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
|
|
|
500 |
* executed by the corresponding object.
|
|
|
501 |
*
|
|
|
502 |
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
|
|
|
503 |
* some databases may return the number of rows returned by that statement. However,
|
|
|
504 |
* this behaviour is not guaranteed for all databases and should not be
|
|
|
505 |
* relied on for portable applications.
|
|
|
506 |
*
|
|
|
507 |
* @return integer Returns the number of rows.
|
|
|
508 |
*/
|
|
|
509 |
public function rowCount()
|
|
|
510 |
{
|
|
|
511 |
return @oci_num_rows($this->statement);
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
/**
|
|
|
515 |
* Set a statement attribute
|
|
|
516 |
*
|
|
|
517 |
* @param integer $attribute
|
|
|
518 |
* @param mixed $value the value of given attribute
|
|
|
519 |
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
|
520 |
*/
|
|
|
521 |
public function setAttribute($attribute, $value)
|
|
|
522 |
{
|
|
|
523 |
switch ($attribute) {
|
|
|
524 |
case Doctrine_Core::ATTR_ERRMODE;
|
|
|
525 |
break;
|
|
|
526 |
default:
|
|
|
527 |
throw new Doctrine_Adapter_Exception("Unsupported Attribute: $attribute");
|
|
|
528 |
}
|
|
|
529 |
$this->attributes[$attribute] = $value;
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
/**
|
|
|
533 |
* Retrieve a statement attribute
|
|
|
534 |
*
|
|
|
535 |
* @param integer $attribute
|
|
|
536 |
* @see Doctrine_Core::ATTR_* constants
|
|
|
537 |
* @return mixed the attribute value
|
|
|
538 |
*/
|
|
|
539 |
public function getAttribute($attribute)
|
|
|
540 |
{
|
|
|
541 |
return $this->attributes[$attribute];
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
/**
|
|
|
545 |
* Set the default fetch mode for this statement
|
|
|
546 |
*
|
|
|
547 |
* @param integer $mode The fetch mode must be one of the Doctrine_Core::FETCH_* constants.
|
|
|
548 |
* @return boolean Returns 1 on success or FALSE on failure.
|
|
|
549 |
*/
|
|
|
550 |
public function setFetchMode($mode, $arg1 = null, $arg2 = null)
|
|
|
551 |
{
|
|
|
552 |
throw new Doctrine_Adapter_Exception("Unsupported");
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
private function handleError($params=array())
|
|
|
556 |
{
|
|
|
557 |
|
|
|
558 |
switch ($this->attributes[Doctrine_Core::ATTR_ERRMODE]) {
|
|
|
559 |
case Doctrine_Core::ERRMODE_EXCEPTION:
|
|
|
560 |
if (isset($params['message'])) {
|
|
|
561 |
throw new Doctrine_Adapter_Exception($params['message']);
|
|
|
562 |
} else {
|
|
|
563 |
throw new Doctrine_Adapter_Exception($this->errorInfo());
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
break;
|
|
|
567 |
case Doctrine_Core::ERRMODE_WARNING:
|
|
|
568 |
case Doctrine_Core::ERRMODE_SILENT:
|
|
|
569 |
break;
|
|
|
570 |
}
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
/**
|
|
|
574 |
* Parse actual query from queryString and returns OCI statement handler
|
|
|
575 |
* @param string Query string to parse, if NULL, $this->queryString is used
|
|
|
576 |
*
|
|
|
577 |
* @return resource OCI statement handler
|
|
|
578 |
*/
|
|
|
579 |
private function parseQuery($query=null)
|
|
|
580 |
{
|
|
|
581 |
if (is_null($query)) {
|
|
|
582 |
$query = $this->queryString;
|
|
|
583 |
}
|
|
|
584 |
$bind_index = 1;
|
|
|
585 |
// Replace ? bind-placeholders with :oci_b_var_ variables
|
|
|
586 |
$query = preg_replace("/(\?)/e", '":oci_b_var_". $bind_index++' , $query);
|
|
|
587 |
|
|
|
588 |
$this->statement = @oci_parse($this->connection, $query);
|
|
|
589 |
|
|
|
590 |
if ( $this->statement == false )
|
|
|
591 |
{
|
|
|
592 |
throw new Doctrine_Adapter_Exception($this->getOciError());
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
return $this->statement;
|
|
|
596 |
}
|
|
|
597 |
}
|