Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3198' into develop
Browse files Browse the repository at this point in the history
Close #3198
  • Loading branch information
weierophinney committed Jan 7, 2014
2 parents a9709a5 + 277a3ea commit 73ddefd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions library/Zend/Db/Adapter/Driver/Pdo/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ protected function bindParametersFromContainer()
foreach ($parameters as $name => &$value) {
if (is_bool($value)) {
$type = \PDO::PARAM_BOOL;
} elseif (is_int($value)) {
$type = \PDO::PARAM_INT;
} else {
$type = \PDO::PARAM_STR;
}
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa

if ($parameterContainer) {
// create bottom part of query, with offset and limit using row_number
array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?');
$limitParamName = $driver->formatParameterName('limit');
$offsetParamName = $driver->formatParameterName('offset');
$offsetForSumParamName = $driver->formatParameterName('offsetForSum');
array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN '
. $offsetParamName . '+1 AND ' . $limitParamName . '+' . $offsetForSumParamName);
$parameterContainer->offsetSet('offset', $this->offset);
$parameterContainer->offsetSet('limit', $this->limit);
$parameterContainer->offsetSetReference('offsetForSum', 'offset');
Expand Down
19 changes: 13 additions & 6 deletions tests/ZendTest/Db/Sql/Platform/SqlServer/SelectDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ class SelectDecoratorTest extends \PHPUnit_Framework_TestCase
* @covers Zend\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset
* @dataProvider dataProvider
*/
public function testPrepareStatement(Select $select, $expectedSql, $expectedParams)
public function testPrepareStatement(Select $select, $expectedSql, $expectedParams, $notUsed, $expectedFormatParamCount)
{
$driver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$driver->expects($this->exactly($expectedFormatParamCount))->method('formatParameterName')->will($this->returnValue('?'));

// test
$adapter = $this->getMock(
'Zend\Db\Adapter\Adapter',
null,
array(
$this->getMock('Zend\Db\Adapter\Driver\DriverInterface'),
$driver,
new SqlServerPlatform()
)
);
Expand Down Expand Up @@ -72,30 +75,34 @@ public function dataProvider()
$expectedPrepareSql0 = 'SELECT [bar], [baz] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [baz], ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?';
$expectedParams0 = array('offset' => 10, 'limit' => 5, 'offsetForSum' => 10);
$expectedSql0 = 'SELECT [bar], [baz] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [baz], ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10';
$expectedFormatParamCount0 = 3;

$select1 = new Select;
$select1->from('foo')->columns(array('bar', 'bam' => 'baz'))->limit(5)->offset(10);
$expectedPrepareSql1 = 'SELECT [bar], [bam] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [bam], ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?';
$expectedParams1 = array('offset' => 10, 'limit' => 5, 'offsetForSum' => 10);
$expectedSql1 = 'SELECT [bar], [bam] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [bam], ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10';
$expectedFormatParamCount1 = 3;

$select2 = new Select;
$select2->from('foo')->order('bar')->limit(5)->offset(10);
$expectedPrepareSql2 = 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?';
$expectedParams2 = array('offset' => 10, 'limit' => 5, 'offsetForSum' => 10);
$expectedSql2 = 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10';
$expectedFormatParamCount2 = 3;

$select3 = new Select;
$select3->from('foo');
$expectedPrepareSql3 = 'SELECT [foo].* FROM [foo]';
$expectedParams3 = array();
$expectedSql3 = 'SELECT [foo].* FROM [foo]';
$expectedFormatParamCount3 = 0;

return array(
array($select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0),
array($select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1),
array($select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2),
array($select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3)
array($select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0, $expectedFormatParamCount0),
array($select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1, $expectedFormatParamCount1),
array($select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2, $expectedFormatParamCount2),
array($select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3, $expectedFormatParamCount3)
);
}

Expand Down

0 comments on commit 73ddefd

Please sign in to comment.