lock alias mysql

This commit is contained in:
Yuri Kuznetsov
2023-03-01 13:04:50 +02:00
parent c72bcc365a
commit 656ff76a8d
2 changed files with 27 additions and 2 deletions
@@ -39,7 +39,9 @@ class MysqlQueryComposer extends BaseQueryComposer
{
$params = $query->getRaw();
$table = $this->toDb($this->sanitize($params['table']));
$entityType = $this->sanitize($params['table']);
$table = $this->toDb($entityType);
$mode = $params['mode'];
@@ -60,6 +62,13 @@ class MysqlQueryComposer extends BaseQueryComposer
$sql .= $modeMap[$mode];
if (str_contains($table, '_')) {
// MySQL has an issue that aliased tables must be locked with alias.
$sql .= ", " .
$this->quoteIdentifier($table) . " AS " .
$this->quoteIdentifier(lcfirst($entityType)) . " " . $modeMap[$mode];
}
return $sql;
}
+17 -1
View File
@@ -2668,7 +2668,7 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expectedSql, $sql);
}
public function testLockTableExclusive()
public function testLockTableExclusive1()
{
$builder = new LockTableBuilder();
@@ -2684,6 +2684,22 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expectedSql, $sql);
}
public function testLockTableExclusive2()
{
$builder = new LockTableBuilder();
$query = $builder
->table('EntityTeam')
->inExclusiveMode()
->build();
$sql = $this->query->compose($query);
$expectedSql = "LOCK TABLES `entity_team` WRITE, `entity_team` AS `entityTeam` WRITE";
$this->assertEquals($expectedSql, $sql);
}
public function testFunctionConverter1(): void
{
$functionConverter = $this->createMock(FunctionConverter::class);