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_Db2 Class Reference
Inheritance diagram for Zend_Db_Adapter_Db2:
Zend_Db_Adapter_Abstract

Public Member Functions

 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 _getExecuteMode ()
 
 _setExecuteMode ($mode)
 
 getQuoteIdentifierSymbol ()
 
 listTables ($schema=null)
 
 describeTable ($tableName, $schemaName=null)
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 lastInsertId ($tableName=null, $primaryKey=null, $idType=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 supportsParameters ($type)
 
 getServerVersion ()
 
 isI5 ()
 
- 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 ()
 
 _determineI5 ()
 
 _i5listTables ($schema=null)
 
 _i5LastInsertId ($objectName=null, $idType=null)
 
- 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
 
 $_execute_mode = DB2_AUTOCOMMIT_ON
 
 $_defaultStmtClass = 'Zend_Db_Statement_Db2'
 
 $_isI5 = false
 
 $_numericDataTypes
 
- 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 46 of file Db2.php.

Member Function Documentation

◆ _beginTransaction()

_beginTransaction ( )
protected

Begin a transaction.

Returns
void

Definition at line 578 of file Db2.php.

579  {
580  $this->_setExecuteMode(DB2_AUTOCOMMIT_OFF);
581  }
_setExecuteMode($mode)
Definition: Db2.php:257

◆ _commit()

_commit ( )
protected

Commit a transaction.

Returns
void
See also
Zend_Db_Adapter_Db2_Exception

Definition at line 588 of file Db2.php.

589  {
590  if (!db2_commit($this->_connection)) {
594  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
596  db2_conn_errormsg($this->_connection),
597  db2_conn_error($this->_connection));
598  }
599 
600  $this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
601  }
_setExecuteMode($mode)
Definition: Db2.php:257

◆ _connect()

_connect ( )
protected

Creates a connection resource.

Returns
void
See also
Zend_Db_Adapter_Db2_Exception
Zend_Db_Adapter_Db2_Exception

Definition at line 119 of file Db2.php.

120  {
121  if (is_resource($this->_connection)) {
122  // connection already exists
123  return;
124  }
125 
126  if (!extension_loaded('ibm_db2')) {
130  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
131  throw new Zend_Db_Adapter_Db2_Exception('The IBM DB2 extension is required for this adapter but the extension is not loaded');
132  }
133 
134  $this->_determineI5();
135  if ($this->_config['persistent']) {
136  // use persistent connection
137  $conn_func_name = 'db2_pconnect';
138  } else {
139  // use "normal" connection
140  $conn_func_name = 'db2_connect';
141  }
142 
143  if (!isset($this->_config['driver_options']['autocommit'])) {
144  // set execution mode
145  $this->_config['driver_options']['autocommit'] = &$this->_execute_mode;
146  }
147 
148  if (isset($this->_config['options'][Zend_Db::CASE_FOLDING])) {
149  $caseAttrMap = array(
150  Zend_Db::CASE_NATURAL => DB2_CASE_NATURAL,
151  Zend_Db::CASE_UPPER => DB2_CASE_UPPER,
152  Zend_Db::CASE_LOWER => DB2_CASE_LOWER
153  );
154  $this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]];
155  }
156 
157  if ($this->_isI5 && isset($this->_config['driver_options']['i5_naming'])) {
158  if ($this->_config['driver_options']['i5_naming']) {
159  $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_ON;
160  } else {
161  $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_OFF;
162  }
163  }
164 
165  if ($this->_config['host'] !== 'localhost' && !$this->_isI5) {
166  // if the host isn't localhost, use extended connection params
167  $dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
168  ';DATABASE=' . $this->_config['dbname'] .
169  ';HOSTNAME=' . $this->_config['host'] .
170  ';PORT=' . $this->_config['port'] .
171  ';PROTOCOL=' . $this->_config['protocol'] .
172  ';UID=' . $this->_config['username'] .
173  ';PWD=' . $this->_config['password'] .';';
174  $this->_connection = $conn_func_name(
175  $dbname,
176  null,
177  null,
178  $this->_config['driver_options']
179  );
180  } else {
181  // host is localhost, so use standard connection params
182  $this->_connection = $conn_func_name(
183  $this->_config['dbname'],
184  $this->_config['username'],
185  $this->_config['password'],
186  $this->_config['driver_options']
187  );
188  }
189 
190  // check the connection
191  if (!$this->_connection) {
195  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
196  throw new Zend_Db_Adapter_Db2_Exception(db2_conn_errormsg(), db2_conn_error());
197  }
198  }
const CASE_UPPER
Definition: Db.php:125
const CASE_NATURAL
Definition: Db.php:124
const CASE_FOLDING
Definition: Db.php:43
const CASE_LOWER
Definition: Db.php:123

