Skip to content

Commit

Permalink
Fixing describing of table columns for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 19, 2010
1 parent 3f0c79f commit d0fc2fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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'));
Expand All @@ -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);

Expand Down

0 comments on commit d0fc2fd

Please sign in to comment.