From 9d2819970d2a7a2c6c4e1ca8d0ef357a134fe19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 13 Apr 2010 01:08:31 -0430 Subject: [PATCH] Fixing schema generation for postgres. Now character varying without lenght is translated to "text", to avoid sql errors. Closes #564 --- cake/libs/model/datasources/dbo/dbo_postgres.php | 7 ++++++- .../cases/libs/model/datasources/dbo/dbo_postgres.test.php | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 18212d902..8ed4cefbc 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -231,7 +231,12 @@ class DboPostgres extends DboSource { if (!empty($c['char_length'])) { $length = intval($c['char_length']); } elseif (!empty($c['oct_length'])) { - $length = intval($c['oct_length']); + if ($c['type'] == 'character varying') { + $length = null; + $c['type'] = 'text'; + } else { + $length = intval($c['oct_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 8f69e9ec1..f67caa272 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 @@ -567,6 +567,7 @@ class DboPostgresTest extends CakeTestCase { $db1->query('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, CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id) @@ -579,7 +580,9 @@ class DboPostgresTest extends CakeTestCase { )); $schema->tables = array('datatypes' => $result['tables']['datatypes']); $result = $db1->createSchema($schema, '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'));