diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-02-27 09:12:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-27 09:12:35 +0100 |
commit | 72cc8270cdd0f1c95ef1708be81cf4ac424dca47 (patch) | |
tree | 5177f46b807203514663f2b4f4e3d611f6b5c08a | |
parent | d91c0d8bd692437bbaf41f115ae5a3a154066acc (diff) | |
parent | 9c9f8fa5f7bb66ba1cb294705e11dc4f8ea315fc (diff) | |
download | nextcloud-server-72cc8270cdd0f1c95ef1708be81cf4ac424dca47.tar.gz nextcloud-server-72cc8270cdd0f1c95ef1708be81cf4ac424dca47.zip |
Merge pull request #19659 from nextcloud/techdebt/17486/allow-non-integer-ids-in-entity-mapper
Allow non integer ids in Entity Mapper
-rw-r--r-- | lib/public/AppFramework/Db/QBMapper.php | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php index a6c8ac27acb..5fa367491b0 100644 --- a/lib/public/AppFramework/Db/QBMapper.php +++ b/lib/public/AppFramework/Db/QBMapper.php @@ -89,9 +89,11 @@ abstract class QBMapper { public function delete(Entity $entity): Entity { $qb = $this->db->getQueryBuilder(); + $idType = $this->getParameterTypeForProperty($entity, 'id'); + $qb->delete($this->tableName) ->where( - $qb->expr()->eq('id', $qb->createNamedParameter($entity->getId())) + $qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType)) ); $qb->execute(); return $entity; @@ -126,6 +128,7 @@ abstract class QBMapper { $qb->execute(); if($entity->id === null) { + // When autoincrement is used id is always an int $entity->setId((int)$qb->getLastInsertId()); } @@ -191,8 +194,10 @@ abstract class QBMapper { $qb->set($column, $qb->createNamedParameter($value, $type)); } + $idType = $this->getParameterTypeForProperty($entity, 'id'); + $qb->where( - $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) + $qb->expr()->eq('id', $qb->createNamedParameter($id, $idType)) ); $qb->execute(); |