You are here

function DB_storage::_makeWhere in Flickr API 5

Utility method to build a "WHERE" clause to locate ourselves in the table.

XXX future improvement: use rowids?

@access private

3 calls to DB_storage::_makeWhere()
DB_storage::remove in phpFlickr/PEAR/DB/storage.php
Remove the row represented by this object from the database.
DB_storage::setup in phpFlickr/PEAR/DB/storage.php
Method used to initialize a DB_storage object from the configured table.
DB_storage::store in phpFlickr/PEAR/DB/storage.php
Stores changes to this object in the database.

File

phpFlickr/PEAR/DB/storage.php, line 117

Class

DB_storage
Provides an object interface to a table row

Code

function _makeWhere($keyval = null) {
  if (is_array($this->_keycolumn)) {
    if ($keyval === null) {
      for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
        $keyval[] = $this->{$this->_keycolumn[$i]};
      }
    }
    $whereclause = '';
    for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
      if ($i > 0) {
        $whereclause .= ' AND ';
      }
      $whereclause .= $this->_keycolumn[$i];
      if (is_null($keyval[$i])) {

        // there's not much point in having a NULL key,
        // but we support it anyway
        $whereclause .= ' IS NULL';
      }
      else {
        $whereclause .= ' = ' . $this->_dbh
          ->quote($keyval[$i]);
      }
    }
  }
  else {
    if ($keyval === null) {
      $keyval = @$this->{$this->_keycolumn};
    }
    $whereclause = $this->_keycolumn;
    if (is_null($keyval)) {

      // there's not much point in having a NULL key,
      // but we support it anyway
      $whereclause .= ' IS NULL';
    }
    else {
      $whereclause .= ' = ' . $this->_dbh
        ->quote($keyval);
    }
  }
  return $whereclause;
}