public function testSetValuesSameNoError() { $this->makeTestTable(); $this->connection->setValues('table', ['integerfield' => 1], ['textfield' => 'foo', 'clobfield' => 'not_null']); // this will result in 'no affected rows' on certain optimizing DBs // ensure the PreConditionNotMetException isn't thrown $this->connection->setValues('table', ['integerfield' => 1], ['textfield' => 'foo']); }
/** * Set a user defined value * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we want to store the value under * @param string $key the key under which the value is being stored * @param string $value the value that you want to store * @param string $preCondition only update if the config value was previously the value passed as $preCondition * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met */ public function setUserValue($userId, $appName, $key, $value, $preCondition = null) { // TODO - FIXME $this->fixDIInit(); $preconditionArray = []; if (isset($preCondition)) { $preconditionArray = ['configvalue' => $preCondition]; } $this->connection->setValues('preferences', ['userid' => $userId, 'appid' => $appName, 'configkey' => $key], ['configvalue' => $value], $preconditionArray); // only add to the cache if we already loaded data for the user if (isset($this->userCache[$userId])) { if (!isset($this->userCache[$userId][$appName])) { $this->userCache[$userId][$appName] = array(); } $this->userCache[$userId][$appName][$key] = $value; } }
/** * Set a user defined value * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we want to store the value under * @param string $key the key under which the value is being stored * @param string|float|int $value the value that you want to store * @param string $preCondition only update if the config value was previously the value passed as $preCondition * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met * @throws \UnexpectedValueException when trying to store an unexpected value */ public function setUserValue($userId, $appName, $key, $value, $preCondition = null) { if (!is_int($value) && !is_float($value) && !is_string($value)) { throw new \UnexpectedValueException('Only integers, floats and strings are allowed as value'); } // TODO - FIXME $this->fixDIInit(); $preconditionArray = []; if (isset($preCondition)) { $preconditionArray = ['configvalue' => $preCondition]; } $this->connection->setValues('preferences', ['userid' => $userId, 'appid' => $appName, 'configkey' => $key], ['configvalue' => $value], $preconditionArray); // only add to the cache if we already loaded data for the user if (isset($this->userCache[$userId])) { if (!isset($this->userCache[$userId][$appName])) { $this->userCache[$userId][$appName] = array(); } $this->userCache[$userId][$appName][$key] = $value; } }
/** * Insert or update a row value * * @param string $table * @param array $keys (column name => value) * @param array $values (column name => value) * @param array $updatePreconditionValues ensure values match preconditions (column name => value) * @return int number of new rows * @throws \Doctrine\DBAL\DBALException * @throws PreconditionNotMetException */ public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { return $this->connection->setValues($table, $keys, $values, $updatePreconditionValues); }
/** * Store a set of credentials * * @param string|null $userId Null for system-wide credentials * @param string $identifier * @param mixed $credentials */ public function store($userId, $identifier, $credentials) { $value = $this->crypto->encrypt(json_encode($credentials)); $this->dbConnection->setValues(self::DB_TABLE, ['user' => $userId, 'identifier' => $identifier], ['credentials' => $value]); }
/** * @expectedException \OCP\PreConditionNotMetException */ public function testSetValuesOverWritePreconditionFailed() { $this->makeTestTable(); $this->connection->setValues('table', ['integerfield' => 1], ['textfield' => 'foo', 'booleanfield' => true, 'clobfield' => 'not_null']); $this->connection->setValues('table', ['integerfield' => 1], ['textfield' => 'bar'], ['booleanfield' => false]); }