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

Public Member Functions

 isConnected ()
 
 closeConnection ()
 
 setLobAsString ($lobAsString)
 
 getLobAsString ()
 
 prepare ($sql)
 
 quoteTableAs ($ident, $alias=null, $auto=false)
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 _getExecuteMode ()
 
 supportsParameters ($type)
 
 getServerVersion ()
 
- Public Member Functions inherited from Zend_Db_Adapter_Abstract
 __construct ($config)
 
 getConnection ()
 
 getConfig ()
 
 setProfiler ($profiler)
 
 getProfiler ()
 
 getStatementClass ()
 
 setStatementClass ($class)
 
 query ($sql, $bind=array())
 
 beginTransaction ()
 
 commit ()
 
 rollBack ()
 
 insert ($table, array $bind)
 
 update ($table, array $bind, $where='')
 
 delete ($table, $where='')
 
 select ()
 
 getFetchMode ()
 
 fetchAll ($sql, $bind=array(), $fetchMode=null)
 
 fetchRow ($sql, $bind=array(), $fetchMode=null)
 
 fetchAssoc ($sql, $bind=array())
 
 fetchCol ($sql, $bind=array())
 
 fetchPairs ($sql, $bind=array())
 
 fetchOne ($sql, $bind=array())
 
 quote ($value, $type=null)
 
 quoteInto ($text, $value, $type=null, $count=null)
 
 quoteIdentifier ($ident, $auto=false)
 
 quoteColumnAs ($ident, $alias, $auto=false)
 
 quoteTableAs ($ident, $alias=null, $auto=false)
 
 getQuoteIdentifierSymbol ()
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 foldCase ($key)
 
 __sleep ()
 
 __wakeup ()
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 supportsParameters ($type)
 
 getServerVersion ()
 

Protected Member Functions

 _connect ()
 
 _quote ($value)
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 
- Protected Member Functions inherited from Zend_Db_Adapter_Abstract
 _checkRequiredOptions (array $config)
 
 _whereExpr ($where)
 
 _quote ($value)
 
 _quoteIdentifierAs ($ident, $alias=null, $auto=false, $as=' AS ')
 
 _quoteIdentifier ($value, $auto=false)
 
 _connect ()
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 

Protected Attributes

 $_config
 
 $_numericDataTypes
 
 $_execute_mode = null
 
 $_defaultStmtClass = 'Zend_Db_Statement_Oracle'
 
 $_lobAsString = null
 
- Protected Attributes inherited from Zend_Db_Adapter_Abstract
 $_config = array()
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_profiler
 
 $_defaultStmtClass = 'Zend_Db_Statement'
 
 $_defaultProfilerClass = 'Zend_Db_Profiler'
 
 $_connection = null
 
 $_caseFolding = Zend_Db::CASE_NATURAL
 
 $_autoQuoteIdentifiers = true
 
 $_numericDataTypes
 
 $_allowSerialization = true
 
 $_autoReconnectOnUnserialize = false
 

Detailed Description

Definition at line 40 of file Oracle.php.

Member Function Documentation

◆ _beginTransaction()

_beginTransaction ( )
protected

Leave autocommit mode and begin a transaction.

Returns
void

Definition at line 454 of file Oracle.php.

455  {
456  $this->_setExecuteMode(OCI_DEFAULT);
457  }

◆ _commit()

_commit ( )
protected

Commit a transaction and return to autocommit mode.

Returns
void
Exceptions
Zend_Db_Adapter_Oracle_Exception
See also
Zend_Db_Adapter_Oracle_Exception

Definition at line 465 of file Oracle.php.

466  {
467  if (!oci_commit($this->_connection)) {
471  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
472  throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));
473  }
474  $this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
475  }

◆ _connect()

_connect ( )
protected

Creates a connection resource.

Returns
void
Exceptions
Zend_Db_Adapter_Oracle_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Definition at line 107 of file Oracle.php.

108  {
109  if (is_resource($this->_connection)) {
110  // connection already exists
111  return;
112  }
113 
114  if (!extension_loaded('oci8')) {
118  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
119  throw new Zend_Db_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but the extension is not loaded');
120  }
121 
122  $this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
123 
124  $connectionFuncName = ($this->_config['persistent'] == true) ? 'oci_pconnect' : 'oci_connect';
125 
126  $this->_connection = @$connectionFuncName(
127  $this->_config['username'],
128  $this->_config['password'],
129  $this->_config['dbname'],
130  $this->_config['charset']);
131 
132  // check the connection
133  if (!$this->_connection) {
137  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
138  throw new Zend_Db_Adapter_Oracle_Exception(oci_error());
139  }
140  }

◆ _getExecuteMode()

_getExecuteMode ( )
Returns
int

