mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
More Postgres abstraction/emulation fixes
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6387 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d3e790a27a
commit
4c6bbaffff
3 changed files with 29 additions and 16 deletions
|
@ -184,12 +184,18 @@ class DboPostgres extends DboSource {
|
||||||
$fields[$c['name']] = array(
|
$fields[$c['name']] = array(
|
||||||
'type' => $this->column($c['type']),
|
'type' => $this->column($c['type']),
|
||||||
'null' => ($c['null'] == 'NO' ? false : true),
|
'null' => ($c['null'] == 'NO' ? false : true),
|
||||||
'default' => preg_replace('/::.*/', '', $c['default']),
|
'default' => preg_replace("/^'(.*)'$/", "$1", preg_replace('/::.*/', '', $c['default'])),
|
||||||
'length' => $length
|
'length' => $length
|
||||||
);
|
);
|
||||||
if (preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) {
|
if ($c['name'] == $model->primaryKey) {
|
||||||
$this->_sequenceMap[$table][$c['name']] = $seq[1];
|
$fields[$c['name']]['key'] = 'primary';
|
||||||
|
$fields[$c['name']]['length'] = 11;
|
||||||
|
}
|
||||||
|
if ($fields[$c['name']]['default'] == 'NULL' || preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) {
|
||||||
$fields[$c['name']]['default'] = null;
|
$fields[$c['name']]['default'] = null;
|
||||||
|
if (!empty($seq) && isset($seq[1])) {
|
||||||
|
$this->_sequenceMap[$table][$c['name']] = $seq[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -515,6 +521,9 @@ class DboPostgres extends DboSource {
|
||||||
if (strpos($col, 'timestamp') !== false) {
|
if (strpos($col, 'timestamp') !== false) {
|
||||||
return 'datetime';
|
return 'datetime';
|
||||||
}
|
}
|
||||||
|
if (strpos($col, 'time') === 0) {
|
||||||
|
return 'time';
|
||||||
|
}
|
||||||
if ($col == 'inet') {
|
if ($col == 'inet') {
|
||||||
return('inet');
|
return('inet');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1723,15 +1723,15 @@ class Model extends Overloadable {
|
||||||
$valuePath = "{n}.{$this->alias}.{$this->displayField}";
|
$valuePath = "{n}.{$this->alias}.{$this->displayField}";
|
||||||
$groupPath = null;
|
$groupPath = null;
|
||||||
} else {
|
} else {
|
||||||
if (!is_array($query['fields']) ) {
|
if (!is_array($query['fields'])) {
|
||||||
$query['fields'] = String::tokenize($query['fields']);
|
$query['fields'] = String::tokenize($query['fields']);
|
||||||
}
|
}
|
||||||
if (count($query['fields']) == 1 ) {
|
if (count($query['fields']) == 1) {
|
||||||
$keyPath = "{n}.{$this->alias}.{$this->primaryKey}";
|
$keyPath = "{n}.{$this->alias}.{$this->primaryKey}";
|
||||||
$valuePath = '{n}.' . $query['fields'][0];
|
$valuePath = '{n}.' . $query['fields'][0];
|
||||||
$groupPath = null;
|
$groupPath = null;
|
||||||
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]);
|
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]);
|
||||||
} elseif (count($query['fields']) == 3 ) {
|
} elseif (count($query['fields']) == 3) {
|
||||||
$keyPath = '{n}.' . $query['fields'][0];
|
$keyPath = '{n}.' . $query['fields'][0];
|
||||||
$valuePath = '{n}.' . $query['fields'][1];
|
$valuePath = '{n}.' . $query['fields'][1];
|
||||||
$groupPath = '{n}.' . $query['fields'][2];
|
$groupPath = '{n}.' . $query['fields'][2];
|
||||||
|
|
|
@ -627,14 +627,15 @@ class ModelTest extends CakeTestCase {
|
||||||
$ts = date('Y-m-d H:i:s');
|
$ts = date('Y-m-d H:i:s');
|
||||||
$this->model->save();
|
$this->model->save();
|
||||||
|
|
||||||
|
$this->model->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC';
|
||||||
$result = $this->model->findById(1);
|
$result = $this->model->findById(1);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $ts),
|
'Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $ts),
|
||||||
'SomethingElse' => array(
|
'SomethingElse' => array(
|
||||||
array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
|
|
||||||
'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')),
|
|
||||||
array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
|
array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
|
||||||
'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '1')),
|
'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '1')),
|
||||||
|
array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
|
||||||
|
'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')),
|
||||||
array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
|
array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
|
||||||
'JoinThing' => array('doomed' => null, 'something_id' => '1', 'something_else_id' => '3'))));
|
'JoinThing' => array('doomed' => null, 'something_id' => '1', 'something_else_id' => '3'))));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -737,7 +738,6 @@ class ModelTest extends CakeTestCase {
|
||||||
$result = $this->model->create();
|
$result = $this->model->create();
|
||||||
$expected = array('Article' => array('published' => 'N'));
|
$expected = array('Article' => array('published' => 'N'));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testCreationOfEmptyRecord() {
|
function testCreationOfEmptyRecord() {
|
||||||
|
@ -1364,8 +1364,13 @@ class ModelTest extends CakeTestCase {
|
||||||
array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')))));
|
array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')))));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @todo Figure out why Featured is not getting truncated properly
|
||||||
|
*/
|
||||||
function testRecursiveFindAll() {
|
function testRecursiveFindAll() {
|
||||||
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
|
$db->truncate(new Featured());
|
||||||
|
|
||||||
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'Featured', 'Category');
|
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'Featured', 'Category');
|
||||||
$this->model =& new Article();
|
$this->model =& new Article();
|
||||||
|
|
||||||
|
@ -1429,7 +1434,7 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->Featured->bindModel(array(
|
$this->Featured->bindModel(array(
|
||||||
'belongsTo' => array(
|
'belongsTo' => array(
|
||||||
'ArticleFeatured' => array(
|
'ArticleFeatured' => array(
|
||||||
'conditions' => 'ArticleFeatured.published = \'Y\'',
|
'conditions' => "ArticleFeatured.published = 'Y'",
|
||||||
'fields' => 'id, title, user_id, published'
|
'fields' => 'id, title, user_id, published'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -1990,8 +1995,7 @@ class ModelTest extends CakeTestCase {
|
||||||
uses('xml');
|
uses('xml');
|
||||||
}
|
}
|
||||||
$Article = new Article();
|
$Article = new Article();
|
||||||
$result = $Article->save(new Xml('<article title="test xml"/>'));
|
$this->assertTrue($Article->save(new Xml('<article title="test xml" user_id="5" />')));
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$results = $Article->find(array('Article.title' => 'test xml'));
|
$results = $Article->find(array('Article.title' => 'test xml'));
|
||||||
$this->assertTrue($results);
|
$this->assertTrue($results);
|
||||||
|
@ -2298,10 +2302,10 @@ class ModelTest extends CakeTestCase {
|
||||||
array('title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'author_id' => 2)
|
array('title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'author_id' => 2)
|
||||||
));
|
));
|
||||||
|
|
||||||
$result = $this->model->find('all', array('recursive' => -1));
|
$result = $this->model->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array('Post' => array('id' => '6', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)),
|
array('Post' => array('id' => '5', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)),
|
||||||
array('Post' => array('id' => '5', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts))
|
array('Post' => array('id' => '6', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts))
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue