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

Commit

Permalink
PR #5538
Browse files Browse the repository at this point in the history
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
Ralph Schindler committed Nov 27, 2013
2 parents 2bebab9 + e6f774d commit cc9f6d0
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
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;
}
}
1 change: 1 addition & 0 deletions library/Zend/Db/Sql/Platform/SqlServer/SqlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class SqlServer extends AbstractPlatform
public function __construct(SelectDecorator $selectDecorator = null)
{
$this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator());
$this->setTypeDecorator('Zend\Db\Sql\Ddl\CreateTable', new Ddl\CreateTableDecorator());
}
}
7 changes: 7 additions & 0 deletions tests/ZendTest/Db/Sql/Ddl/CreateTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ public function testGetSqlString()
$ct = new CreateTable('foo');
$this->assertEquals("CREATE TABLE \"foo\" (\n)", $ct->getSqlString());

$ct = new CreateTable('foo', true);
$this->assertEquals("CREATE TEMPORARY TABLE \"foo\" (\n)", $ct->getSqlString());

$ct = new CreateTable('foo');
$ct->addColumn(new Column('bar'));
$this->assertEquals("CREATE TABLE \"foo\" (\n \"bar\" INTEGER NOT NULL\n)", $ct->getSqlString());

$ct = new CreateTable('foo', true);
$ct->addColumn(new Column('bar'));
$this->assertEquals("CREATE TEMPORARY TABLE \"foo\" (\n \"bar\" INTEGER NOT NULL\n)", $ct->getSqlString());
}
}
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());
}
}

0 comments on commit cc9f6d0

Please sign in to comment.