From f06401c5632ff76b6173767279f901f04f81cde2 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 14 Nov 2008 02:00:02 +0000 Subject: [PATCH] Correcting regex that parses default values from schema in DboMssql, fixes #5748. Thanks Pixilation for the patch and test case. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7873 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mssql.php | 2 +- .../model/datasources/dbo/dbo_mssql.test.php | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index df69dea2b..88938ba3b 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -219,7 +219,7 @@ class DboMssql extends DboSource { $fields[$field] = array( 'type' => $this->column($column[0]['Type']), 'null' => (strtoupper($column[0]['Null']) == 'YES'), - 'default' => preg_replace("/^\('?([^']*)?'?\)$/", "$1", $column[0]['Default']), + 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column[0]['Default']), 'length' => intval($column[0]['Length']), 'key' => ($column[0]['Key'] == '1') ); diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index e7a1362cc..7a19d29be 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -44,6 +44,13 @@ class DboMssqlTestDb extends DboMssql { * @access public */ var $simulated = array(); +/** + * fetchAllResultsStack + * + * @var array + * @access public + */ + var $fetchAllResultsStack = array(); /** * execute method * @@ -55,6 +62,20 @@ class DboMssqlTestDb extends DboMssql { $this->simulated[] = $sql; return null; } +/** + * fetchAll method + * + * @param mixed $sql + * @access protected + * @return void + */ + function fetchAll($sql, $cache = true, $modelName = null) { + $result = parent::fetchAll($sql, $cache, $modelName); + if (!empty($this->fetchAllResultsStack)) { + return array_pop($this->fetchAllResultsStack); + } + return $result; + } /** * getLastQuery method * @@ -243,6 +264,40 @@ class DboMssqlTest extends CakeTestCase { $result = $this->db->getLastQuery(); $this->assertPattern('/^SELECT DISTINCT TOP 5/', $result); } +/** + * testDescribe method + * + * @access public + * @return void + */ + function testDescribe() { + $MssqlTableDescription = array( + 0 => array( + 0 => array( + 'Default' => '((0))', + 'Field' => 'count', + 'Key' => 0, + 'Length' => '4', + 'Null' => 'NO', + 'Type' => 'integer', + ) + ) + ); + $this->db->fetchAllResultsStack = array($MssqlTableDescription); + $dummyModel = $this->model; + $result = $this->db->describe($dummyModel); + $expected = array( + 'count' => array( + 'type' => 'integer', + 'null' => false, + 'default' => '0', + 'length' => 4 + ) + ); + $this->assertEqual($result, $expected); + } + + /** * tearDown method *