Definition at line 601 of file Oracle.php.

602  {
603  return $this->_execute_mode;
604  }

◆ _quote()

_quote (   $value)
protected

Quote a raw string.

Parameters
string$valueRaw string
Returns
string Quoted string

Definition at line 226 of file Oracle.php.

227  {
228  if (is_int($value) || is_float($value)) {
229  return $value;
230  }
231  $value = str_replace("'", "''", $value);
232  return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
233  }
$value
Definition: gender.phtml:16

◆ _rollBack()

_rollBack ( )
protected

Roll back a transaction and return to autocommit mode.

Returns
void
Exceptions
Zend_Db_Adapter_Oracle_Exception
See also
Zend_Db_Adapter_Oracle_Exception

Definition at line 483 of file Oracle.php.

484  {
485  if (!oci_rollback($this->_connection)) {
489  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
490  throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));
491  }
492  $this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
493  }

◆ closeConnection()

closeConnection ( )

Force the connection to close.

Returns
void

Definition at line 159 of file Oracle.php.

160  {
161  if ($this->isConnected()) {
162  oci_close($this->_connection);
163  }
164  $this->_connection = null;
165  }

◆ describeTable()

describeTable (   $tableName,
  $schemaName = null 
)

Returns the column descriptions for a table.

The return value is an associative array keyed by the column name, as returned by the RDBMS.

The value of each array element is an associative array with the following keys:

SCHEMA_NAME => string; name of schema TABLE_NAME => string; COLUMN_NAME => string; column name COLUMN_POSITION => number; ordinal position of column in table DATA_TYPE => string; SQL datatype name of column DEFAULT => string; default expression of column, null if none NULLABLE => boolean; true if column can have nulls LENGTH => number; length of CHAR/VARCHAR SCALE => number; scale of NUMERIC/DECIMAL PRECISION => number; precision of NUMERIC/DECIMAL UNSIGNED => boolean; unsigned property of an integer type PRIMARY => boolean; true if column is part of the primary key PRIMARY_POSITION => integer; position of column in primary key IDENTITY => integer; true if column is auto-generated with unique values

Todo:
Discover integer unsigned property.
Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array

Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection

Oracle does not support auto-increment keys.

Definition at line 355 of file Oracle.php.

356  {
357  $version = $this->getServerVersion();
358  if (($version === null) || version_compare($version, '9.0.0', '>=')) {
359  $sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
360  TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
361  TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
362  FROM ALL_TAB_COLUMNS TC
363  LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
364  ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P'))
365  ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
366  WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
367  $bind[':TBNAME'] = $tableName;
368  if ($schemaName) {
369  $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
370  $bind[':SCNAME'] = $schemaName;
371  }
372  $sql .= ' ORDER BY TC.COLUMN_ID';
373  } else {
374  $subSql="SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION
375  from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC
376  WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
377  AND ACC.TABLE_NAME = AC.TABLE_NAME
378  AND ACC.OWNER = AC.OWNER
379  AND AC.CONSTRAINT_TYPE = 'P'
380  AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
381  $bind[':TBNAME'] = $tableName;
382  if ($schemaName) {
383  $subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
384  $bind[':SCNAME'] = $schemaName;
385  }
386  $sql="SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
387  TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
388  TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION
389  FROM ALL_TAB_COLUMNS TC, ($subSql) CC
390  WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)
391  AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
392  if ($schemaName) {
393  $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
394  }
395  $sql .= ' ORDER BY TC.COLUMN_ID';
396  }
397 
398  $stmt = $this->query($sql, $bind);
399 
403  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
404 
405  $table_name = 0;
406  $owner = 1;
407  $column_name = 2;
408  $data_type = 3;
409  $data_default = 4;
410  $nullable = 5;
411  $column_id = 6;
412  $data_length = 7;
413  $data_scale = 8;
414  $data_precision = 9;
415  $constraint_type = 10;
416  $position = 11;
417 
418  $desc = array();
419  foreach ($result as $key => $row) {
420  list ($primary, $primaryPosition, $identity) = array(false, null, false);
421  if ($row[$constraint_type] == 'P') {
422  $primary = true;
423  $primaryPosition = $row[$position];
427  $identity = false;
428  }
429  $desc[$this->foldCase($row[$column_name])] = array(
430  'SCHEMA_NAME' => $this->foldCase($row[$owner]),
431  'TABLE_NAME' => $this->foldCase($row[$table_name]),
432  'COLUMN_NAME' => $this->foldCase($row[$column_name]),
433  'COLUMN_POSITION' => $row[$column_id],
434  'DATA_TYPE' => $row[$data_type],
435  'DEFAULT' => $row[$data_default],
436  'NULLABLE' => (bool) ($row[$nullable] == 'Y'),
437  'LENGTH' => $row[$data_length],
438  'SCALE' => $row[$data_scale],
439  'PRECISION' => $row[$data_precision],
440  'UNSIGNED' => null, // @todo
441  'PRIMARY' => $primary,
442  'PRIMARY_POSITION' => $primaryPosition,
443  'IDENTITY' => $identity
444  );
445  }
446  return $desc;
447  }
$tableName
Definition: trigger.php:13
const FETCH_NUM
Definition: Db.php:153
query($sql, $bind=array())
Definition: Abstract.php:457

