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
This commit is contained in:
nate 2008-11-14 02:00:02 +00:00
parent 9478b9a19f
commit f06401c563
2 changed files with 56 additions and 1 deletions

View file

@ -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')
);

View file

@ -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
*