◆ _determineI5()

_determineI5 ( )
protected

Check the connection parameters according to verify type of used OS

Returns
void

Definition at line 761 of file Db2.php.

762  {
763  // first us the compiled flag.
764  $this->_isI5 = (php_uname('s') == 'OS400') ? true : false;
765 
766  // if this is set, then us it
767  if (isset($this->_config['os'])){
768  if (strtolower($this->_config['os']) === 'i5') {
769  $this->_isI5 = true;
770  } else {
771  // any other value passed in, its null
772  $this->_isI5 = false;
773  }
774  }
775 
776  }

◆ _getExecuteMode()

_getExecuteMode ( )

Gets the execution mode

Returns
int the execution mode (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)

Definition at line 248 of file Db2.php.

249  {
250  return $this->_execute_mode;
251  }

◆ _i5LastInsertId()

_i5LastInsertId (   $objectName = null,
  $idType = null 
)
protected

Definition at line 817 of file Db2.php.

818  {
819 
820  if ($objectName === null) {
821  $sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM QSYS2.QSQPTABL';
822  $value = $this->fetchOne($sql);
823  return $value;
824  }
825 
826  if (strtoupper($idType) === 'S'){
827  //check i5_lib option
828  $sequenceName = $objectName;
829  return $this->lastSequenceId($sequenceName);
830  }
831 
832  //returns last identity value for the specified table
833  //if (strtoupper($idType) === 'I') {
834  $tableName = $objectName;
835  return $this->fetchOne('SELECT IDENTITY_VAL_LOCAL() from ' . $this->quoteIdentifier($tableName));
836  }
$tableName
Definition: trigger.php:13
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16
lastSequenceId($sequenceName)
Definition: Db2.php:500
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959

◆ _i5listTables()

_i5listTables (   $schema = null)
protected

Db2 On I5 specific method

Returns a list of the tables in the database . Used only for DB2/400.

Returns
array

Definition at line 786 of file Db2.php.

787  {
788  //list of i5 libraries.
789  $tables = array();
790  if ($schema) {
791  $tablesStatement = db2_tables($this->_connection, null, $schema);
792  while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
793  if ($rowTables['TABLE_NAME'] !== null) {
794  $tables[] = $rowTables['TABLE_NAME'];
795  }
796  }
797  } else {
798  $schemaStatement = db2_tables($this->_connection);
799  while ($schema = db2_fetch_assoc($schemaStatement)) {
800  if ($schema['TABLE_SCHEM'] !== null) {
801  // list of the tables which belongs to the selected library
802  $tablesStatement = db2_tables($this->_connection, NULL, $schema['TABLE_SCHEM']);
803  if (is_resource($tablesStatement)) {
804  while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
805  if ($rowTables['TABLE_NAME'] !== null) {
806  $tables[] = $rowTables['TABLE_NAME'];
807  }
808  }
809  }
810  }
811  }
812  }
813 
814  return $tables;
815  }

◆ _quote()

_quote (   $value)
protected

Quote a raw string.

Parameters
string$valueRaw string
Returns
string Quoted string

Use db2_escape_string() if it is present in the IBM DB2 extension. But some supported versions of PHP do not include this function, so fall back to default quoting in the parent class.

Definition at line 281 of file Db2.php.

282  {
283  if (is_int($value) || is_float($value)) {
284  return $value;
285  }
291  if (function_exists('db2_escape_string')) {
292  return "'" . db2_escape_string($value) . "'";
293  }
294  return parent::_quote($value);
295  }
$value
Definition: gender.phtml:16

◆ _rollBack()

_rollBack ( )
protected

Rollback a transaction.

Returns
void
See also
Zend_Db_Adapter_Db2_Exception

Definition at line 608 of file Db2.php.

609  {
610  if (!db2_rollback($this->_connection)) {
614  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
616  db2_conn_errormsg($this->_connection),
617  db2_conn_error($this->_connection));
618  }
619  $this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
620  }
_setExecuteMode($mode)
Definition: Db2.php:257

◆ _setExecuteMode()

_setExecuteMode (   $mode)
Parameters
integer$mode
Returns
void
See also
Zend_Db_Adapter_Db2_Exception

Definition at line 257 of file Db2.php.

