This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'turrsis-hotfix/db-create-temporary-table' into develop * turrsis-hotfix/db-create-temporary-table: Added hook to SqlServer decorator for DDL\CreateTable fix create temporary tables
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
library/Zend/Db/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Db\Sql\Platform\SqlServer\Ddl; | ||
|
||
use Zend\Db\Adapter\Platform\PlatformInterface; | ||
use Zend\Db\Sql\Ddl\CreateTable; | ||
use Zend\Db\Sql\Platform\PlatformDecoratorInterface; | ||
|
||
class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface | ||
{ | ||
/** | ||
* @var CreateTable | ||
*/ | ||
protected $createTable; | ||
|
||
/** | ||
* @param CreateTable $subject | ||
* @return self | ||
*/ | ||
public function setSubject($subject) | ||
{ | ||
$this->createTable = $subject; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param null|PlatformInterface $platform | ||
* @return string | ||
*/ | ||
public function getSqlString(PlatformInterface $platform = null) | ||
{ | ||
// localize variables | ||
foreach (get_object_vars($this->createTable) as $name => $value) { | ||
$this->{$name} = $value; | ||
} | ||
return parent::getSqlString($platform); | ||
} | ||
|
||
/** | ||
* @param PlatformInterface $adapterPlatform | ||
* @return array | ||
*/ | ||
protected function processTable(PlatformInterface $adapterPlatform = null) | ||
{ | ||
$ret = array(''); | ||
if ($this->isTemporary) { | ||
$table = '#'; | ||
} else { | ||
$table = ''; | ||
} | ||
$ret[] = $adapterPlatform->quoteIdentifier($table . ltrim($this->table, '#')); | ||
return $ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/ZendTest/Db/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Db\Sql\Platform\SqlServer\Ddl; | ||
|
||
use Zend\Db\Sql\Ddl\CreateTable; | ||
use Zend\Db\Sql\Platform\SqlServer\Ddl\CreateTableDecorator; | ||
use Zend\Db\Sql\Ddl\Column\Column; | ||
|
||
class CreateTableDecoratorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @covers Zend\Db\Sql\Platform\SqlServer\Ddl\CreateTableDecorator::getSqlString | ||
*/ | ||
public function testGetSqlString() | ||
{ | ||
$ctd = new CreateTableDecorator(); | ||
|
||
$ct = new CreateTable('foo'); | ||
$this->assertEquals("CREATE TABLE \"foo\" (\n)", $ctd->setSubject($ct)->getSqlString()); | ||
|
||
$ct = new CreateTable('foo', true); | ||
$this->assertEquals("CREATE TABLE \"#foo\" (\n)", $ctd->setSubject($ct)->getSqlString()); | ||
|
||
$ct = new CreateTable('foo'); | ||
$ct->addColumn(new Column('bar')); | ||
$this->assertEquals("CREATE TABLE \"foo\" (\n \"bar\" INTEGER NOT NULL\n)", $ctd->setSubject($ct)->getSqlString()); | ||
|
||
$ct = new CreateTable('foo', true); | ||
$ct->addColumn(new Column('bar')); | ||
$this->assertEquals("CREATE TABLE \"#foo\" (\n \"bar\" INTEGER NOT NULL\n)", $ctd->setSubject($ct)->getSqlString()); | ||
} | ||
} |