◆ getLobAsString()

getLobAsString ( )

Return whether or not LOB are returned as string

Returns
boolean

Definition at line 184 of file Oracle.php.

185  {
186  if ($this->_lobAsString === null) {
187  // if never set by user, we use driver option if it exists otherwise false
188  if (isset($this->_config['driver_options']) &&
189  isset($this->_config['driver_options']['lob_as_string'])) {
190  $this->_lobAsString = (bool) $this->_config['driver_options']['lob_as_string'];
191  } else {
192  $this->_lobAsString = false;
193  }
194  }
195  return $this->_lobAsString;
196  }

◆ getServerVersion()

getServerVersion ( )

Retrieve server version in PHP style

Returns
string

Definition at line 628 of file Oracle.php.

629  {
630  $this->_connect();
631  $version = oci_server_version($this->_connection);
632  if ($version !== false) {
633  $matches = null;
634  if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
635  return $matches[1];
636  } else {
637  return null;
638  }
639  } else {
640  return null;
641  }
642  }

◆ isConnected()

isConnected ( )

Test if a connection is active

Returns
boolean

Definition at line 147 of file Oracle.php.

148  {
149  return ((bool) (is_resource($this->_connection)
150  && (get_resource_type($this->_connection) == 'oci8 connection'
151  || get_resource_type($this->_connection) == 'oci8 persistent connection')));
152  }

◆ lastInsertId()

lastInsertId (   $tableName = null,
  $primaryKey = null 
)

Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.

As a convention, on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence from the arguments and returns the last id generated by that sequence. On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method returns the last value generated for such a column, and the table name argument is disregarded.

Oracle does not support IDENTITY columns, so if the sequence is not specified, this method returns null.

Parameters
string$tableNameOPTIONAL Name of table.
string$primaryKeyOPTIONAL Name of primary key column.
Returns
string

Definition at line 298 of file Oracle.php.

299  {
300  if ($tableName !== null) {
301  $sequenceName = $tableName;
302  if ($primaryKey) {
303  $sequenceName .= "_$primaryKey";
304  }
305  $sequenceName .= '_seq';
306  return $this->lastSequenceId($sequenceName);
307  }
308 
309  // No support for IDENTITY columns; return null
310  return null;
311  }
$tableName
Definition: trigger.php:13
lastSequenceId($sequenceName)
Definition: Oracle.php:257

◆ lastSequenceId()

lastSequenceId (   $sequenceName)

Return the most recent value from the specified sequence in the database. This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.

Parameters
string$sequenceName
Returns
string

Definition at line 257 of file Oracle.php.

