Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Statement_Oracle Class Reference
Inheritance diagram for Zend_Db_Statement_Oracle:
Zend_Db_Statement Zend_Db_Statement_Interface

Public Member Functions

 setLobAsString ($lob_as_string)
 
 getLobAsString ()
 
 closeCursor ()
 
 columnCount ()
 
 errorCode ()
 
 errorInfo ()
 
 _execute (array $params=null)
 
 fetch ($style=null, $cursor=null, $offset=null)
 
 fetchAll ($style=null, $col=0)
 
 fetchColumn ($col=0)
 
 fetchObject ($class='stdClass', array $config=array())
 
 nextRowset ()
 
 rowCount ()
 
- Public Member Functions inherited from Zend_Db_Statement
 __construct ($adapter, $sql)
 
 bindColumn ($column, &$param, $type=null)
 
 bindParam ($parameter, &$variable, $type=null, $length=null, $options=null)
 
 bindValue ($parameter, $value, $type=null)
 
 execute (array $params=null)
 
 fetchAll ($style=null, $col=null)
 
 fetchColumn ($col=0)
 
 fetchObject ($class='stdClass', array $config=array())
 
 getAttribute ($key)
 
 setAttribute ($key, $val)
 
 setFetchMode ($mode)
 
 _fetchBound ($row)
 
 getAdapter ()
 
 getDriverStatement ()
 

Protected Member Functions

 _prepare ($sql)
 
 _bindParam ($parameter, &$variable, $type=null, $length=null, $options=null)
 
- Protected Member Functions inherited from Zend_Db_Statement
 _prepare ($sql)
 
 _parseParameters ($sql)
 
 _stripQuoted ($sql)
 

Protected Attributes

 $_keys
 
 $_values
 
 $_lobAsString = false
 
- Protected Attributes inherited from Zend_Db_Statement
 $_stmt = null
 
 $_adapter = null
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_attribute = array()
 
 $_bindColumn = array()
 
 $_bindParam = array()
 
 $_sqlSplit = array()
 
 $_sqlParam = array()
 
 $_queryId = null
 

Detailed Description

Definition at line 37 of file Oracle.php.

Member Function Documentation

◆ _bindParam()

_bindParam (   $parameter,
$variable,
  $type = null,
  $length = null,
  $options = null 
)
protected

Binds a parameter to the specified variable name.

Parameters
mixed$parameterName the parameter, either integer or string.
mixed$variableReference to PHP variable containing the value.
mixed$typeOPTIONAL Datatype of SQL parameter.
mixed$lengthOPTIONAL Length of SQL parameter.
mixed$optionsOPTIONAL Other options.
Returns
bool
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception

Definition at line 111 of file Oracle.php.

112  {
113  // default value
114  if ($type === NULL) {
115  $type = SQLT_CHR;
116  }
117 
118  // default value
119  if ($length === NULL) {
120  $length = -1;
121  }
122 
123  $retval = @oci_bind_by_name($this->_stmt, $parameter, $variable, $length, $type);
124  if ($retval === false) {
128  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
129  throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
130  }
131 
132  return true;
133  }
$variable
Definition: variable.php:7
$type
Definition: item.phtml:13

◆ _execute()

_execute ( array  $params = null)

Executes a prepared statement.

Parameters
array$paramsOPTIONAL Values to bind to parameter placeholders.
Returns
bool
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Definition at line 229 of file Oracle.php.

