You are here

function DB_mysql::_BCsequence in Flickr API 5

Backwards compatibility with old sequence emulation implementation (clean up the dupes)

@access private

Parameters

string $seqname the sequence name to clean up:

Return value

bool true on success. A DB_Error object on failure.

1 call to DB_mysql::_BCsequence()
DB_mysql::nextId in phpFlickr/PEAR/DB/mysql.php
Returns the next free id in a sequence

File

phpFlickr/PEAR/DB/mysql.php, line 711

Class

DB_mysql
The methods PEAR DB uses to interact with PHP's mysql extension for interacting with MySQL databases

Code

function _BCsequence($seqname) {

  // Obtain a user-level lock... this will release any previous
  // application locks, but unlike LOCK TABLES, it does not abort
  // the current transaction and is much less frequently used.
  $result = $this
    ->getOne("SELECT GET_LOCK('{$seqname}_lock',10)");
  if (DB::isError($result)) {
    return $result;
  }
  if ($result == 0) {

    // Failed to get the lock, can't do the conversion, bail
    // with a DB_ERROR_NOT_LOCKED error
    return $this
      ->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
  }
  $highest_id = $this
    ->getOne("SELECT MAX(id) FROM {$seqname}");
  if (DB::isError($highest_id)) {
    return $highest_id;
  }

  // This should kill all rows except the highest
  // We should probably do something if $highest_id isn't
  // numeric, but I'm at a loss as how to handle that...
  $result = $this
    ->query('DELETE FROM ' . $seqname . " WHERE id <> {$highest_id}");
  if (DB::isError($result)) {
    return $result;
  }

  // If another thread has been waiting for this lock,
  // it will go thru the above procedure, but will have no
  // real effect
  $result = $this
    ->getOne("SELECT RELEASE_LOCK('{$seqname}_lock')");
  if (DB::isError($result)) {
    return $result;
  }
  return true;
}