Use executeQuery and executeUpdate in the QBMapper

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-03-18 08:28:06 +01:00
parent b34035f845
commit 0d8b3baf61
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
2 changed files with 13 additions and 13 deletions

View File

@ -25,9 +25,9 @@ declare(strict_types=1);
namespace OCA\UserStatus\Tests\Db; namespace OCA\UserStatus\Tests\Db;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\UserStatus\Db\UserStatus; use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper; use OCA\UserStatus\Db\UserStatusMapper;
use OCP\DB\Exception;
use Test\TestCase; use Test\TestCase;
class UserStatusMapperTest extends TestCase { class UserStatusMapperTest extends TestCase {
@ -147,7 +147,7 @@ class UserStatusMapperTest extends TestCase {
$userStatus2->setStatusTimestamp(6000); $userStatus2->setStatusTimestamp(6000);
$userStatus2->setIsUserDefined(false); $userStatus2->setIsUserDefined(false);
$this->expectException(UniqueConstraintViolationException::class); $this->expectException(Exception::class);
$this->mapper->insert($userStatus2); $this->mapper->insert($userStatus2);
} }

View File

@ -101,7 +101,7 @@ abstract class QBMapper {
->where( ->where(
$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType)) $qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
); );
$qb->execute(); $qb->executeUpdate();
return $entity; return $entity;
} }
@ -132,7 +132,7 @@ abstract class QBMapper {
$qb->setValue($column, $qb->createNamedParameter($value, $type)); $qb->setValue($column, $qb->createNamedParameter($value, $type));
} }
$qb->execute(); $qb->executeUpdate();
if ($entity->id === null) { if ($entity->id === null) {
// When autoincrement is used id is always an int // When autoincrement is used id is always an int
@ -208,7 +208,7 @@ abstract class QBMapper {
$qb->where( $qb->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id, $idType)) $qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
); );
$qb->execute(); $qb->executeUpdate();
return $entity; return $entity;
} }
@ -259,19 +259,19 @@ abstract class QBMapper {
* @since 14.0.0 * @since 14.0.0
*/ */
protected function findOneQuery(IQueryBuilder $query): array { protected function findOneQuery(IQueryBuilder $query): array {
$cursor = $query->execute(); $result = $query->executeQuery();
$row = $cursor->fetch(); $row = $result->fetch();
if ($row === false) { if ($row === false) {
$cursor->closeCursor(); $result->closeCursor();
$msg = $this->buildDebugMessage( $msg = $this->buildDebugMessage(
'Did expect one result but found none when executing', $query 'Did expect one result but found none when executing', $query
); );
throw new DoesNotExistException($msg); throw new DoesNotExistException($msg);
} }
$row2 = $cursor->fetch(); $row2 = $result->fetch();
$cursor->closeCursor(); $result->closeCursor();
if ($row2 !== false) { if ($row2 !== false) {
$msg = $this->buildDebugMessage( $msg = $this->buildDebugMessage(
'Did not expect more than one result when executing', $query 'Did not expect more than one result when executing', $query
@ -317,15 +317,15 @@ abstract class QBMapper {
* @since 14.0.0 * @since 14.0.0
*/ */
protected function findEntities(IQueryBuilder $query): array { protected function findEntities(IQueryBuilder $query): array {
$cursor = $query->execute(); $result = $query->executeQuery();
$entities = []; $entities = [];
while ($row = $cursor->fetch()) { while ($row = $result->fetch()) {
$entities[] = $this->mapRowToEntity($row); $entities[] = $this->mapRowToEntity($row);
} }
$cursor->closeCursor(); $result->closeCursor();
return $entities; return $entities;
} }