Beispiel #1
0
 /**
  * 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));
 }
Beispiel #2
0
 /**
  * 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));
 }
Beispiel #3
0
 /**
  * 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));
 }
Beispiel #4
0
 public function testBasicUpdateWithParamMarker()
 {
     $driver = new MySQLDriver();
     $args = new ArgumentArray();
     $query = new UpdateQuery();
     $query->options('LOW_PRIORITY', 'IGNORE')->update('users')->set(['name' => new ParamMarker('Mary')]);
     $query->where()->equal('id', new ParamMarker(3));
     ok($query);
     $sql = $query->toSql($driver, $args);
     is('UPDATE LOW_PRIORITY IGNORE users SET name = ? WHERE id = ?', $sql);
 }