From d0fc2fd1717725373d47f1ecc46cbfca137f8690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 19 Oct 2010 00:48:08 -0430 Subject: [PATCH] Fixing describing of table columns for postgres --- cake/libs/model/datasources/dbo/dbo_postgres.php | 6 +++--- .../libs/model/datasources/dbo/dbo_postgres.test.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 98ec313a469..f3bf33841df 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -199,15 +199,15 @@ function &describe(&$model) { foreach ($cols as $c) { $type = $c->type; - if (!empty($c->char_length)) { - $length = intval($c->char_length); - } elseif (!empty($c->oct_length)) { + if (!empty($c->oct_length) && $c->char_length === null) { if ($c->type == 'character varying') { $length = null; $type = 'text'; } else { $length = intval($c->oct_length); } + } elseif (!empty($c->char_length)) { + $length = intval($c->char_length); } else { $length = $this->length($c->type); } 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 ca73d487687..d8c3dadb7a6 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 @@ -556,12 +556,12 @@ public function testCakeSchema() { $db1 = ConnectionManager::getDataSource('test'); $db1->cacheSources = false; $db1->reconnect(array('persistent' => false)); - $db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' ( + $db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' ( id serial NOT NULL, "varchar" character varying(40) NOT NULL, "full_length" character varying NOT NULL, "timestamp" timestamp without time zone, - date date, + "date" date, CONSTRAINT test_data_types_pkey PRIMARY KEY (id) )'); $model = new Model(array('name' => 'Datatype', 'ds' => 'test')); @@ -570,21 +570,21 @@ public function testCakeSchema() { 'connection' => 'test', 'models' => array('Datatype') )); - $schema->tables = array('datatypes' => $result['tables']['datatypes']); + + $schema->tables = array('datatypes' => $result['tables']['missing']['datatypes']); $result = $db1->createSchema($schema, 'datatypes'); + $db1->rawQuery('DROP TABLE ' . $db1->fullTableName('datatypes')); $this->assertNoPattern('/timestamp DEFAULT/', $result); $this->assertPattern('/\"full_length\"\s*text\s.*,/', $result); $this->assertPattern('/timestamp\s*,/', $result); - $db1->query('DROP TABLE ' . $db1->fullTableName('datatypes')); - $db1->query($result); $result2 = $schema->read(array( 'connection' => 'test', 'models' => array('Datatype') )); - $schema->tables = array('datatypes' => $result2['tables']['datatypes']); + $schema->tables = array('datatypes' => $result2['tables']['missing']['datatypes']); $result2 = $db1->createSchema($schema, 'datatypes'); $this->assertEqual($result, $result2);