Skip to content

Commit 9976e47

Browse files
Merge pull request #23602 from nextcloud/fix/appconfig_update_null
Fix updates of NULL appconfig values
2 parents bd4c9d9 + db82d27 commit 9976e47

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

lib/private/AppConfig.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,35 @@ public function setValue($app, $key, $value) {
202202

203203
$sql = $this->conn->getQueryBuilder();
204204
$sql->update('appconfig')
205-
->set('configvalue', $sql->createParameter('configvalue'))
206-
->where($sql->expr()->eq('appid', $sql->createParameter('app')))
207-
->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
208-
->setParameter('configvalue', $value)
209-
->setParameter('app', $app)
210-
->setParameter('configkey', $key);
205+
->set('configvalue', $sql->createNamedParameter($value))
206+
->where($sql->expr()->eq('appid', $sql->createNamedParameter($app)))
207+
->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key)));
211208

212209
/*
213210
* Only limit to the existing value for non-Oracle DBs:
214211
* http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286
215212
* > Large objects (LOBs) are not supported in comparison conditions.
216213
*/
217214
if (!($this->conn instanceof OracleConnection)) {
218-
// Only update the value when it is not the same
219-
$sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue')))
220-
->setParameter('configvalue', $value);
215+
216+
/*
217+
* Only update the value when it is not the same
218+
* Note that NULL requires some special handling. Since comparing
219+
* against null can have special results.
220+
*/
221+
222+
if ($value === null) {
223+
$sql->andWhere(
224+
$sql->expr()->isNotNull('configvalue')
225+
);
226+
} else {
227+
$sql->andWhere(
228+
$sql->expr()->orX(
229+
$sql->expr()->isNull('configvalue'),
230+
$sql->expr()->neq('configvalue', $sql->createNamedParameter($value))
231+
)
232+
);
233+
}
221234
}
222235

223236
$changedRow = (bool) $sql->execute();

0 commit comments

Comments
 (0)