230  {
231  $connection = $this->_adapter->getConnection();
232 
233  if (!$this->_stmt) {
234  return false;
235  }
236 
237  if ($params !== null) {
238  if (!is_array($params)) {
239  $params = array($params);
240  }
241  $error = false;
242  foreach (array_keys($params) as $name) {
243  if (!$this->bindParam($name, $params[$name], null, -1)) {
244  $error = true;
245  break;
246  }
247  }
248  if ($error) {
252  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
253  throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
254  }
255  }
256 
257  $retval = @oci_execute($this->_stmt, $this->_adapter->_getExecuteMode());
258  if ($retval === false) {
262  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
263  throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
264  }
265 
266  $this->_keys = Array();
267  if ($field_num = oci_num_fields($this->_stmt)) {
268  for ($i = 1; $i <= $field_num; $i++) {
269  $name = oci_field_name($this->_stmt, $i);
270  $this->_keys[] = $name;
271  }
272  }
273 
274  $this->_values = Array();
275  if ($this->_keys) {
276  $this->_values = array_fill(0, count($this->_keys), null);
277  }
278 
279  return $retval;
280  }
bindParam($parameter, &$variable, $type=null, $length=null, $options=null)
Definition: Statement.php:241
$connection
Definition: bulk.php:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$i
Definition: gallery.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _prepare()

_prepare (   $sql)
protected

Prepares statement handle

Parameters
string$sql
Returns
void
Exceptions
Zend_Db_Statement_Oracle_Exception
See also
Zend_Db_Statement_Oracle_Exception

Definition at line 87 of file Oracle.php.

88  {
89  $connection = $this->_adapter->getConnection();
90  $this->_stmt = @oci_parse($connection, $sql);
91  if (!$this->_stmt) {
95  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
96  throw new Zend_Db_Statement_Oracle_Exception(oci_error($connection));
97  }
98  }
$connection
Definition: bulk.php:13

◆ closeCursor()

closeCursor ( )

Closes the cursor, allowing the statement to be executed again.

Returns
bool

Implements Zend_Db_Statement_Interface.

Definition at line 140 of file Oracle.php.

141  {
142  if (!$this->_stmt) {
143  return false;
144  }
145 
146  oci_free_statement($this->_stmt);
147  $this->_stmt = false;
148  return true;
149  }

◆ columnCount()

columnCount ( )

Returns the number of columns in the result set. Returns null if the statement has no result set metadata.

Returns
int The number of columns.

Implements Zend_Db_Statement_Interface.

Definition at line 157 of file Oracle.php.

158  {
159  if (!$this->_stmt) {
160  return false;
161  }
162 
163  return oci_num_fields($this->_stmt);
164  }

◆ errorCode()

errorCode ( )

Retrieves the error code, if any, associated with the last operation on the statement handle.

Returns
string error code.

Implements Zend_Db_Statement_Interface.

Definition at line 173 of file Oracle.php.

174  {
175  if (!$this->_stmt) {
176  return false;
177  }
178 
179  $error = oci_error($this->_stmt);
180 
181  if (!$error) {
182  return false;
183  }
184 
185  return $error['code'];
186  }

◆ errorInfo()

errorInfo ( )

Retrieves an array of error information, if any, associated with the last operation on the statement handle.

Returns
array

Implements Zend_Db_Statement_Interface.

Definition at line 195 of file Oracle.php.

196  {
197  if (!$this->_stmt) {
198  return false;
199  }
200 
201  $error = oci_error($this->_stmt);
202  if (!$error) {
203  return false;
204  }
205 
206  if (isset($error['sqltext'])) {
207  return array(
208  $error['code'],
209  $error['message'],
210  $error['offset'],
211  $error['sqltext'],
212  );
213  } else {
214  return array(
215  $error['code'],
216  $error['message'],
217  );
218  }
219  }

◆ fetch()

fetch (   $style = null,
  $cursor = null,
  $offset = null 
)

Fetches a row from the result set.

Parameters
int$styleOPTIONAL Fetch mode for this fetch operation.
int$cursorOPTIONAL Absolute, relative, or other.
int$offsetOPTIONAL Number for absolute or relative cursors.
Returns
mixed Array, object, or scalar depending on fetch mode.
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 291 of file Oracle.php.

