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_Pgsql Class Reference
Inheritance diagram for Zend_Db_Adapter_Pdo_Pgsql:
Zend_Db_Adapter_Pdo_Abstract Zend_Db_Adapter_Abstract

Public Member Functions

 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 limit ($sql, $count, $offset=0)
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
- 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

 _connect ()
 
- 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 = 'pgsql'
 
 $_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 Pgsql.php.

Member Function Documentation

◆ _connect()

_connect ( )
protected

Creates a PDO object and connects to the database.

Returns
void
Exceptions
Zend_Db_Adapter_Exception

Definition at line 81 of file Pgsql.php.

82  {
83  if ($this->_connection) {
84  return;
85  }
86 
87  parent::_connect();
88 
89  if (!empty($this->_config['charset'])) {
90  $sql = "SET NAMES '" . $this->_config['charset'] . "'";
91  $this->_connection->exec($sql);
92  }
93  }

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

Definition at line 149 of file Pgsql.php.

150  {
151  $sql = "SELECT
152  a.attnum,
153  n.nspname,
154  c.relname,
155  a.attname AS colname,
156  t.typname AS type,
157  a.atttypmod,
158  FORMAT_TYPE(a.atttypid, a.atttypmod) AS complete_type,
159  d.adsrc AS default_value,
160  a.attnotnull AS notnull,
161  a.attlen AS length,
162  co.contype,
163  ARRAY_TO_STRING(co.conkey, ',') AS conkey
164  FROM pg_attribute AS a
165  JOIN pg_class AS c ON a.attrelid = c.oid
166  JOIN pg_namespace AS n ON c.relnamespace = n.oid
167  JOIN pg_type AS t ON a.atttypid = t.oid
168  LEFT OUTER JOIN pg_constraint AS co ON (co.conrelid = c.oid
169  AND a.attnum = ANY(co.conkey) AND co.contype = 'p')
170  LEFT OUTER JOIN pg_attrdef AS d ON d.adrelid = c.oid AND d.adnum = a.attnum
171  WHERE a.attnum > 0 AND c.relname = ".$this->quote($tableName);
172  if ($schemaName) {
173  $sql .= " AND n.nspname = ".$this->quote($schemaName);
174  }
175  $sql .= ' ORDER BY a.attnum';
176 
177  $stmt = $this->query($sql);
178 
179  // Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
180  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
181 
182  $attnum = 0;
183  $nspname = 1;
184  $relname = 2;
185  $colname = 3;
186  $type = 4;
187  $atttypemod = 5;
188  $complete_type = 6;
189  $default_value = 7;
190  $notnull = 8;
191  $length = 9;
192  $contype = 10;
193  $conkey = 11;
194 
195  $desc = array();
196  foreach ($result as $key => $row) {
197  $defaultValue = $row[$default_value];
198  if ($row[$type] == 'varchar' || $row[$type] == 'bpchar' ) {
199  if (preg_match('/character(?: varying)?(?:\((\d+)\))?/', $row[$complete_type], $matches)) {
200  if (isset($matches[1])) {
201  $row[$length] = $matches[1];
202  } else {
203  $row[$length] = null; // unlimited
204  }
205  }
206  if (preg_match("/^'(.*?)'::(?:character varying|bpchar)$/", $defaultValue, $matches)) {
207  $defaultValue = $matches[1];
208  }
209  }
210  list($primary, $primaryPosition, $identity) = array(false, null, false);
211  if ($row[$contype] == 'p') {
212  $primary = true;
213  $primaryPosition = array_search($row[$attnum], explode(',', $row[$conkey])) + 1;
214  $identity = (bool) (preg_match('/^nextval/', $row[$default_value]));
215  }
216  $desc[$this->foldCase($row[$colname])] = array(
217  'SCHEMA_NAME' => $this->foldCase($row[$nspname]),
218  'TABLE_NAME' => $this->foldCase($row[$relname]),
219  'COLUMN_NAME' => $this->foldCase($row[$colname]),
220  'COLUMN_POSITION' => $row[$attnum],
221  'DATA_TYPE' => $row[$type],
222  'DEFAULT' => $defaultValue,
223  'NULLABLE' => (bool) ($row[$notnull] != 't'),
224  'LENGTH' => $row[$length],
225  'SCALE' => null, // @todo
226  'PRECISION' => null, // @todo
227  'UNSIGNED' => null, // @todo
228  'PRIMARY' => $primary,
229  'PRIMARY_POSITION' => $primaryPosition,
230  'IDENTITY' => $identity
231  );
232  }
233  return $desc;
234  }
$tableName
Definition: trigger.php:13
$type
Definition: item.phtml: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.

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

Definition at line 323 of file Pgsql.php.

324  {
325  if ($tableName !== null) {
326  $sequenceName = $tableName;
327  if ($primaryKey) {
328  $sequenceName .= "_$primaryKey";
329  }
330  $sequenceName .= '_seq';
331  return $this->lastSequenceId($sequenceName);
332  }
333  return $this->_connection->lastInsertId($tableName);
334  }
$tableName
Definition: trigger.php:13
lastSequenceId($sequenceName)
Definition: Pgsql.php:281

◆ 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 281 of file Pgsql.php.

282  {
283  $this->_connect();
284  $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName);
285  $value = $this->fetchOne("SELECT CURRVAL("
286  . $this->quote($this->quoteIdentifier($sequenceName, true))
287  . ")");
288  return $value;
289  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
quote($value, $type=null)
Definition: Abstract.php:859
$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_Exception
Zend_Db_Adapter_Exception

Definition at line 245 of file Pgsql.php.

246  {
247  $count = intval($count);
248  if ($count <= 0) {
252  #require_once 'Zend/Db/Adapter/Exception.php';
253  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
254  }
255 
256  $offset = intval($offset);
257  if ($offset < 0) {
261  #require_once 'Zend/Db/Adapter/Exception.php';
262  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
263  }
264 
265  $sql .= " LIMIT $count";
266  if ($offset > 0) {
267  $sql .= " OFFSET $offset";
268  }
269 
270  return $sql;
271  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 100 of file Pgsql.php.

101  {
102  // @todo use a better query with joins instead of subqueries
103  $sql = "SELECT c.relname AS table_name "
104  . "FROM pg_class c, pg_user u "
105  . "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
106  . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
107  . "AND c.relname !~ '^(pg_|sql_)' "
108  . "UNION "
109  . "SELECT c.relname AS table_name "
110  . "FROM pg_class c "
111  . "WHERE c.relkind = 'r' "
112  . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
113  . "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
114  . "AND c.relname !~ '^pg_'";
115 
116  return $this->fetchCol($sql);
117  }
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 299 of file Pgsql.php.

300  {
301  $this->_connect();
302  $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName);
303  $value = $this->fetchOne("SELECT NEXTVAL("
304  . $this->quote($this->quoteIdentifier($sequenceName, true))
305  . ")");
306  return $value;
307  }
fetchOne($sql, $bind=array())
Definition: Abstract.php:826
quote($value, $type=null)
Definition: Abstract.php:859
$value
Definition: gender.phtml:16
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959

Field Documentation

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 60 of file Pgsql.php.

◆ $_pdoType

$_pdoType = 'pgsql'
protected

Definition at line 47 of file Pgsql.php.


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