{
if (is_null($value)) {
return true;
}
$table = $this->invoker->getTable();
$conn = $table->getConnection();
$pks = $table->getIdentifierColumnNames();
if (is_array($pks)) {
for ($i = 0, $l = count($pks); $i < $l; $i++) {
$pks[$i] = $conn->quoteIdentifier($pks[$i]);
}
$pks = implode(', ', $pks);
}
$sql = 'SELECT ' . $pks . ' FROM ' . $conn->quoteIdentifier($table->getTableName()) . ' WHERE ';
if (is_array($this->field)) {
foreach ($this->field as $k => $v) {
$this->field[$k] = $conn->quoteIdentifier($table->getColumnName($v));
}
$sql .= implode(' = ? AND ', $this->field) . ' = ?';
$values = $value;
} else {
$sql .= $conn->quoteIdentifier($table->getColumnName($this->field)) . ' = ?';
$values = array();
$values[] = $value;
}
$state = $this->invoker->state();
foreach ((array) $table->getIdentifierColumnNames() as $pk) {
$sql .= ' AND ' . $conn->quoteIdentifier($pk) . ' != ?';
$pkFieldName = $table->getFieldName($pk);
$values[] = $this->invoker->$pkFieldName;
}
}
if (isset($this->args) && is_array($this->args) && isset($this->args['where'])) {
$sql .= ' AND ' . $this->args['where'];
}
$stmt = $table->getConnection()->getDbh()->prepare($sql);
$stmt->execute($values);
return ( ! is_array($stmt->fetch()));
}