Example #1
0
 /**
  * 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);
     }
 }
Example #2
0
 /**
  * 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.
  *
  * @param string $sequenceName sequence name
  * @return string
  */
 public function lastSequenceId($sequenceName)
 {
     return $this->_adapter->lastSequenceId($sequenceName);
 }