mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing issue with "DEFAULT NULL NULL" generated by buildColumn.
Making the tests pass by just changing the start and end quotes. Providing "created" values for CakeTestFixtureTestFixture Fixture. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8262 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f710ae7fbe
commit
ee8d12c939
4 changed files with 118 additions and 22 deletions
|
@ -211,9 +211,10 @@ class DboMssql extends DboSource {
|
|||
return $cache;
|
||||
}
|
||||
|
||||
$fields = false;
|
||||
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $this->fullTableName($model, false) . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $this->fullTableName($model, false) . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $this->fullTableName($model, false) . "'", false);
|
||||
$table = $this->fullTableName($model, false);
|
||||
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table . "'", false);
|
||||
|
||||
$fields = false;
|
||||
foreach ($cols as $column) {
|
||||
$field = $column[0]['Field'];
|
||||
$fields[$field] = array(
|
||||
|
@ -659,23 +660,11 @@ class DboMssql extends DboSource {
|
|||
* Generate a database-native column schema string
|
||||
*
|
||||
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
|
||||
* where options can be 'default', 'length', or 'key'.
|
||||
* where options can be 'default', 'length', or 'key'.
|
||||
* @return string
|
||||
*/
|
||||
function buildColumn($column) {
|
||||
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
||||
$null = (
|
||||
(isset($column['null']) && $column['null'] == true) ||
|
||||
(array_key_exists('default', $column) && $column['default'] === null) ||
|
||||
(array_keys($column) == array('type', 'name'))
|
||||
);
|
||||
$primaryKey = (isset($column['key']) && $column['key'] == 'primary');
|
||||
$stringKey = ($primaryKey && $column['type'] != 'integer');
|
||||
|
||||
if ($null && !$primaryKey) {
|
||||
$result .= " NULL";
|
||||
}
|
||||
return $result;
|
||||
return preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
||||
}
|
||||
/**
|
||||
* Format indexes for create table
|
||||
|
@ -723,7 +712,6 @@ class DboMssql extends DboSource {
|
|||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,9 +60,9 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
|
|||
* @var array
|
||||
*/
|
||||
var $records = array(
|
||||
array('name' => 'Gandalf'),
|
||||
array('name' => 'Captain Picard'),
|
||||
array('name' => 'Chewbacca')
|
||||
array('name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00')
|
||||
);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -43,6 +43,13 @@ class DboMssqlTestDb extends DboMssql {
|
|||
* @access public
|
||||
*/
|
||||
var $simulated = array();
|
||||
/**
|
||||
* simalate property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $simulate = true;
|
||||
/**
|
||||
* fetchAllResultsStack
|
||||
*
|
||||
|
@ -58,8 +65,12 @@ class DboMssqlTestDb extends DboMssql {
|
|||
* @return void
|
||||
*/
|
||||
function _execute($sql) {
|
||||
$this->simulated[] = $sql;
|
||||
return null;
|
||||
if ($this->simulate) {
|
||||
$this->simulated[] = $sql;
|
||||
return null;
|
||||
} else {
|
||||
return parent::_execute($sql);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* fetchAll method
|
||||
|
@ -203,6 +214,20 @@ class DboMssqlTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
var $db = null;
|
||||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $autoFixtures = false;
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.category');
|
||||
/**
|
||||
* Skip if cannot connect to mssql
|
||||
*
|
||||
|
@ -212,6 +237,26 @@ class DboMssqlTest extends CakeTestCase {
|
|||
$this->_initDb();
|
||||
$this->skipUnless($this->db->config['driver'] == 'mssql', '%s SQL Server connection not available');
|
||||
}
|
||||
/**
|
||||
* Make sure all fixtures tables are being created
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function start() {
|
||||
$this->db->simulate = false;
|
||||
parent::start();
|
||||
$this->db->simulate = true;
|
||||
}
|
||||
/**
|
||||
* Make sure all fixtures tables are being dropped
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function end() {
|
||||
$this->db->simulate = false;
|
||||
parent::end();
|
||||
$this->db->simulate = true;
|
||||
}
|
||||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
|
@ -330,6 +375,59 @@ class DboMssqlTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testBuildColumn
|
||||
*
|
||||
* @return unknown_type
|
||||
* @access public
|
||||
*/
|
||||
function testBuildColumn() {
|
||||
$column = array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[id] int IDENTITY (1, 1) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int DEFAULT 0 NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
// 'name' => 'type' format
|
||||
$column = array('name' => 'client_id', 'type' => 'integer');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int DEFAULT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) DEFAULT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) DEFAULT \'\'';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testUpdateAllSyntax method
|
||||
*
|
||||
|
@ -353,6 +451,7 @@ class DboMssqlTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
function testGetPrimaryKey() {
|
||||
// When param is a model
|
||||
$result = $this->db->getPrimaryKey($this->model);
|
||||
$this->assertEqual($result, 'id');
|
||||
|
||||
|
@ -361,6 +460,12 @@ class DboMssqlTest extends CakeTestCase {
|
|||
$this->model->setSchema($schema);
|
||||
$result = $this->db->getPrimaryKey($this->model);
|
||||
$this->assertNull($result);
|
||||
|
||||
// When param is a table name
|
||||
$this->db->simulate = false;
|
||||
$this->loadFixtures('Category');
|
||||
$result = $this->db->getPrimaryKey('categories');
|
||||
$this->assertEqual($result, 'id');
|
||||
}
|
||||
/**
|
||||
* testInsertMulti
|
||||
|
|
|
@ -1211,6 +1211,8 @@ class DboSourceTest extends CakeTestCase {
|
|||
|
||||
$this->testDb =& new DboTest($this->__config);
|
||||
$this->testDb->cacheSources = false;
|
||||
$this->testDb->startQuote = '`';
|
||||
$this->testDb->endQuote = '`';
|
||||
Configure::write('debug', 1);
|
||||
$this->debug = Configure::read('debug');
|
||||
$this->Model =& new TestModel();
|
||||
|
@ -1235,6 +1237,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testFieldDoubleEscaping() {
|
||||
$config = array_merge($this->__config, array('driver' => 'test'));
|
||||
$test =& ConnectionManager::create('quoteTest', $config);
|
||||
$test->simulated = array();
|
||||
|
||||
$this->Model =& new Article2(array('alias' => 'Article', 'ds' => 'quoteTest'));
|
||||
$this->Model->setDataSource('quoteTest');
|
||||
|
|
Loading…
Reference in a new issue