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_Pdo_Ibm_Ids Class Reference

Public Member Functions

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

Protected Member Functions

 _getDataType ($typeNo)
 
 _getPrimaryInfo ($tabid)
 

Protected Attributes

 $_adapter = null
 

Detailed Description

Definition at line 38 of file Ids.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 Ids.php.

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

Member Function Documentation

◆ _getDataType()

_getDataType (   $typeNo)
protected

Map number representation of a data type to a string

Parameters
int$typeNo
Returns
string

Definition at line 161 of file Ids.php.

162  {
163  $typemap = array(
164  0 => "CHAR",
165  1 => "SMALLINT",
166  2 => "INTEGER",
167  3 => "FLOAT",
168  4 => "SMALLFLOAT",
169  5 => "DECIMAL",
170  6 => "SERIAL",
171  7 => "DATE",
172  8 => "MONEY",
173  9 => "NULL",
174  10 => "DATETIME",
175  11 => "BYTE",
176  12 => "TEXT",
177  13 => "VARCHAR",
178  14 => "INTERVAL",
179  15 => "NCHAR",
180  16 => "NVARCHAR",
181  17 => "INT8",
182  18 => "SERIAL8",
183  19 => "SET",
184  20 => "MULTISET",
185  21 => "LIST",
186  22 => "Unnamed ROW",
187  40 => "Variable-length opaque type",
188  4118 => "Named ROW"
189  );
190 
191  if ($typeNo - 256 >= 0) {
192  $typeNo = $typeNo - 256;
193  }
194 
195  return $typemap[$typeNo];
196  }

◆ _getPrimaryInfo()

_getPrimaryInfo (   $tabid)
protected

Helper method to retrieve primary key column and column location

Parameters
int$tabid
Returns
array

Definition at line 205 of file Ids.php.

206  {
207  $sql = "SELECT i.part1, i.part2, i.part3, i.part4, i.part5, i.part6,
208  i.part7, i.part8, i.part9, i.part10, i.part11, i.part12,
209  i.part13, i.part14, i.part15, i.part16
210  FROM sysindexes i
211  JOIN sysconstraints c ON c.idxname = i.idxname
212  WHERE i.tabid = " . $tabid . " AND c.constrtype = 'P'";
213 
214  $stmt = $this->_adapter->query($sql);
215  $results = $stmt->fetchAll();
216 
217  $cols = array();
218 
219  // this should return only 1 row
220  // unless there is no primary key,
221  // in which case, the empty array is returned
222  if ($results) {
223  $row = $results[0];
224  } else {
225  return $cols;
226  }
227 
228  $position = 0;
229  foreach ($row as $key => $colno) {
230  $position++;
231  if ($colno == 0) {
232  return $cols;
233  } else {
234  $cols[$colno] = $position;
235  }
236  }
237  }
$results
Definition: popup.phtml:13

◆ describeTable()

describeTable (   $tableName,
  $schemaName = null 
)

IDS catalog lookup for describe table

Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array

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

Definition at line 78 of file Ids.php.

79  {
80  // this is still a work in progress
81 
82  $sql= "SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,
83  d.default, c.collength, t.tabid
84  FROM syscolumns c
85  JOIN systables t ON c.tabid = t.tabid
86  LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno
87  WHERE "
88  . $this->_adapter->quoteInto('UPPER(t.tabname) = UPPER(?)', $tableName);
89  if ($schemaName) {
90  $sql .= $this->_adapter->quoteInto(' AND UPPER(t.owner) = UPPER(?)', $schemaName);
91  }
92  $sql .= " ORDER BY c.colno";
93 
94  $desc = array();
95  $stmt = $this->_adapter->query($sql);
96 
97  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
98 
103  $tabschema = 0;
104  $tabname = 1;
105  $colname = 2;
106  $colno = 3;
107  $typename = 4;
108  $default = 5;
109  $length = 6;
110  $tabid = 7;
111 
112  $primaryCols = null;
113 
114  foreach ($result as $key => $row) {
115  $primary = false;
116  $primaryPosition = null;
117 
118  if (!$primaryCols) {
119  $primaryCols = $this->_getPrimaryInfo($row[$tabid]);
120  }
121 
122  if (array_key_exists($row[$colno], $primaryCols)) {
123  $primary = true;
124  $primaryPosition = $primaryCols[$row[$colno]];
125  }
126 
127  $identity = false;
128  if ($row[$typename] == 6 + 256 ||
129  $row[$typename] == 18 + 256) {
130  $identity = true;
131  }
132 
133  $desc[$this->_adapter->foldCase($row[$colname])] = array (
134  'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
135  'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
136  'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
137  'COLUMN_POSITION' => $row[$colno],
138  'DATA_TYPE' => $this->_getDataType($row[$typename]),
139  'DEFAULT' => $row[$default],
140  'NULLABLE' => (bool) !($row[$typename] - 256 >= 0),
141  'LENGTH' => $row[$length],
142  'SCALE' => ($row[$typename] == 5 ? $row[$length]&255 : 0),
143  'PRECISION' => ($row[$typename] == 5 ? (int)($row[$length]/256) : 0),
144  'UNSIGNED' => false,
145  'PRIMARY' => $primary,
146  'PRIMARY_POSITION' => $primaryPosition,
147  'IDENTITY' => $identity
148  );
149  }
150 
151  return $desc;
152  }
$tableName
Definition: trigger.php:13
const FETCH_NUM
Definition: Db.php:153

◆ lastSequenceId()

lastSequenceId (   $sequenceName)

IDS-specific last sequence id

Parameters
string$sequenceName
Returns
integer

Definition at line 280 of file Ids.php.

281  {
282  $sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.CURRVAL FROM '
283  .'systables WHERE tabid = 1';
284  $value = $this->_adapter->fetchOne($sql);
285  return $value;
286  }
$value
Definition: gender.phtml:16

◆ limit()

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

Adds an IDS-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

Definition at line 248 of file Ids.php.

249  {
250  $count = intval($count);
251  if ($count < 0) {
253  #require_once 'Zend/Db/Adapter/Exception.php';
254  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
255  } else if ($count == 0) {
256  $limit_sql = str_ireplace("SELECT", "SELECT * FROM (SELECT", $sql);
257  $limit_sql .= ") WHERE 0 = 1";
258  } else {
259  $offset = intval($offset);
260  if ($offset < 0) {
262  #require_once 'Zend/Db/Adapter/Exception.php';
263  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
264  }
265  if ($offset == 0) {
266  $limit_sql = str_ireplace("SELECT", "SELECT FIRST $count", $sql);
267  } else {
268  $limit_sql = str_ireplace("SELECT", "SELECT SKIP $offset LIMIT $count", $sql);
269  }
270  }
271  return $limit_sql;
272  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 63 of file Ids.php.

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

◆ nextSequenceId()

nextSequenceId (   $sequenceName)

IDS-specific sequence id value

Parameters
string$sequenceName
Returns
integer

Definition at line 294 of file Ids.php.

295  {
296  $sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.NEXTVAL FROM '
297  .'systables WHERE tabid = 1';
298  $value = $this->_adapter->fetchOne($sql);
299  return $value;
300  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_adapter

$_adapter = null
protected

Definition at line 43 of file Ids.php.


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