292  {
293  if (!$this->_stmt) {
294  return false;
295  }
296 
297  if ($style === null) {
298  $style = $this->_fetchMode;
299  }
300 
301  $lob_as_string = $this->getLobAsString() ? OCI_RETURN_LOBS : 0;
302 
303  switch ($style) {
304  case Zend_Db::FETCH_NUM:
305  $row = oci_fetch_array($this->_stmt, OCI_NUM | OCI_RETURN_NULLS | $lob_as_string);
306  break;
308  $row = oci_fetch_array($this->_stmt, OCI_ASSOC | OCI_RETURN_NULLS | $lob_as_string);
309  break;
310  case Zend_Db::FETCH_BOTH:
311  $row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
312  break;
313  case Zend_Db::FETCH_OBJ:
314  $row = oci_fetch_object($this->_stmt);
315  break;
317  $row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
318  if ($row !== false) {
319  return $this->_fetchBound($row);
320  }
321  break;
322  default:
326  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
328  array(
329  'code' => 'HYC00',
330  'message' => "Invalid fetch mode '$style' specified"
331  )
332  );
333  break;
334  }
335 
336  if (! $row && $error = oci_error($this->_stmt)) {
340  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
341  throw new Zend_Db_Statement_Oracle_Exception($error);
342  }
343 
344  if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
345  unset($row['zend_db_rownum']);
346  }
347 
348  return $row;
349  }
const FETCH_BOUND
Definition: Db.php:144
const FETCH_ASSOC
Definition: Db.php:142
const FETCH_BOTH
Definition: Db.php:143
const FETCH_NUM
Definition: Db.php:153
const FETCH_OBJ
Definition: Db.php:154

◆ fetchAll()

fetchAll (   $style = null,
  $col = 0 
)

Returns an array containing all of the result set rows.

Parameters
int$styleOPTIONAL Fetch mode.
int$colOPTIONAL Column number, if fetch mode is by column.
Returns
array Collection of rows, each in a format by the fetch mode.
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 359 of file Oracle.php.

360  {
361  if (!$this->_stmt) {
362  return false;
363  }
364 
365  // make sure we have a fetch mode
366  if ($style === null) {
367  $style = $this->_fetchMode;
368  }
369 
370  $flags = OCI_FETCHSTATEMENT_BY_ROW;
371 
372  switch ($style) {
373  case Zend_Db::FETCH_BOTH:
377  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
379  array(
380  'code' => 'HYC00',
381  'message' => "OCI8 driver does not support fetchAll(FETCH_BOTH), use fetch() in a loop instead"
382  )
383  );
384  // notreached
385  $flags |= OCI_NUM;
386  $flags |= OCI_ASSOC;
387  break;
388  case Zend_Db::FETCH_NUM:
389  $flags |= OCI_NUM;
390  break;
392  $flags |= OCI_ASSOC;
393  break;
394  case Zend_Db::FETCH_OBJ:
395  break;
397  $flags = $flags &~ OCI_FETCHSTATEMENT_BY_ROW;
398  $flags |= OCI_FETCHSTATEMENT_BY_COLUMN;
399  $flags |= OCI_NUM;
400  break;
401  default:
405  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
407  array(
408  'code' => 'HYC00',
409  'message' => "Invalid fetch mode '$style' specified"
410  )
411  );
412  break;
413  }
414 
415  $result = Array();
416  if ($flags != OCI_FETCHSTATEMENT_BY_ROW) { /* not Zend_Db::FETCH_OBJ */
417  if (! ($rows = oci_fetch_all($this->_stmt, $result, 0, -1, $flags) )) {
418  if ($error = oci_error($this->_stmt)) {
422  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
423  throw new Zend_Db_Statement_Oracle_Exception($error);
424  }
425  if (!$rows) {
426  return array();
427  }
428  }
429  if ($style == Zend_Db::FETCH_COLUMN) {
430  $result = $result[$col];
431  }
432  foreach ($result as &$row) {
433  if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
434  unset($row['zend_db_rownum']);
435  }
436  }
437  } else {
438  while (($row = oci_fetch_object($this->_stmt)) !== false) {
439  $result [] = $row;
440  }
441  if ($error = oci_error($this->_stmt)) {
445  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
446  throw new Zend_Db_Statement_Oracle_Exception($error);
447  }
448  }
449 
450  return $result;
451  }
const FETCH_ASSOC
Definition: Db.php:142
const FETCH_COLUMN
Definition: Db.php:147
const FETCH_BOTH
Definition: Db.php:143
const FETCH_NUM
Definition: Db.php:153
const FETCH_OBJ
Definition: Db.php:154

