Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Db_Adapter_Pdo_Ibm_Db2 Class Reference

Public Member Functions

 __construct ($adapter)
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 limit ($sql, $count, $offset=0)
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 

Protected Attributes

 $_adapter = null
 

Detailed Description

Definition at line 38 of file Db2.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $adapter)

Construct the data server class.

It will be used to generate non-generic SQL for a particular data server

Parameters
Zend_Db_Adapter_Abstract$adapter

Definition at line 53 of file Db2.php.

54  {
55  $this->_adapter = $adapter;
56  }
$adapter
Definition: webapi_user.php:16

Member Function Documentation

◆ describeTable()

describeTable (   $tableName,
  $schemaName = null 
)

DB2 catalog lookup for describe table

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

78  {
79  $sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
80  c.typename, c.default, c.nulls, c.length, c.scale,
81  c.identity, tc.type AS tabconsttype, k.colseq
82  FROM syscat.columns c
83  LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
84  ON (k.tabschema = tc.tabschema
85  AND k.tabname = tc.tabname
86  AND tc.type = 'P'))
87  ON (c.tabschema = k.tabschema
88  AND c.tabname = k.tabname
89  AND c.colname = k.colname)
90  WHERE "
91  . $this->_adapter->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
92  if ($schemaName) {
93  $sql .= $this->_adapter->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
94  }
95  $sql .= " ORDER BY c.colno";
96 
97  $desc = array();
98  $stmt = $this->_adapter->query($sql);
99 
103  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
104 
109  $tabschema = 0;
110  $tabname = 1;
111  $colname = 2;
112  $colno = 3;
113  $typename = 4;
114  $default = 5;
115  $nulls = 6;
116  $length = 7;
117  $scale = 8;
118  $identityCol = 9;
119  $tabconstype = 10;
120  $colseq = 11;
121 
122  foreach ($result as $key => $row) {
123  list ($primary, $primaryPosition, $identity) = array(false, null, false);
124  if ($row[$tabconstype] == 'P') {
125  $primary = true;
126  $primaryPosition = $row[$colseq];
127  }
132  if ($row[$identityCol] == 'Y') {
133  $identity = true;
134  }
135 
136  $desc[$this->_adapter->foldCase($row[$colname])] = array(
137  'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
138  'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
139  'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
140  'COLUMN_POSITION' => $row[$colno]+1,
141  'DATA_TYPE' => $row[$typename],
142  'DEFAULT' => $row[$default],
143  'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
144  'LENGTH' => $row[$length],
145  'SCALE' => $row[$scale],
146  'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
147  'UNSIGNED' => false,
148  'PRIMARY' => $primary,
149  'PRIMARY_POSITION' => $primaryPosition,
150  'IDENTITY' => $identity
151  );
152  }
153 
154  return $desc;
155  }
$tableName
Definition: trigger.php:13
const FETCH_NUM
Definition: Db.php:153

◆ lastSequenceId()

lastSequenceId (   $sequenceName)

DB2-specific last sequence id

Parameters
string$sequenceName
Returns
integer

Definition at line 209 of file Db2.php.

210  {
211  $sql = 'SELECT PREVVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
212  $value = $this->_adapter->fetchOne($sql);
213  return $value;
214  }
$value
Definition: gender.phtml:16

◆ limit()

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

Adds a DB2-specific LIMIT clause to the SELECT statement.

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

167  {
168  $count = intval($count);
169  if ($count < 0) {
171  #require_once 'Zend/Db/Adapter/Exception.php';
172  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
173  } else {
174  $offset = intval($offset);
175  if ($offset < 0) {
177  #require_once 'Zend/Db/Adapter/Exception.php';
178  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
179  }
180 
181  if ($offset == 0 && $count > 0) {
182  $limit_sql = $sql . " FETCH FIRST $count ROWS ONLY";
183  return $limit_sql;
184  }
191  $limit_sql = "SELECT z2.*
192  FROM (
193  SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
194  FROM (
195  " . $sql . "
196  ) z1
197  ) z2
198  WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
199  }
200  return $limit_sql;
201  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 63 of file Db2.php.

64  {
65  $sql = "SELECT tabname "
66  . "FROM SYSCAT.TABLES ";
67  return $this->_adapter->fetchCol($sql);
68  }

◆ nextSequenceId()

nextSequenceId (   $sequenceName)

DB2-specific sequence id value

Parameters
string$sequenceName
Returns
integer

Definition at line 222 of file Db2.php.

223  {
224  $sql = 'SELECT NEXTVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
225  $value = $this->_adapter->fetchOne($sql);
226  return $value;
227  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_adapter

$_adapter = null
protected

Definition at line 43 of file Db2.php.


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