Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Adapter_Pdo_Oci Class Reference
Inheritance diagram for Zend_Db_Adapter_Pdo_Oci:
Zend_Db_Adapter_Pdo_Abstract Zend_Db_Adapter_Abstract

Public Member Functions

 quoteTableAs ($ident, $alias=null, $auto=false)
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 limit ($sql, $count, $offset=0)
 
- Public Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 query ($sql, $bind=array())
 
 exec ($sql)
 
 setFetchMode ($mode)
 
 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

 _dsn ()
 
 _quote ($value)
 
- Protected Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 _dsn ()
 
 _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

 $_pdoType = 'oci'
 
 $_defaultStmtClass = 'Zend_Db_Statement_Pdo_Oci'
 
 $_numericDataTypes
 
- Protected Attributes inherited from Zend_Db_Adapter_Pdo_Abstract
 $_defaultStmtClass = 'Zend_Db_Statement_Pdo'
 
- 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 39 of file Oci.php.

Member Function Documentation

◆ _dsn()

_dsn ( )
protected

Creates a PDO DSN for the adapter from $this->_config settings.

Returns
string

Definition at line 81 of file Oci.php.

82  {
83  // baseline of DSN parts
84  $dsn = $this->_config;
85 
86  if (isset($dsn['host'])) {
87  $tns = 'dbname=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
88  '(HOST=' . $dsn['host'] . ')';
89 
90  if (isset($dsn['port'])) {
91  $tns .= '(PORT=' . $dsn['port'] . ')';
92  } else {
93  $tns .= '(PORT=1521)';
94  }
95 
96  $tns .= '))(CONNECT_DATA=(SID=' . $dsn['dbname'] . ')))';
97  } else {
98  $tns = 'dbname=' . $dsn['dbname'];
99  }
100 
101  if (isset($dsn['charset'])) {
102  $tns .= ';charset=' . $dsn['charset'];
103  }
104 
105  return $this->_pdoType . ':' . $tns;
106  }

◆ _quote()

_quote (   $value)
protected

Quote a raw string. Most PDO drivers have an implementation for the quote() method, but the Oracle OCI driver must use the same implementation as the Zend_Db_Adapter_Abstract class.

Parameters
string$valueRaw string
Returns
string Quoted string

Definition at line 117 of file Oci.php.

118  {
119  if (is_int($value) || is_float($value)) {
120  return $value;
121  }
122  $value = str_replace("'", "''", $value);
123  return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
124  }
$value
Definition: gender.phtml:16

◆ 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 180 of file Oci.php.

181  {
182  $version = $this->getServerVersion();
183  if (($version === null) || version_compare($version, '9.0.0', '>=')) {
184  $sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
185  TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
186  TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
187  FROM ALL_TAB_COLUMNS TC
188  LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
189  ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P'))
190  ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
191  WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
192  $bind[':TBNAME'] = $tableName;
193  if ($schemaName) {
194  $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
195  $bind[':SCNAME'] = $schemaName;
196  }
197  $sql .= ' ORDER BY TC.COLUMN_ID';
198  } else {
199  $subSql="SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION
200  from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC
201  WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
202  AND ACC.TABLE_NAME = AC.TABLE_NAME
203  AND ACC.OWNER = AC.OWNER
204  AND AC.CONSTRAINT_TYPE = 'P'
205  AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
206  $bind[':TBNAME'] = $tableName;
207  if ($schemaName) {
208  $subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
209  $bind[':SCNAME'] = $schemaName;
210  }
211  $sql="SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
212  TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
213  TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION
214  FROM ALL_TAB_COLUMNS TC, ($subSql) CC
215  WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)
216  AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
217  if ($schemaName) {
218  $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
219  }
220  $sql .= ' ORDER BY TC.COLUMN_ID';
221  }
222 
223  $stmt = $this->query($sql, $bind);
224 
228  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
229 
230  $table_name = 0;
231  $owner = 1;
232  $column_name = 2;
233  $data_type = 3;
234  $data_default = 4;
235  $nullable = 5;
236  $column_id = 6;
237  $data_length = 7;
238  $data_scale = 8;
239  $data_precision = 9;
240  $constraint_type = 10;
241  $position = 11;
242 
243  $desc = array();
244  foreach ($result as $key => $row) {
245  list ($primary, $primaryPosition, $identity) = array(false, null, false);
246  if ($row[$constraint_type] == 'P') {
247  $primary = true;
248  $primaryPosition = $row[$position];
252  $identity = false;
253  }
254  $desc[$this->foldCase($row[$column_name])] = array(
255  'SCHEMA_NAME' => $this->foldCase($row[$owner]),
256  'TABLE_NAME' => $this->foldCase($row[$table_name]),
257  'COLUMN_NAME' => $this->foldCase($row[$column_name]),
258  'COLUMN_POSITION' => $row[$column_id],
259  'DATA_TYPE' => $row[$data_type],
260  'DEFAULT' => $row[$data_default],
261  'NULLABLE' => (bool) ($row[$nullable] == 'Y'),
262  'LENGTH' => $row[$data_length],
263  'SCALE' => $row[$data_scale],
264  'PRECISION' => $row[$data_precision],
265  'UNSIGNED' => null, // @todo
266  'PRIMARY' => $primary,
267  'PRIMARY_POSITION' => $primaryPosition,
268  'IDENTITY' => $identity
269  );
270  }
271  return $desc;
272  }
$tableName
Definition: trigger.php:13
const FETCH_NUM
Definition: Db.php:153
query($sql, $bind=array())
Definition: Abstract.php:221

