Commit 45e85624 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #509 from deeky666/fix-sql-anywhere-lock-hints

Fix table lock hints on SQL Anywhere
parents c4d4c5f2 e107b015
......@@ -60,26 +60,22 @@ class SQLAnywherePlatform extends AbstractPlatform
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
public function appendLockHint($fromClause, $lockMode)
{
switch (true) {
case $lockMode === LockMode::NONE:
$lockClause = ' WITH (NOLOCK)';
break;
return $fromClause . ' WITH (NOLOCK)';
case $lockMode === LockMode::PESSIMISTIC_READ:
$lockClause = ' WITH (UPDLOCK)';
break;
return $fromClause . ' WITH (UPDLOCK)';
case $lockMode === LockMode::PESSIMISTIC_WRITE:
$lockClause = ' WITH (XLOCK)';
break;
return $fromClause . ' WITH (XLOCK)';
default:
throw new \InvalidArgumentException('Invalid lock mode: ' . $lockMode);
return $fromClause;
}
return $fromClause . $lockClause;
}
/**
......
......@@ -220,29 +220,28 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
);
}
public function testAppendsLockHints()
/**
* @dataProvider getLockHints
*/
public function testAppendsLockHint($lockMode, $lockHint)
{
$fromClause = 'SELECT * FROM lock_hints';
$fromClause = 'FROM users';
$expectedResult = $fromClause . $lockHint;
$this->assertEquals(
$fromClause . ' WITH (NOLOCK)',
$this->_platform->appendLockHint($fromClause, LockMode::NONE)
);
$this->assertEquals(
$fromClause . ' WITH (UPDLOCK)',
$this->_platform->appendLockHint($fromClause, LockMode::PESSIMISTIC_READ)
);
$this->assertEquals(
$fromClause . ' WITH (XLOCK)',
$this->_platform->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)
);
$this->assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode));
}
public function testCannotAppendInvalidLockHint()
public function getLockHints()
{
$this->setExpectedException('\InvalidArgumentException');
$this->_platform->appendLockHint('SELECT * FROM lock_hints', 'invalid_lock_mode');
return array(
array(null, ''),
array(false, ''),
array(true, ''),
array(LockMode::NONE, ' WITH (NOLOCK)'),
array(LockMode::OPTIMISTIC, ''),
array(LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'),
array(LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'),
);
}
public function testHasCorrectMaxIdentifierLength()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment