/** * @param Vo $vo * @return int 返回删除数据的行数 * @throws \Simple\Model\Exception\DbException * @throws \Simple\Exception\UnexpectedValueException */ public function delete(Vo $vo) { if (!$vo instanceof PDOVo) { throw new UnexpectedValueException('vo参数必须为PDOVo对象。'); } $priKey = $vo->getPrimaryKey(); $where = " `{$priKey}`=:{$priKey} "; $tbName = $vo->getTableName(); $sql = "DELETE FROM `" . $tbName . "` WHERE " . $where; Debug::trace('delete:' . $sql, 'mysql'); $sth = $this->_link->prepare($sql); $sth->bindValue(":{$priKey}", call_user_func_array(array(&$vo, "get" . ucfirst($priKey)), array())); $ret = $sth->execute(); if ($ret === false) { throw new DbException($sth->errorInfo(), $sth->errorCode()); } return $sth->rowCount(); }
/** * cas更新 * @param Vo $vo * @return bool * @throws \Simple\Exception\UnexpectedValueException */ public function cas(Vo $vo) { if (!$vo instanceof NoSQLVo) { throw new UnexpectedValueException('vo对象必须为NoSQLVo'); } return $this->_link->cas($vo->getKey(), $vo->toSave(), $vo->getExpiredTime(), $vo->getCas()); }