◆ 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
Exceptions
Zend_Db_Adapter_Oracle_Exception

Definition at line 322 of file Oci.php.

323  {
324  if ($tableName !== null) {
325  $sequenceName = $tableName;
326  if ($primaryKey) {
327  $sequenceName .= $this->foldCase("_$primaryKey");
328  }
329  $sequenceName .= $this->foldCase('_seq');
330  return $this->lastSequenceId($sequenceName);
331  }
332  // No support for IDENTITY columns; return null
333  return null;
334  }
$tableName
Definition: trigger.php:13
lastSequenceId($sequenceName)
Definition: Oci.php:282

◆ 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
integer

Definition at line 282 of file Oci.php.

283  {
284  $this->_connect();
285  $value = $this->fetchOne('SELECT '.$this->quoteIdentifier($sequenceName, true).'.CURRVAL FROM dual');
286  return $value;
287  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959

◆ limit()

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

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

Parameters
string$sql
integer$count
integer$offset
Exceptions
Zend_Db_Adapter_Exception
Returns
string
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_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 345 of file Oci.php.

346  {
347  $count = intval($count);
348  if ($count <= 0) {
350  #require_once 'Zend/Db/Adapter/Exception.php';
351  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
352  }
353 
354  $offset = intval($offset);
355  if ($offset < 0) {
357  #require_once 'Zend/Db/Adapter/Exception.php';
358  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
359  }
360 
367  $limit_sql = "SELECT z2.*
368  FROM (
369  SELECT z1.*, ROWNUM AS \"zend_db_rownum\"
370  FROM (
371  " . $sql . "
372  ) z1
373  ) z2
374  WHERE z2.\"zend_db_rownum\" BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
375  return $limit_sql;
376  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 144 of file Oci.php.

145  {
146  $data = $this->fetchCol('SELECT table_name FROM all_tables');
147  return $data;
148  }
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
integer

Definition at line 297 of file Oci.php.

298  {
299  $this->_connect();
300  $value = $this->fetchOne('SELECT '.$this->quoteIdentifier($sequenceName, true).'.NEXTVAL FROM dual');
301  return $value;
302  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959

◆ 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.
Returns
string The quoted identifier and alias.

Definition at line 133 of file Oci.php.

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

Field Documentation

◆ $_defaultStmtClass

$_defaultStmtClass = 'Zend_Db_Statement_Pdo_Oci'
protected

Definition at line 54 of file Oci.php.

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 67 of file Oci.php.

◆ $_pdoType

$_pdoType = 'oci'
protected

Definition at line 47 of file Oci.php.


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