Can not lock tables because of doctrine internal aliases
Asked Answered
C

0

6

I am trying to execute this code :

$em->getConnection()->exec('LOCK TABLES Portfolio t0 WRITE, User u1_ READ);
$portfolio = $this->doctrine->getRepository('Portfolio')->findOneBy(array('user'=>$user->getId(), 'game'=>$game->getId()));
$assets = $this->doctrine->getRepository('Asset')->findBy(array('portfolio' => $portfolio, 'isActive' => 1));
$em->getConnection()->exec('UNLOCK TABLES;');

So when I execute this code I have this Error :

An exception occurred while executing 'SELECT t0.id AS id1 FROM Asset t0' SQLSTATE[HY000]: General error: 1100 Table 't0' was not locked with LOCK TABLES

I must give some explanation before asking the question.

  1. To do the the lock, we must use doctrine internal aliases (t0, u1_, ...) because doctrine queries findBy, findOneBy finaly use these aliases.
  2. In MySql, when we lock, we must lock all the tables that are queried within the LOCK and the UNLOCK statements.
  3. I got the above error because I did not locked the table Asset aliased t0 in my lock statement.
  4. I can not lock the table Asset with alias t0, because I already have an aliase t0 used for the table Portfolio.

So the question is, can I force doctrine to use a specific internal alias ?

Curtin answered 13/2, 2015 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.