Commit e107b015 authored by Steve Müller's avatar Steve Müller

fix table lock hints on SQL Anywhere

parent 2790ee79
...@@ -60,26 +60,22 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -60,26 +60,22 @@ class SQLAnywherePlatform extends AbstractPlatform
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @throws \InvalidArgumentException
*/ */
public function appendLockHint($fromClause, $lockMode) public function appendLockHint($fromClause, $lockMode)
{ {
switch (true) { switch (true) {
case $lockMode === LockMode::NONE: case $lockMode === LockMode::NONE:
$lockClause = ' WITH (NOLOCK)'; return $fromClause . ' WITH (NOLOCK)';
break;
case $lockMode === LockMode::PESSIMISTIC_READ: case $lockMode === LockMode::PESSIMISTIC_READ:
$lockClause = ' WITH (UPDLOCK)'; return $fromClause . ' WITH (UPDLOCK)';
break;
case $lockMode === LockMode::PESSIMISTIC_WRITE: case $lockMode === LockMode::PESSIMISTIC_WRITE:
$lockClause = ' WITH (XLOCK)'; return $fromClause . ' WITH (XLOCK)';
break;
default: default:
throw new \InvalidArgumentException('Invalid lock mode: ' . $lockMode); return $fromClause;
} }
return $fromClause . $lockClause;
} }
/** /**
......
...@@ -220,29 +220,28 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -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( $this->assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode));
$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)
);
} }
public function testCannotAppendInvalidLockHint() public function getLockHints()
{ {
$this->setExpectedException('\InvalidArgumentException'); return array(
array(null, ''),
$this->_platform->appendLockHint('SELECT * FROM lock_hints', 'invalid_lock_mode'); 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() 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