public function testCrossPlatformBasicUpdate() { $query = new UpdateQuery(); $query->update('users')->partitions('p1', 'p2')->join('user_votes')->as('uv')->left()->on('uv.user_id = u.id'); $query->set(['name' => new Bind('name', 'Mary'), 'phone' => new Bind('phone', '09752222123')]); $query->where()->equal('id', 3); $query->limit(1); $this->assertSqlStrings($query, [[new MySQLDriver(), 'UPDATE users LEFT JOIN user_votes AS uv ON (uv.user_id = u.id) PARTITION (p1,p2) SET name = :name, phone = :phone WHERE id = 3 LIMIT 1'], [new PgSQLDriver(), 'UPDATE users LEFT JOIN user_votes AS uv ON (uv.user_id = u.id) SET name = :name, phone = :phone WHERE id = 3'], [new SQLiteDriver(), 'UPDATE users LEFT JOIN user_votes AS uv ON (uv.user_id = u.id) SET name = :name, phone = :phone WHERE id = 3']]); }
/** * 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)); }