diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 815ed94d5..a6d389dcc 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -104,10 +104,10 @@ class DboPostgres extends DboSource { * @return boolean True if the database could be disconnected, else false */ function disconnect() { - if (is_resource($this->results)) { - pg_free_result($this->results); + if (is_resource($this->_result)) { + pg_free_result($this->_result); } - if (is_resource($this->connected)) { + if (is_resource($this->connection)) { $this->connected = !pg_close($this->connection); } else { $this->connected = false; @@ -176,6 +176,7 @@ class DboPostgres extends DboSource { if (isset($column[0])) { $c = $column[0]; + if (!empty($c['char_length'])) { $length = intval($c['char_length']); } elseif (!empty($c['oct_length'])) { @@ -191,7 +192,9 @@ class DboPostgres extends DboSource { ); if ($c['name'] == $model->primaryKey) { $fields[$c['name']]['key'] = 'primary'; - $fields[$c['name']]['length'] = 11; + if ($fields[$c['name']]['type'] !== 'string') { + $fields[$c['name']]['length'] = 11; + } } if ($fields[$c['name']]['default'] == 'NULL' || preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) { $fields[$c['name']]['default'] = null; @@ -558,20 +561,15 @@ class DboPostgres extends DboSource { * @return mixed Converted boolean value */ function boolean($data, $quote = true) { - $result = null; - - if ($data === true || $data === false) { - $result = $data; - } elseif (is_string($data) && !is_numeric($data)) { - if (strpos(strtolower($data), 't') !== false) { - $result = true; - } else { - $result = false; - } - } else { - $result = (bool)$data; + switch (true) { + case ($data === true || $data === false): + return $data; + case ($data === 't' || $data === 'f'): + return ($data === 't'); + default: + return (bool)$data; + break; } - return $result; } /** * Sets the database encoding diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 4074e64e9..b5dc135f1 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -264,7 +264,6 @@ class DboSource extends DataSource { * @return array The fetched row as an array */ function fetchRow($sql = null) { - if (!empty($sql) && is_string($sql) && strlen($sql) > 5) { if (!$this->execute($sql)) { return null; diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 964b8524e..832f4fad4 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -186,8 +186,12 @@ class DboPostgresTest extends CakeTestCase { } function testColumnParsing() { - var_export($this->db->isConnected()); - var_export($this->db->fetchAll("SELECT table_name as name FROM INFORMATION_SCHEMA.tables;")); + $this->assertEqual($this->db->column('text'), 'text'); + $this->assertEqual($this->db->column('date'), 'date'); + $this->assertEqual($this->db->column('boolean'), 'boolean'); + $this->assertEqual($this->db->column('character varying'), 'string'); + $this->assertEqual($this->db->column('time without time zone'), 'time'); + $this->assertEqual($this->db->column('timestamp without time zone'), 'datetime'); } } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 09789e994..719f8c252 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -138,7 +138,30 @@ class ModelTest extends CakeTestCase { function testHabtmFinderQuery() { $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); $this->Article =& new Article(); - $this->Article->hasAndBelongsToMany['Tag']['finderQuery'] = 'SELECT Tag.id, Tag.tag, ArticlesTag.article_id, ArticlesTag.tag_id FROM tags AS Tag JOIN articles_tags AS ArticlesTag ON (ArticlesTag.article_id = {$__cakeID__$} AND ArticlesTag.tag_id = Tag.id)'; + + $db =& ConnectionManager::getDataSource('test_suite'); + $sql = $db->buildStatement( + array( + 'fields' => $db->fields($this->Article->Tag, null, array('Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id')), + 'table' => 'tags', + 'alias' => 'Tag', + 'limit' => null, + 'offset' => null, + 'joins' => array(array( + 'alias' => 'ArticlesTag', + 'table' => 'articles_tags', + 'conditions' => array( + array("ArticlesTag.article_id" => '{$__cakeID__$}'), + array("ArticlesTag.tag_id" => '{$__cakeIdentifier[Tag.id]__$}') + ) + )), + 'conditions' => array(), + 'order' => null + ), + $this->Article + ); + + $this->Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; $result = $this->Article->find('first'); $expected = array(array('id' => '1', 'tag' => 'tag1'), array('id' => '2', 'tag' => 'tag2')); $this->assertEqual($result['Tag'], $expected);