本文整理汇总了PHP中Zend_Db_Adapter_Abstract::nextSequenceId方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Adapter_Abstract::nextSequenceId方法的具体用法?PHP Zend_Db_Adapter_Abstract::nextSequenceId怎么用?PHP Zend_Db_Adapter_Abstract::nextSequenceId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Adapter_Abstract
的用法示例。
在下文中一共展示了Zend_Db_Adapter_Abstract::nextSequenceId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* Inserts a new row.
*
* @param array $data Column-value pairs.
* @return mixed The primary key of the row inserted.
*/
public function insert(array $data)
{
/**
* Zend_Db_Table assumes that if you have a compound primary key
* and one of the columns in the key uses a sequence,
* it's the _first_ column in the compound key.
*/
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int) $this->_identity];
/**
* If this table uses a database sequence object and the data does not
* specify a value, then get the next ID from the sequence and add it
* to the row. We assume that only the first column in a compound
* primary key takes a value from a sequence.
*/
if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
}
/**
* If the primary key can be generated automatically, and no value was
* specified in the user-supplied data, then omit it from the tuple.
*/
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
unset($data[$pkIdentity]);
}
/**
* INSERT the new row.
*/
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
$this->_db->insert($tableSpec, $data);
/**
* Fetch the most recent ID generated by an auto-increment
* or IDENTITY column, unless the user has specified a value,
* overriding the auto-increment mechanism.
*/
if ($this->_sequence === true && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->lastInsertId();
}
/**
* Return the primary key value if the PK is a single column,
* else return an associative array of the PK column/value pairs.
*/
$pkData = array_intersect_key($data, array_flip($primary));
if (count($primary) == 1) {
return current($pkData);
} else {
return $pkData;
}
/**
* The last case: the user did not specify a value for the primary
* key, nor is this table class declared to use an auto-increment key.
* Since the insert did not fail, we can assume this is one of the edge
* cases, which may include:
* - the table has no primary key defined;
* - the database table uses a trigger to set a primary key value;
* - the RDBMS permits primary keys to be NULL or have a value set
* to the column's DEFAULT
*/
return null;
}
示例2: insert
/**
* Inserts a new row.
*
* @param array $data Column-value pairs.
* @return mixed The primary key of the row inserted.
*/
public function insert(array $data)
{
/**
* Zend_Db_Table assumes that if you have a compound primary key
* and one of the columns in the key uses a sequence,
* it's the _first_ column in the compound key.
*/
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int) $this->_identity];
/**
* If this table uses a database sequence object and the data does not
* specify a value, then get the next ID from the sequence and add it
* to the row. We assume that only the first column in a compound
* primary key takes a value from a sequence.
*/
if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
}
/**
* If the primary key can be generated automatically, and no value was
* specified in the user-supplied data, then omit it from the tuple.
*/
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
unset($data[$pkIdentity]);
}
/**
* Run pre-INSERT logic
*/
if ($this->notify('preInsert', $this, $data) === false) {
return null;
}
/**
* INSERT the new row.
*/
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
$this->_db->insert($tableSpec, $data);
/**
* Fetch the most recent ID generated by an auto-increment
* or IDENTITY column, unless the user has specified a value,
* overriding the auto-increment mechanism.
*/
if ($this->_sequence === true && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->lastInsertId();
}
/**
* Run post-INSERT logic
*/
$this->notify('postInsert', $this, $data);
/**
* Return the primary key value if the PK is a single column,
* else return an associative array of the PK column/value pairs.
*/
$pkData = array_intersect_key($data, array_flip($primary));
if (count($primary) == 1) {
reset($pkData);
return current($pkData);
}
return $pkData;
}
示例3: insert
/**
* Inserts a new row.
*
* @param array $data Column-value pairs.
* @return mixed The primary key of the row inserted.
*/
public function insert(array $data)
{
/**
* Zend_Db_Table assumes that if you have a compound primary key
* and one of the columns in the key uses a sequence,
* it's the _first_ column in the compound key.
*/
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int) $this->_identity];
/**
* If this table uses a database sequence object and the data does not
* specify a value, then get the next ID from the sequence and add it
* to the row. We assume that only the first column in a compound
* primary key takes a value from a sequence.
*/
if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
}
/**
* INSERT the new row.
*/
$this->_db->insert($this->_name, $data);
if (isset($data[$pkIdentity])) {
/**
* Return the primary key value or array of values(s) if the
* primary key is compound. This handles the case of natural keys
* and sequence-driven keys. This also covers the case of
* auto-increment keys when the user specifies a value, thus
* overriding the auto-increment logic.
*/
$pkData = array_intersect_key($data, array_flip($primary));
if (count($primary) == 1) {
return current($pkData);
} else {
return $pkData;
}
}
if ($this->_sequence === true) {
/**
* Return the most recent ID generated by an auto-increment
* or IDENTITY column.
*/
return $this->_db->lastInsertId();
}
/**
* The last case: the user did not specify a value for the primary
* key, nor is this table class declared to use an auto-increment key.
* Since the insert did not fail, we can assume this is one of the edge
* cases, which may include:
* - the table has no primary key defined;
* - the database table uses a trigger to set a primary key value;
* - the RDBMS permits primary keys to be NULL or have a value set
* to the column's DEFAULT
*/
return null;
}
示例4: insert
/**
* Inserts a new row.
*
* @param array $data Column-value pairs.
* @return mixed The primary key of the row inserted.
*/
public function insert(array $data)
{
$this->_setupPrimaryKey();
/**
* Zend_Db_Table assumes that if you have a compound primary key
* and one of the columns in the key uses a sequence,
* it's the _first_ column in the compound key.
*/
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int) $this->_identity];
/**
* If this table uses a database sequence object and the data does not
* specify a value, then get the next ID from the sequence and add it
* to the row. We assume that only the first column in a compound
* primary key takes a value from a sequence.
*/
if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
$pkSuppliedBySequence = true;
}
/**
* If the primary key can be generated automatically, and no value was
* specified in the user-supplied data, then omit it from the tuple.
*
* Note: this checks for sensible values in the supplied primary key
* position of the data. The following values are considered empty:
* null, false, true, '', array()
*/
if (!isset($pkSuppliedBySequence) && array_key_exists($pkIdentity, $data)) {
if ($data[$pkIdentity] === null || $data[$pkIdentity] === '' || is_bool($data[$pkIdentity]) || is_array($data[$pkIdentity]) && empty($data[$pkIdentity])) {
// empty array
unset($data[$pkIdentity]);
}
}
/**
* INSERT the new row.
*/
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
$this->_db->insert($tableSpec, $data);
/**
* Fetch the most recent ID generated by an auto-increment
* or IDENTITY column, unless the user has specified a value,
* overriding the auto-increment mechanism.
*/
if ($this->_sequence === true && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->lastInsertId();
}
/**
* Return the primary key value if the PK is a single column,
* else return an associative array of the PK column/value pairs.
*/
$pkData = array_intersect_key($data, array_flip($primary));
if (count($primary) == 1) {
reset($pkData);
return current($pkData);
}
return $pkData;
}
示例5: nextSequenceId
/**
* 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.
*
* @param string $sequenceName sequence name
* @return string
*/
public function nextSequenceId($sequenceName)
{
return $this->_adapter->nextSequenceId($sequenceName);
}