258  {
259  switch ($mode) {
260  case DB2_AUTOCOMMIT_OFF:
261  case DB2_AUTOCOMMIT_ON:
262  $this->_execute_mode = $mode;
263  db2_autocommit($this->_connection, $mode);
264  break;
265  default:
269  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
270  throw new Zend_Db_Adapter_Db2_Exception("execution mode not supported");
271  break;
272  }
273  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

◆ closeConnection()

closeConnection ( )

Force the connection to close.

Returns
void

Definition at line 216 of file Db2.php.

217  {
218  if ($this->isConnected()) {
219  db2_close($this->_connection);
220  }
221  $this->_connection = null;
222  }

◆ 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 database or 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 DB2 not supports UNSIGNED integer. 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

Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array

To avoid case issues, fetch using FETCH_NUM

The ordering of columns is defined by the query so we can map to variables to improve readability

In IBM DB2, an column can be IDENTITY even if it is not part of the PRIMARY KEY.

Definition at line 376 of file Db2.php.

377  {
378  // Ensure the connection is made so that _isI5 is set
379  $this->_connect();
380 
381  if ($schemaName === null && $this->_config['schema'] != null) {
382  $schemaName = $this->_config['schema'];
383  }
384 
385  if (!$this->_isI5) {
386 
387  $sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
388  c.typename, c.default, c.nulls, c.length, c.scale,
389  c.identity, tc.type AS tabconsttype, k.colseq
390  FROM syscat.columns c
391  LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
392  ON (k.tabschema = tc.tabschema
393  AND k.tabname = tc.tabname
394  AND tc.type = 'P'))
395  ON (c.tabschema = k.tabschema
396  AND c.tabname = k.tabname
397  AND c.colname = k.colname)
398  WHERE "
399  . $this->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
400 
401  if ($schemaName) {
402  $sql .= $this->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
403  }
404 
405  $sql .= " ORDER BY c.colno";
406 
407  } else {
408 
409  // DB2 On I5 specific query
410  $sql = "SELECT DISTINCT C.TABLE_SCHEMA, C.TABLE_NAME, C.COLUMN_NAME, C.ORDINAL_POSITION,
411  C.DATA_TYPE, C.COLUMN_DEFAULT, C.NULLS ,C.LENGTH, C.SCALE, LEFT(C.IDENTITY,1),
412  LEFT(tc.TYPE, 1) AS tabconsttype, k.COLSEQ
413  FROM QSYS2.SYSCOLUMNS C
414  LEFT JOIN (QSYS2.syskeycst k JOIN QSYS2.SYSCST tc
415  ON (k.TABLE_SCHEMA = tc.TABLE_SCHEMA
416  AND k.TABLE_NAME = tc.TABLE_NAME
417  AND LEFT(tc.type,1) = 'P'))
418  ON (C.TABLE_SCHEMA = k.TABLE_SCHEMA
419  AND C.TABLE_NAME = k.TABLE_NAME
420  AND C.COLUMN_NAME = k.COLUMN_NAME)
421  WHERE "
422  . $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName);
423 
424  if ($schemaName) {
425  $sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
426  }
427 
428  $sql .= " ORDER BY C.ORDINAL_POSITION FOR FETCH ONLY";
429  }
430 
431  $desc = array();
432  $stmt = $this->query($sql);
433 
437  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
438 
443  $tabschema = 0;
444  $tabname = 1;
445  $colname = 2;
446  $colno = 3;
447  $typename = 4;
448  $default = 5;
449  $nulls = 6;
450  $length = 7;
451  $scale = 8;
452  $identityCol = 9;
453  $tabconstType = 10;
454  $colseq = 11;
455 
456  foreach ($result as $key => $row) {
457  list ($primary, $primaryPosition, $identity) = array(false, null, false);
458  if ($row[$tabconstType] == 'P') {
459  $primary = true;
460  $primaryPosition = $row[$colseq];
461  }
466  if ($row[$identityCol] == 'Y') {
467  $identity = true;
468  }
469 
470  // only colname needs to be case adjusted
471  $desc[$this->foldCase($row[$colname])] = array(
472  'SCHEMA_NAME' => $this->foldCase($row[$tabschema]),
473  'TABLE_NAME' => $this->foldCase($row[$tabname]),
474  'COLUMN_NAME' => $this->foldCase($row[$colname]),
475  'COLUMN_POSITION' => (!$this->_isI5) ? $row[$colno]+1 : $row[$colno],
476  'DATA_TYPE' => $row[$typename],
477  'DEFAULT' => $row[$default],
478  'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
479  'LENGTH' => $row[$length],
480  'SCALE' => $row[$scale],
481  'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
482  'UNSIGNED' => false,
483  'PRIMARY' => $primary,
484  'PRIMARY_POSITION' => $primaryPosition,
485  'IDENTITY' => $identity
486  );
487  }
488 
489  return $desc;
490  }
$tableName
Definition: trigger.php:13
const FETCH_NUM
Definition: Db.php:153
quoteInto($text, $value, $type=null, $count=null)
Definition: Abstract.php:928
query($sql, $bind=array())
Definition: Abstract.php:457

