Adding fix for Ticket #2737, changed TRUNCATE to TRUNCATE TABLE

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5308 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-06-20 03:20:59 +00:00
parent 3ea80f7618
commit 9f5becbc33

View file

@ -52,41 +52,41 @@ class CakeTestFixture extends Object {
function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
$import = array();
if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) {
$import = am(array('records' => false), ife(is_array($this->import), $this->import, array()));
$import['model'] = ife(is_array($this->import), $this->import['model'], $this->import);
} else if (isset($this->import['table'])) {
$import = am(array('connection' => 'default', 'records' => false), $this->import);
}
if (isset($import['model']) && (class_exists($import['model']) || loadModel($import['model']))) {
$model =& new $import['model'];
$modelDb =& ConnectionManager::getDataSource($model->useDbConfig);
$info = $model->loadInfo();
$this->fields = array_combine(Set::extract($info->value, '{n}.name'), $info->value);
$this->fields[$model->primaryKey]['key'] = 'primary';
$this->primaryKey = array( $model->primaryKey );
} else if (isset($import['table'])) {
$model =& new stdClass();
$modelDb =& ConnectionManager::getDataSource($import['connection']);
$model->name = Inflector::camelize(Inflector::singularize($import['table']));
$model->table = $import['table'];
$model->tablePrefix = $modelDb->config['prefix'];
$info = $modelDb->describe($model);
$this->fields = array_combine(Set::extract($info, '{n}.name'), $info);
}
if ($import['records'] !== false && isset($model) && isset($modelDb)) {
$this->records = array();
$query = array(
'fields' => Set::extract($this->fields, '{n}.name'),
'table' => $modelDb->name($model->table),
@ -95,19 +95,19 @@ class CakeTestFixture extends Object {
'order' => null,
'limit' => null
);
foreach($query['fields'] as $index => $field) {
$query['fields'][$index] = $modelDb->name($query['alias']) . '.' . $modelDb->name($field);
}
$records = $modelDb->fetchAll($modelDb->buildStatement($query, $model), false, $model->name);
if ($records !== false && !empty($records)) {
$this->records = Set::extract($records, '{n}.' . $model->name);
}
}
}
if (!isset($this->table)) {
$this->table = Inflector::underscore(Inflector::pluralize($this->name));
}
@ -119,11 +119,11 @@ class CakeTestFixture extends Object {
if (isset($this->primaryKey) && !is_array($this->primaryKey)) {
$this->primaryKey = array( $this->primaryKey );
}
if (isset($this->primaryKey) && isset($this->fields[$this->primaryKey[0]])) {
$this->fields[$this->primaryKey[0]]['key'] = 'primary';
}
if (isset($this->fields)) {
foreach($this->fields as $index => $field) {
if (empty($field['default'])) {
@ -180,7 +180,7 @@ class CakeTestFixture extends Object {
$this->_create = $create;
}
return $this->_create;
}
/**
@ -206,7 +206,7 @@ class CakeTestFixture extends Object {
*/
function truncate() {
if (!isset($this->_truncate)) {
$this->_truncate = 'TRUNCATE ' . $this->db->name($this->db->config['prefix'] . $this->table);
$this->_truncate = 'TRUNCATE TABLE ' . $this->db->name($this->db->config['prefix'] . $this->table);
}
return $this->_truncate;
@ -249,7 +249,7 @@ class CakeTestFixture extends Object {
$this->_insert = $inserts;
}
return $this->_insert;
}
}