public function testMySQLBasicUpdate() { $driver = new MySQLDriver(); $args = new ArgumentArray(); $query = new UpdateQuery(); $query->update('users')->set(['name' => new Bind('name', 'Mary')]); $query->where()->equal('id', 3); ok($query); $sql = $query->toSql($driver, $args); is('UPDATE users SET name = :name WHERE id = 3', $sql); }
/** * Simply update record without validation and triggers. * * @param array $args */ public function rawUpdate(array $args) { $dsId = $this->writeSourceId; $conn = $this->getWriteConnection(); $driver = $this->getWriteQueryDriver(); $k = static::PRIMARY_KEY; $kVal = isset($args[$k]) ? $args[$k] : isset($this->_data[$k]) ? $this->_data[$k] : null; $arguments = new ArgumentArray(); $query = new UpdateQuery(); $query->set($args); $query->update($this->table); $query->where()->equal($k, $kVal); $sql = $query->toSql($driver, $arguments); $stm = $conn->prepare($sql); $stm->execute($arguments->toArray()); // update current data stash $this->_data = array_merge($this->_data, $args); return $this->reportSuccess('Update success', array('sql' => $sql, 'type' => Result::TYPE_UPDATE)); }
/** * Simply update record without validation and triggers. * * @param array $args */ public function rawUpdate(array $args) { $dsId = $this->getWriteSourceId(); $conn = $this->getConnection($dsId); $k = static::primary_key; $kVal = isset($args[$k]) ? $args[$k] : isset($this->_data[$k]) ? $this->_data[$k] : null; $arguments = new ArgumentArray(); $query = new UpdateQuery(); $query->set($args); $query->update($this->getTable()); $query->where()->equal($k, $kVal); $sql = $query->toSql($conn->createQueryDriver(), $arguments); $stm = $this->dbPrepareAndExecute($conn, $sql, $arguments->toArray()); // update current data stash $this->_data = array_merge($this->_data, $args); return $this->reportSuccess('Update success', array('sql' => $sql)); }
/** * Update collection * * FIXME */ public function update(array $data) { $schema = $this->getSchema(); $dsId = $schema->getWriteSourceId(); $conn = ConnectionManager::getInstance()->getConnection($dsId); $driver = $conn->createQueryDriver(); $query = new UpdateQuery(); $query->setWhere(clone $this->getCurrentReadQuery()->getWhere()); $query->update($this->getTable()); $query->set($data); $arguments = new ArgumentArray(); $sql = $query->toSql($driver, $arguments); try { $this->handle = $conn->prepareAndExecute($sql, $arguments->toArray()); } catch (Exception $e) { return Result::failure('Collection update failed: ' . $e->getMessage(), array('vars' => $arguments->toArray(), 'sql' => $sql, 'exception' => $e)); } return Result::success('Updated', array('sql' => $sql)); }