◆ getQuoteIdentifierSymbol()

getQuoteIdentifierSymbol ( )
Returns
string

Definition at line 300 of file Db2.php.

301  {
302  $this->_connect();
303  $info = db2_server_info($this->_connection);
304  if ($info) {
305  $identQuote = $info->IDENTIFIER_QUOTE_CHAR;
306  } else {
307  // db2_server_info() does not return result on some i5 OS version
308  if ($this->_isI5) {
309  $identQuote ="'";
310  }
311  }
312  return $identQuote;
313  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ getServerVersion()

getServerVersion ( )

Retrieve server version in PHP style

Returns
string

Definition at line 726 of file Db2.php.

727  {
728  $this->_connect();
729  $server_info = db2_server_info($this->_connection);
730  if ($server_info !== false) {
731  $version = $server_info->DBMS_VER;
732  if ($this->_isI5) {
733  $version = (int) substr($version, 0, 2) . '.' . (int) substr($version, 2, 2) . '.' . (int) substr($version, 4);
734  }
735  return $version;
736  } else {
737  return null;
738  }
739  }

◆ isConnected()

isConnected ( )

Test if a connection is active

Returns
boolean

Definition at line 205 of file Db2.php.

206  {
207  return ((bool) (is_resource($this->_connection)
208  && get_resource_type($this->_connection) == 'DB2 Connection'));
209  }

◆ isI5()

isI5 ( )

Return whether or not this is running on i5

Returns
bool

Definition at line 746 of file Db2.php.

747  {
748  if ($this->_isI5 === null) {
749  $this->_determineI5();
750  }
751 
752  return (bool) $this->_isI5;
753  }

◆ lastInsertId()

lastInsertId (   $tableName = null,
  $primaryKey = null,
  $idType = 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.

The IDENTITY_VAL_LOCAL() function gives the last generated identity value in the current process, even if it was for a GENERATED column.

Parameters
string$tableNameOPTIONAL
string$primaryKeyOPTIONAL
string$idTypeOPTIONAL used for i5 platform to define sequence/idenity unique value
Returns
string

Definition at line 551 of file Db2.php.

552  {
553  $this->_connect();
554 
555  if ($this->_isI5) {
556  return (string) $this->_i5LastInsertId($tableName, $idType);
557  }
558 
559  if ($tableName !== null) {
560  $sequenceName = $tableName;
561  if ($primaryKey) {
562  $sequenceName .= "_$primaryKey";
563  }
564  $sequenceName .= '_seq';
565  return $this->lastSequenceId($sequenceName);
566  }
567 
568  $sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1';
569  $value = $this->fetchOne($sql);
570  return (string) $value;
571  }
$tableName
Definition: trigger.php:13
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
$value
Definition: gender.phtml:16
lastSequenceId($sequenceName)
Definition: Db2.php:500
_i5LastInsertId($objectName=null, $idType=null)
Definition: Db2.php:817

◆ 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 500 of file Db2.php.

501  {
502  $this->_connect();
503 
504  if (!$this->_isI5) {
505  $quotedSequenceName = $this->quoteIdentifier($sequenceName, true);
506  $sql = 'SELECT PREVVAL FOR ' . $quotedSequenceName . ' AS VAL FROM SYSIBM.SYSDUMMY1';
507  } else {
508  $quotedSequenceName = $sequenceName;
509  $sql = 'SELECT PREVVAL FOR ' . $this->quoteIdentifier($sequenceName, true) . ' AS VAL FROM QSYS2.QSQPTABL';
510  }
511 
512  $value = $this->fetchOne($sql);
513  return (string) $value;
514  }
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$offsetOPTIONAL
Returns
string
See also
Zend_Db_Adapter_Db2_Exception
Zend_Db_Adapter_Db2_Exception

DB2 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 663 of file Db2.php.

664  {
665  $count = intval($count);
666  if ($count <= 0) {
670  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
671  throw new Zend_Db_Adapter_Db2_Exception("LIMIT argument count=$count is not valid");
672  }
673 
674  $offset = intval($offset);
675  if ($offset < 0) {
679  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
680  throw new Zend_Db_Adapter_Db2_Exception("LIMIT argument offset=$offset is not valid");
681  }
682 
683  if ($offset == 0) {
684  $limit_sql = $sql . " FETCH FIRST $count ROWS ONLY";
685  return $limit_sql;
686  }
687 
694  $limit_sql = "SELECT z2.*
695  FROM (
696  SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
697  FROM (
698  " . $sql . "
699  ) z1
700  ) z2
701  WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
702  return $limit_sql;
703  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables (   $schema = null)

Returns a list of the tables in the database.

Parameters
string$schemaOPTIONAL
Returns
array

Definition at line 320 of file Db2.php.

321  {
322  $this->_connect();
323 
324  if ($schema === null && $this->_config['schema'] != null) {
325  $schema = $this->_config['schema'];
326  }
327 
328  $tables = array();
329 
330  if (!$this->_isI5) {
331  if ($schema) {
332  $stmt = db2_tables($this->_connection, null, $schema);
333  } else {
334  $stmt = db2_tables($this->_connection);
335  }
336  while ($row = db2_fetch_assoc($stmt)) {
337  $tables[] = $row['TABLE_NAME'];
338  }
339  } else {
340  $tables = $this->_i5listTables($schema);
341  }
342 
343  return $tables;
344  }
_i5listTables($schema=null)
Definition: Db2.php:786

◆ 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 524 of file Db2.php.

525  {
526  $this->_connect();
527  $sql = 'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName, true).' AS VAL FROM SYSIBM.SYSDUMMY1';
528  $value = $this->fetchOne($sql);
529  return (string) $value;
530  }
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_Db2

Definition at line 230 of file Db2.php.

231  {
232  $this->_connect();
233  $stmtClass = $this->_defaultStmtClass;
234  if (!class_exists($stmtClass)) {
235  #require_once 'Zend/Loader.php';
236  Zend_Loader::loadClass($stmtClass);
237  }
238  $stmt = new $stmtClass($this, $sql);
239  $stmt->setFetchMode($this->_fetchMode);
240  return $stmt;
241  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52

◆ setFetchMode()

setFetchMode (   $mode)

Set the fetch mode.

Parameters
integer$mode
Returns
void
Exceptions
Zend_Db_Adapter_Db2_Exception
See also
Zend_Db_Adapter_Db2_Exception
Zend_Db_Adapter_Db2_Exception

Definition at line 629 of file Db2.php.

630  {
631  switch ($mode) {
632  case Zend_Db::FETCH_NUM: // seq array
633  case Zend_Db::FETCH_ASSOC: // assoc array
634  case Zend_Db::FETCH_BOTH: // seq+assoc array
635  case Zend_Db::FETCH_OBJ: // object
636  $this->_fetchMode = $mode;
637  break;
638  case Zend_Db::FETCH_BOUND: // bound to PHP variable
642  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
643  throw new Zend_Db_Adapter_Db2_Exception('FETCH_BOUND is not supported yet');
644  break;
645  default:
649  #require_once 'Zend/Db/Adapter/Db2/Exception.php';
650  throw new Zend_Db_Adapter_Db2_Exception("Invalid fetch mode '$mode' specified");
651  break;
652  }
653  }
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

◆ supportsParameters()

supportsParameters (   $type)

Check if the adapter supports real SQL parameters.

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

Definition at line 711 of file Db2.php.

712  {
713  if ($type == 'positional') {
714  return true;
715  }
716 
717  // if its 'named' or anything else
718  return false;
719  }
$type
Definition: item.phtml:13

Field Documentation

◆ $_config

$_config
protected
Initial value:
= array(
'dbname' => null,
'username' => null,
'password' => null,
'host' => 'localhost',
'port' => '50000',
'protocol' => 'TCPIP',
'persistent' => false,
'os' => null,
'schema' => null
)

Definition at line 65 of file Db2.php.

◆ $_defaultStmtClass

$_defaultStmtClass = 'Zend_Db_Statement_Db2'
protected

Definition at line 89 of file Db2.php.

◆ $_execute_mode

$_execute_mode = DB2_AUTOCOMMIT_ON
protected

Definition at line 82 of file Db2.php.

◆ $_isI5

$_isI5 = false
protected

Definition at line 90 of file Db2.php.

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 103 of file Db2.php.


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