258  {
259  $this->_connect();
260  $sql = 'SELECT '.$this->quoteIdentifier($sequenceName, true).'.CURRVAL FROM dual';
261  $value = $this->fetchOne($sql);
262  return $value;
263  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16

◆ limit()

limit (   $sql,
  $count,
  $offset = 0 
)

Adds an adapter-specific LIMIT clause to the SELECT statement.

Parameters
string$sql
integer$count
integer$offsetOPTIONAL
Returns
string
Exceptions
Zend_Db_Adapter_Oracle_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Oracle does not implement the LIMIT clause as some RDBMS do. We have to simulate it with subqueries and ROWNUM. Unfortunately because we use the column wildcard "*", this puts an extra column into the query result set.

Definition at line 539 of file Oracle.php.

540  {
541  $count = intval($count);
542  if ($count <= 0) {
546  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
547  throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument count=$count is not valid");
548  }
549 
550  $offset = intval($offset);
551  if ($offset < 0) {
555  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
556  throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument offset=$offset is not valid");
557  }
558 
565  $limit_sql = "SELECT z2.*
566  FROM (
567  SELECT z1.*, ROWNUM AS \"zend_db_rownum\"
568  FROM (
569  " . $sql . "
570  ) z1
571  ) z2
572  WHERE z2.\"zend_db_rownum\" BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
573  return $limit_sql;
574  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 318 of file Oracle.php.

319  {
320  $this->_connect();
321  $data = $this->fetchCol('SELECT table_name FROM all_tables');
322  return $data;
323  }
fetchCol($sql, $bind=array())
Definition: Abstract.php:792

◆ nextSequenceId()

nextSequenceId (   $sequenceName)

Generate a new value from the specified sequence in the database, and return it. This is supported only on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.

Parameters
string$sequenceName
Returns
string

Definition at line 273 of file Oracle.php.

274  {
275  $this->_connect();
276  $sql = 'SELECT '.$this->quoteIdentifier($sequenceName, true).'.NEXTVAL FROM dual';
277  $value = $this->fetchOne($sql);
278  return $value;
279  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16

◆ prepare()

prepare (   $sql)

Returns an SQL statement for preparation.

Parameters
string$sqlThe SQL statement with placeholders.
Returns
Zend_Db_Statement_Oracle

Definition at line 204 of file Oracle.php.

205  {
206  $this->_connect();
207  $stmtClass = $this->_defaultStmtClass;
208  if (!class_exists($stmtClass)) {
209  #require_once 'Zend/Loader.php';
210  Zend_Loader::loadClass($stmtClass);
211  }
212  $stmt = new $stmtClass($this, $sql);
213  if ($stmt instanceof Zend_Db_Statement_Oracle) {
214  $stmt->setLobAsString($this->getLobAsString());
215  }
216  $stmt->setFetchMode($this->_fetchMode);
217  return $stmt;
218  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52

◆ quoteTableAs()

quoteTableAs (   $ident,
  $alias = null,
  $auto = false 
)

Quote a table identifier and alias.

Parameters
string | array | Zend_Db_Expr$identThe identifier or expression.
string$aliasAn alias for the table.
boolean$autoIf true, heed the AUTO_QUOTE_IDENTIFIERS config option.
Returns
string The quoted identifier and alias.

Definition at line 243 of file Oracle.php.

244  {
245  // Oracle doesn't allow the 'AS' keyword between the table identifier/expression and alias.
246  return $this->_quoteIdentifierAs($ident, $alias, $auto, ' ');
247  }
_quoteIdentifierAs($ident, $alias=null, $auto=false, $as=' AS ')
Definition: Abstract.php:999
if(!trim($html)) $alias
Definition: details.phtml:20

◆ setFetchMode()

setFetchMode (   $mode)

Set the fetch mode.

Todo:
Support FETCH_CLASS and FETCH_INTO.
Parameters
integer$modeA fetch mode.
Returns
void
Exceptions
Zend_Db_Adapter_Oracle_Exception
See also
Zend_Db_Adapter_Oracle_Exception
Zend_Db_Adapter_Oracle_Exception

Definition at line 504 of file Oracle.php.

505  {
506  switch ($mode) {
507  case Zend_Db::FETCH_NUM: // seq array
508  case Zend_Db::FETCH_ASSOC: // assoc array
509  case Zend_Db::FETCH_BOTH: // seq+assoc array
510  case Zend_Db::FETCH_OBJ: // object
511  $this->_fetchMode = $mode;
512  break;
513  case Zend_Db::FETCH_BOUND: // bound to PHP variable
517  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
518  throw new Zend_Db_Adapter_Oracle_Exception('FETCH_BOUND is not supported yet');
519  break;
520  default:
524  #require_once 'Zend/Db/Adapter/Oracle/Exception.php';
525  throw new Zend_Db_Adapter_Oracle_Exception("Invalid fetch mode '$mode' specified");
526  break;
527  }
528  }
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
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
const FETCH_OBJ
Definition: Db.php:154

◆ setLobAsString()

setLobAsString (   $lobAsString)

Activate/deactivate return of LOB as string

Parameters
string$lob_as_string
Returns
Zend_Db_Adapter_Oracle

Definition at line 173 of file Oracle.php.

174  {
175  $this->_lobAsString = (bool) $lobAsString;
176  return $this;
177  }

◆ supportsParameters()

supportsParameters (   $type)

Check if the adapter supports real SQL parameters.

Parameters
string$type'positional' or 'named'
Returns
bool

Definition at line 612 of file Oracle.php.

613  {
614  switch ($type) {
615  case 'named':
616  return true;
617  case 'positional':
618  default:
619  return false;
620  }
621  }
$type
Definition: item.phtml:13

Field Documentation

◆ $_config

$_config
protected
Initial value:
= array(
'dbname' => null,
'username' => null,
'password' => null,
'persistent' => false
)

Definition at line 54 of file Oracle.php.

◆ $_defaultStmtClass

$_defaultStmtClass = 'Zend_Db_Statement_Oracle'
protected

Definition at line 91 of file Oracle.php.

◆ $_execute_mode

$_execute_mode = null
protected

Definition at line 84 of file Oracle.php.

◆ $_lobAsString

$_lobAsString = null
protected

Definition at line 99 of file Oracle.php.

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 72 of file Oracle.php.


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