/** * Check if an entry with the given primary key or key/value exists in the database * * @param mixed $id The primary key or an array (key/value) * @return bool */ public function exists($id) { $db = $this->getDb(); $select = $this->createQueryBuilder(); $select->from($this->_tableName, 'a'); if (is_array($id)) { foreach ($id as $key => $val) { if (isset($this->_formatMap[$key])) { $val = Format::toSql($this->_formatMap[$key], $val); } $select->andWhere($this->getDb()->quoteIdentifier($key) . ' = ' . $db->quote($val)); } } else { if (isset($this->_formatMap[$this->_primaryKey])) { $id = Format::fromSql($this->_formatMap[$this->_primaryKey], $id); } $select->where($this->getDb()->quoteIdentifier($this->_primaryKey) . ' = ' . $db->quote($id)); } $data = $this->getDb()->fetchAssoc($select); return is_array($data); }
public function testFromSqlSerialized() { $output = Format::toSql(Format::SERIALIZED, array('foo' => 'bar')); $output = Format::fromSql(Format::SERIALIZED, $output); $this->assertEquals(array('foo' => 'bar'), $output); }