◆ fetchColumn()

fetchColumn (   $col = 0)

Returns a single column from the next row of a result set.

Parameters
int$colOPTIONAL Position of the column to fetch.
Returns
string
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 461 of file Oracle.php.

462  {
463  if (!$this->_stmt) {
464  return false;
465  }
466 
467  if (!oci_fetch($this->_stmt)) {
468  // if no error, there is simply no record
469  if (!$error = oci_error($this->_stmt)) {
470  return false;
471  }
475  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
476  throw new Zend_Db_Statement_Oracle_Exception($error);
477  }
478 
479  $data = oci_result($this->_stmt, $col+1); //1-based
480  if ($data === false) {
484  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
485  throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
486  }
487 
488  if ($this->getLobAsString()) {
489  // instanceof doesn't allow '-', we must use a temporary string
490  $type = 'OCI-Lob';
491  if ($data instanceof $type) {
492  $data = $data->read($data->size());
493  }
494  }
495 
496  return $data;
497  }
$type
Definition: item.phtml:13

◆ fetchObject()

fetchObject (   $class = 'stdClass',
array  $config = array() 
)

Fetches the next row and returns it as an object.

Parameters
string$classOPTIONAL Name of the class to create.
array$configOPTIONAL Constructor arguments for the class.
Returns
mixed One object instance of the specified class.
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 507 of file Oracle.php.

508  {
509  if (!$this->_stmt) {
510  return false;
511  }
512 
513  $obj = oci_fetch_object($this->_stmt);
514 
515  if ($error = oci_error($this->_stmt)) {
519  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
520  throw new Zend_Db_Statement_Oracle_Exception($error);
521  }
522 
523  /* @todo XXX handle parameters */
524 
525  return $obj;
526  }

◆ getLobAsString()

getLobAsString ( )

Return whether or not LOB are returned as string

Returns
boolean

Definition at line 75 of file Oracle.php.

76  {
77  return $this->_lobAsString;
78  }

◆ nextRowset()

nextRowset ( )

Retrieves the next rowset (result set) for a SQL statement that has multiple result sets. An example is a stored procedure that returns the results of multiple queries.

Returns
bool
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Statement_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 536 of file Oracle.php.

537  {
541  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
543  array(
544  'code' => 'HYC00',
545  'message' => 'Optional feature not implemented'
546  )
547  );
548  }

◆ rowCount()

rowCount ( )

Returns the number of rows affected by the execution of the last INSERT, DELETE, or UPDATE statement executed by this statement object.

Returns
int The number of rows affected.
Exceptions
Zend_Db_Statement_Exception
See also
Zend_Db_Adapter_Oracle_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 558 of file Oracle.php.

559  {
560  if (!$this->_stmt) {
561  return false;
562  }
563 
564  $num_rows = oci_num_rows($this->_stmt);
565 
566  if ($num_rows === false) {
570  #require_once 'Zend/Db/Statement/Oracle/Exception.php';
571  throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
572  }
573 
574  return $num_rows;
575  }

◆ setLobAsString()

setLobAsString (   $lob_as_string)

Activate/deactivate return of LOB as string

Parameters
string$lob_as_string
Returns
Zend_Db_Statement_Oracle

Definition at line 64 of file Oracle.php.

65  {
66  $this->_lobAsString = (bool) $lob_as_string;
67  return $this;
68  }

Field Documentation

◆ $_keys

$_keys
protected

Column names.

Definition at line 43 of file Oracle.php.

◆ $_lobAsString

$_lobAsString = false
protected

Definition at line 56 of file Oracle.php.

◆ $_values

$_values
protected

Fetched result values.

Definition at line 48 of file Oracle.php.


The documentation for this class was generated from the following file: