/** * 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. * * @param string $tableName (optional) Name of table. * @param string $primaryKey (optional) Name of primary key column. * @return string */ public function lastInsertId($tableName = null, $primaryKey = null) { if (null === $tableName) { return parent::lastInsertId($tableName, $primaryKey); } $tableName = trim($tableName); if (empty($tableName)) { require_once 'Streamwide/Db/Adapter/Decorator/Exception.php'; throw new Streamwide_Db_Adapter_Decorator_Exception(__METHOD__ . ' requires parameter 1 to be a non empty string'); } try { if (false === ($sequence = $this->_getSequenceName($tableName))) { return parent::lastInsertId($tableName, $primaryKey); } return parent::lastSequenceId($sequence); } catch (Exception $e) { return parent::lastInsertId($tableName, $primaryKey); } }
/** * 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. * * @param string $tableName (optional) Name of table. * @param string $primaryKey (optional) Name of primary key column. * @return string */ public function lastInsertId($tableName = null, $primaryKey = null) { return $this->_adapter->lastInsertId($tableName, $primaryKey); }