mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 06:56:24 +00:00
Adding support for Model.* syntax, which translates to a list of fields from Model.
Fixing buildColumn for null values. Fixing small containable merge, it was duplicating values, tests added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8265 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
9e1dec3ff3
commit
76e50ef625
8 changed files with 222 additions and 107 deletions
|
@ -313,7 +313,7 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
$option = 'conditions';
|
$option = 'conditions';
|
||||||
$val = $Model->{$name}->alias.'.'.$key;
|
$val = $Model->{$name}->alias.'.'.$key;
|
||||||
}
|
}
|
||||||
$children[$option] = isset($children[$option]) ? array_merge((array) $children[$option], (array) $val) : $val;
|
$children[$option] = is_array($val) ? $val : array($val);
|
||||||
$newChildren = null;
|
$newChildren = null;
|
||||||
if (!empty($name) && !empty($children[$key])) {
|
if (!empty($name) && !empty($children[$key])) {
|
||||||
$newChildren = $children[$key];
|
$newChildren = $children[$key];
|
||||||
|
|
|
@ -296,7 +296,8 @@ class DboMssql extends DboSource {
|
||||||
$fields = parent::fields($model, $alias, $fields, false);
|
$fields = parent::fields($model, $alias, $fields, false);
|
||||||
$count = count($fields);
|
$count = count($fields);
|
||||||
|
|
||||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
|
if ($count >= 1 && strpos($fields[0], 'COUNT(*)') === false) {
|
||||||
|
$result = array();
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$prepend = '';
|
$prepend = '';
|
||||||
|
|
||||||
|
@ -307,6 +308,19 @@ class DboMssql extends DboSource {
|
||||||
$fieldAlias = count($this->__fieldMappings);
|
$fieldAlias = count($this->__fieldMappings);
|
||||||
|
|
||||||
if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
|
if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
|
||||||
|
if (substr($fields[$i], -1) == '*') {
|
||||||
|
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
|
||||||
|
$build = explode('.', $fields[$i]);
|
||||||
|
$AssociatedModel = $model->{$build[0]};
|
||||||
|
} else {
|
||||||
|
$AssociatedModel = $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_fields = $this->fields($AssociatedModel, $AssociatedModel->alias, array_keys($AssociatedModel->schema()));
|
||||||
|
$result = array_merge($result, $_fields);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (strpos($fields[$i], '.') === false) {
|
if (strpos($fields[$i], '.') === false) {
|
||||||
$this->__fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i];
|
$this->__fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i];
|
||||||
$fieldName = $this->name($alias . '.' . $fields[$i]);
|
$fieldName = $this->name($alias . '.' . $fields[$i]);
|
||||||
|
@ -322,10 +336,12 @@ class DboMssql extends DboSource {
|
||||||
}
|
}
|
||||||
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
|
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
|
||||||
}
|
}
|
||||||
$fields[$i] = $prepend . $fields[$i];
|
$result[] = $prepend . $fields[$i];
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
return $fields;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generates and executes an SQL INSERT statement for given model, fields, and values.
|
* Generates and executes an SQL INSERT statement for given model, fields, and values.
|
||||||
|
@ -374,6 +390,9 @@ class DboMssql extends DboSource {
|
||||||
if (isset($fields[$model->primaryKey])) {
|
if (isset($fields[$model->primaryKey])) {
|
||||||
unset($fields[$model->primaryKey]);
|
unset($fields[$model->primaryKey]);
|
||||||
}
|
}
|
||||||
|
if (empty($fields)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return parent::update($model, array_keys($fields), array_values($fields), $conditions);
|
return parent::update($model, array_keys($fields), array_values($fields), $conditions);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -461,8 +480,8 @@ class DboMssql extends DboSource {
|
||||||
}
|
}
|
||||||
return $col;
|
return $col;
|
||||||
}
|
}
|
||||||
$col = str_replace(')', '', $real);
|
$col = str_replace(')', '', $real);
|
||||||
$limit = null;
|
$limit = null;
|
||||||
if (strpos($col, '(') !== false) {
|
if (strpos($col, '(') !== false) {
|
||||||
list($col, $limit) = explode('(', $col);
|
list($col, $limit) = explode('(', $col);
|
||||||
}
|
}
|
||||||
|
@ -664,11 +683,13 @@ class DboMssql extends DboSource {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function buildColumn($column) {
|
function buildColumn($column) {
|
||||||
$column = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
||||||
if (strpos($column, 'DEFAULT NULL') !== null) {
|
if (strpos($result, 'DEFAULT NULL') !== false) {
|
||||||
$column = str_replace('DEFAULT NULL', 'NULL', $column);
|
$result = str_replace('DEFAULT NULL', 'NULL', $result);
|
||||||
|
} else if (array_keys($column) == array('type', 'name')) {
|
||||||
|
$result .= ' NULL';
|
||||||
}
|
}
|
||||||
return $column;
|
return $result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Format indexes for create table
|
* Format indexes for create table
|
||||||
|
|
|
@ -1405,6 +1405,7 @@ class DboSource extends DataSource {
|
||||||
function _prepareUpdateFields(&$model, $fields, $quoteValues = true, $alias = false) {
|
function _prepareUpdateFields(&$model, $fields, $quoteValues = true, $alias = false) {
|
||||||
$quotedAlias = $this->startQuote . $model->alias . $this->endQuote;
|
$quotedAlias = $this->startQuote . $model->alias . $this->endQuote;
|
||||||
|
|
||||||
|
$updates = array();
|
||||||
foreach ($fields as $field => $value) {
|
foreach ($fields as $field => $value) {
|
||||||
if ($alias && strpos($field, '.') === false) {
|
if ($alias && strpos($field, '.') === false) {
|
||||||
$quoted = $model->escapeField($field);
|
$quoted = $model->escapeField($field);
|
||||||
|
|
|
@ -1982,70 +1982,76 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->User->find('all', array('contain' => array(
|
$orders = array(
|
||||||
'ArticleFeatured' => array(
|
'title DESC', 'title DESC, published DESC',
|
||||||
'title', 'order' => 'title DESC',
|
array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'),
|
||||||
'Featured' => array(
|
|
||||||
'category_id',
|
|
||||||
'Category' => 'name'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)));
|
|
||||||
$expected = array(
|
|
||||||
array(
|
|
||||||
'User' => array(
|
|
||||||
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
||||||
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
||||||
),
|
|
||||||
'ArticleFeatured' => array(
|
|
||||||
array(
|
|
||||||
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
|
||||||
'Featured' => array()
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
|
||||||
'Featured' => array(
|
|
||||||
'category_id' => 1, 'id' => 1,
|
|
||||||
'Category' => array(
|
|
||||||
'name' => 'Category 1'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'User' => array(
|
|
||||||
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
||||||
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
||||||
),
|
|
||||||
'ArticleFeatured' => array()
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'User' => array(
|
|
||||||
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
||||||
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
||||||
),
|
|
||||||
'ArticleFeatured' => array(
|
|
||||||
array(
|
|
||||||
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
|
||||||
'Featured' => array(
|
|
||||||
'category_id' => 1, 'id' => 2,
|
|
||||||
'Category' => array(
|
|
||||||
'name' => 'Category 1'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'User' => array(
|
|
||||||
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
||||||
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
||||||
),
|
|
||||||
'ArticleFeatured' => array()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
foreach ($orders as $order) {
|
||||||
|
$result = $this->User->find('all', array('contain' => array(
|
||||||
|
'ArticleFeatured' => array(
|
||||||
|
'title', 'order' => $order,
|
||||||
|
'Featured' => array(
|
||||||
|
'category_id',
|
||||||
|
'Category' => 'name'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)));
|
||||||
|
$expected = array(
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
||||||
|
),
|
||||||
|
'ArticleFeatured' => array(
|
||||||
|
array(
|
||||||
|
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
||||||
|
'Featured' => array()
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
||||||
|
'Featured' => array(
|
||||||
|
'category_id' => 1, 'id' => 1,
|
||||||
|
'Category' => array(
|
||||||
|
'name' => 'Category 1'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
||||||
|
),
|
||||||
|
'ArticleFeatured' => array()
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
||||||
|
),
|
||||||
|
'ArticleFeatured' => array(
|
||||||
|
array(
|
||||||
|
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
||||||
|
'Featured' => array(
|
||||||
|
'category_id' => 1, 'id' => 2,
|
||||||
|
'Category' => array(
|
||||||
|
'name' => 'Category 1'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||||
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
||||||
|
),
|
||||||
|
'ArticleFeatured' => array()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testFindThirdLevelNonReset method
|
* testFindThirdLevelNonReset method
|
||||||
|
@ -3225,7 +3231,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
'Comment.comment !=' => 'Crazy',
|
|
||||||
'Comment.published' => 'Y',
|
'Comment.published' => 'Y',
|
||||||
),
|
),
|
||||||
'contain' => 'User',
|
'contain' => 'User',
|
||||||
|
@ -3236,7 +3241,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$dummyResult = $this->Article->Comment->find('all', array(
|
$dummyResult = $this->Article->Comment->find('all', array(
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
'Comment.comment !=' => 'Silly',
|
|
||||||
'User.user' => 'mariano'
|
'User.user' => 'mariano'
|
||||||
),
|
),
|
||||||
'fields' => array('User.password'),
|
'fields' => array('User.password'),
|
||||||
|
@ -3320,7 +3324,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$initialOptions = array(
|
$initialOptions = array(
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
'Comment.comment' => '!= Crazy',
|
|
||||||
'Comment.published' => 'Y',
|
'Comment.published' => 'Y',
|
||||||
),
|
),
|
||||||
'contain' => 'User',
|
'contain' => 'User',
|
||||||
|
@ -3331,7 +3334,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$findOptions = array(
|
$findOptions = array(
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
'Comment.comment !=' => 'Silly',
|
|
||||||
'User.user' => 'mariano',
|
'User.user' => 'mariano',
|
||||||
),
|
),
|
||||||
'fields' => array('User.password'),
|
'fields' => array('User.password'),
|
||||||
|
@ -3409,7 +3411,8 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
'joinTable' => 'articles_tags',
|
'joinTable' => 'articles_tags',
|
||||||
'foreignKey' => 'article_id',
|
'foreignKey' => 'article_id',
|
||||||
'associationForeignKey' => 'tag_id',
|
'associationForeignKey' => 'tag_id',
|
||||||
'conditions' => 'LENGTH(ShortTag.tag) <= 3'
|
// LENGHT function mysql-only, using LIKE does almost the same
|
||||||
|
'conditions' => 'ShortTag.tag LIKE "???"'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -427,15 +427,18 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
|
$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$debug = Configure::read('debug');
|
// MSSQL trigger an error and stops the page even if the debug = 0
|
||||||
Configure::write('debug', 0);
|
if ($this->db->config['driver'] != 'mssql') {
|
||||||
|
$debug = Configure::read('debug');
|
||||||
|
Configure::write('debug', 0);
|
||||||
|
|
||||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
|
||||||
$this->assertEqual($result, array());
|
$this->assertEqual($result, array());
|
||||||
|
|
||||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
|
||||||
$this->assertEqual($result, array());
|
$this->assertEqual($result, array());
|
||||||
Configure::write('debug', $debug);
|
Configure::write('debug', $debug);
|
||||||
|
}
|
||||||
|
|
||||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
|
||||||
$expected = array(1 => null, 2 => null, 3 => null);
|
$expected = array(1 => null, 2 => null, 3 => null);
|
||||||
|
|
|
@ -115,6 +115,15 @@ class DboMssqlTestDb extends DboMssql {
|
||||||
function getPrimaryKey($model) {
|
function getPrimaryKey($model) {
|
||||||
return parent::_getPrimaryKey($model);
|
return parent::_getPrimaryKey($model);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* clearFieldMappings method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function clearFieldMappings() {
|
||||||
|
$this->__fieldMappings = array();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* MssqlTestModel class
|
* MssqlTestModel class
|
||||||
|
@ -163,6 +172,17 @@ class MssqlTestModel extends Model {
|
||||||
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||||
);
|
);
|
||||||
|
/**
|
||||||
|
* belongsTo property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $belongsTo = array(
|
||||||
|
'MssqlClientTestModel' => array(
|
||||||
|
'foreignKey' => 'client_id'
|
||||||
|
)
|
||||||
|
);
|
||||||
/**
|
/**
|
||||||
* find method
|
* find method
|
||||||
*
|
*
|
||||||
|
@ -200,6 +220,41 @@ class MssqlTestModel extends Model {
|
||||||
$this->_schema = $schema;
|
$this->_schema = $schema;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* MssqlClientTestModel class
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases.libs.model.datasources
|
||||||
|
*/
|
||||||
|
class MssqlClientTestModel extends Model {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'MssqlAssociatedTestModel'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'MssqlClientTestModel';
|
||||||
|
/**
|
||||||
|
* useTable property
|
||||||
|
*
|
||||||
|
* @var bool false
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $useTable = false;
|
||||||
|
/**
|
||||||
|
* _schema property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
var $_schema = array(
|
||||||
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
|
||||||
|
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||||
|
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||||
|
'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||||
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||||
|
);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* DboMssqlTest class
|
* DboMssqlTest class
|
||||||
*
|
*
|
||||||
|
@ -283,8 +338,22 @@ class DboMssqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testQuoting() {
|
function testQuoting() {
|
||||||
$result = $this->db->fields($this->model);
|
$expected = "1.2";
|
||||||
$expected = array(
|
$result = $this->db->value(1.2, 'float');
|
||||||
|
$this->assertIdentical($expected, $result);
|
||||||
|
|
||||||
|
$expected = "'1,2'";
|
||||||
|
$result = $this->db->value('1,2', 'float');
|
||||||
|
$this->assertIdentical($expected, $result);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testFields method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testFields() {
|
||||||
|
$fields = array(
|
||||||
'[MssqlTestModel].[id] AS [MssqlTestModel__0]',
|
'[MssqlTestModel].[id] AS [MssqlTestModel__0]',
|
||||||
'[MssqlTestModel].[client_id] AS [MssqlTestModel__1]',
|
'[MssqlTestModel].[client_id] AS [MssqlTestModel__1]',
|
||||||
'[MssqlTestModel].[name] AS [MssqlTestModel__2]',
|
'[MssqlTestModel].[name] AS [MssqlTestModel__2]',
|
||||||
|
@ -304,15 +373,32 @@ class DboMssqlTest extends CakeTestCase {
|
||||||
'[MssqlTestModel].[created] AS [MssqlTestModel__16]',
|
'[MssqlTestModel].[created] AS [MssqlTestModel__16]',
|
||||||
'CONVERT(VARCHAR(20), [MssqlTestModel].[updated], 20) AS [MssqlTestModel__17]'
|
'CONVERT(VARCHAR(20), [MssqlTestModel].[updated], 20) AS [MssqlTestModel__17]'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$result = $this->db->fields($this->model);
|
||||||
|
$expected = $fields;
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$expected = "1.2";
|
$this->db->clearFieldMappings();
|
||||||
$result = $this->db->value(1.2, 'float');
|
$result = $this->db->fields($this->model, null, 'MssqlTestModel.*');
|
||||||
$this->assertIdentical($expected, $result);
|
$expected = $fields;
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$expected = "'1,2'";
|
$this->db->clearFieldMappings();
|
||||||
$result = $this->db->value('1,2', 'float');
|
$result = $this->db->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
|
||||||
$this->assertIdentical($expected, $result);
|
$expected = array_merge($fields, array(
|
||||||
|
'[AnotherModel].[id] AS [AnotherModel__18]',
|
||||||
|
'[AnotherModel].[name] AS [AnotherModel__19]'));
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$this->db->clearFieldMappings();
|
||||||
|
$result = $this->db->fields($this->model, null, array('*', 'MssqlClientTestModel.*'));
|
||||||
|
$expected = array_merge($fields, array(
|
||||||
|
'[MssqlClientTestModel].[id] AS [MssqlClientTestModel__18]',
|
||||||
|
'[MssqlClientTestModel].[name] AS [MssqlClientTestModel__19]',
|
||||||
|
'[MssqlClientTestModel].[email] AS [MssqlClientTestModel__20]',
|
||||||
|
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[created], 20) AS [MssqlClientTestModel__21]',
|
||||||
|
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[updated], 20) AS [MssqlClientTestModel__22]'));
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testDistinctFields method
|
* testDistinctFields method
|
||||||
|
@ -392,17 +478,22 @@ class DboMssqlTest extends CakeTestCase {
|
||||||
$expected = '[client_id] int DEFAULT 0 NOT NULL';
|
$expected = '[client_id] int DEFAULT 0 NOT NULL';
|
||||||
$this->assertEqual($result, $expected);
|
$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);
|
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
|
||||||
$result = $this->db->buildColumn($column);
|
$result = $this->db->buildColumn($column);
|
||||||
$expected = '[client_id] int NULL';
|
$expected = '[client_id] int NULL';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
// 'name' => 'type' format for columns
|
||||||
|
$column = array('type' => 'integer', 'name' => 'client_id');
|
||||||
|
$result = $this->db->buildColumn($column);
|
||||||
|
$expected = '[client_id] int NULL';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$column = array('type' => 'string', 'name' => 'name');
|
||||||
|
$result = $this->db->buildColumn($column);
|
||||||
|
$expected = '[name] varchar(255) NULL';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$column = array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255');
|
$column = array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255');
|
||||||
$result = $this->db->buildColumn($column);
|
$result = $this->db->buildColumn($column);
|
||||||
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
|
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
|
||||||
|
|
|
@ -149,12 +149,8 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAutoSaveUuid() {
|
function testAutoSaveUuid() {
|
||||||
// SQLite does not support non-integer primary keys, and SQL Server
|
// SQLite does not support non-integer primary keys
|
||||||
// is still having problems with custom PK's
|
$this->skipIf($this->db->config['driver'] == 'sqlite');
|
||||||
$this->skipIf(
|
|
||||||
$this->db->config['driver'] == 'sqlite'
|
|
||||||
|| $this->db->config['driver'] == 'mssql'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->loadFixtures('Uuid');
|
$this->loadFixtures('Uuid');
|
||||||
$TestModel =& new Uuid();
|
$TestModel =& new Uuid();
|
||||||
|
|
2
cake/tests/fixtures/uuid_tree_fixture.php
vendored
2
cake/tests/fixtures/uuid_tree_fixture.php
vendored
|
@ -46,7 +46,7 @@ class UuidTreeFixture extends CakeTestFixture {
|
||||||
var $fields = array(
|
var $fields = array(
|
||||||
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
|
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
|
||||||
'name' => array('type' => 'string','null' => false),
|
'name' => array('type' => 'string','null' => false),
|
||||||
'parent_id' => array('type' => 'string', 'length' => 36),
|
'parent_id' => array('type' => 'string', 'length' => 36, 'null' => true),
|
||||||
'lft' => array('type' => 'integer','null' => false),
|
'lft' => array('type' => 'integer','null' => false),
|
||||||
'rght' => array('type' => 'integer','null' => false)
|
'rght' => array('type' => 'integer','null' => false)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue