Commit 75dbc8c8 authored by romanb's avatar romanb

Several bugfixes for the export module (expecially pgsql).

parent 6348e5f7
...@@ -496,7 +496,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict ...@@ -496,7 +496,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} elseif (strstr($db_type, 'text')) { } elseif (strstr($dbType, 'text')) {
$type[] = 'clob'; $type[] = 'clob';
} }
if ($fixed !== false) { if ($fixed !== false) {
...@@ -545,7 +545,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict ...@@ -545,7 +545,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
$length = null; $length = null;
break; break;
default: default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$db_type); throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
} }
return array('type' => $type, return array('type' => $type,
......
...@@ -44,6 +44,7 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -44,6 +44,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
'date' => '1970-01-01', 'date' => '1970-01-01',
'clob' => '', 'clob' => '',
'blob' => '', 'blob' => '',
'string' => ''
); );
/** /**
...@@ -426,7 +427,7 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -426,7 +427,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table; $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
$fields = array(); $fields = array();
foreach (array_keys($definition['fields']) as $field) { foreach ($definition['fields'] as $field) {
$fields[] = $this->conn->quoteIdentifier($field); $fields[] = $this->conn->quoteIdentifier($field);
} }
$query .= ' (' . implode(', ', $fields) . ')'; $query .= ' (' . implode(', ', $fields) . ')';
...@@ -672,7 +673,7 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -672,7 +673,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
? null : $this->valid_default_values[$field['type']]; ? null : $this->valid_default_values[$field['type']];
if ($field['default'] === '' && if ($field['default'] === '' &&
($conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)) { ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)) {
$field['default'] = null; $field['default'] = null;
} }
} }
......
...@@ -283,5 +283,68 @@ class Doctrine_Export_Pgsql extends Doctrine_Export ...@@ -283,5 +283,68 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
return 'DROP SEQUENCE ' . $sequenceName; return 'DROP SEQUENCE ' . $sequenceName;
} }
/**
* Creates a table.
*
* @param unknown_type $name
* @param array $fields
* @param array $options
* @return unknown
*/
public function createTableSql($name, array $fields, array $options = array())
{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
}
if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table ' . $name);
}
$queryFields = $this->getFieldDeclarationList($fields);
if (isset($options['primary']) && ! empty($options['primary'])) {
$queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
$sql[] = $query;
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach($options['indexes'] as $index => $definition) {
$sql[] = $this->createIndexSql($name, $index, $definition);
}
}
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $k => $definition) {
if (is_array($definition)) {
$sql[] = $this->createForeignKeySql($name, $definition);
}
}
}
return $sql;
}
/**
* createForeignKeySql
*
* @param string $table name of the table on which the foreign key is to be created
* @param array $definition associative array that defines properties of the foreign key to be created.
* @return string
*/
public function createForeignKeySql($table, array $definition)
{
$table = $this->conn->quoteIdentifier($table);
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclaration($definition);
return $query;
}
} }
...@@ -88,10 +88,10 @@ class Doctrine_Export_Pgsql_TestCase extends Doctrine_UnitTestCase ...@@ -88,10 +88,10 @@ class Doctrine_Export_Pgsql_TestCase extends Doctrine_UnitTestCase
4 => 'CREATE TABLE foo_bar_record (fooid BIGINT, barid BIGINT, PRIMARY KEY(fooid, barid))', 4 => 'CREATE TABLE foo_bar_record (fooid BIGINT, barid BIGINT, PRIMARY KEY(fooid, barid))',
5 => 'CREATE TABLE foo (id BIGSERIAL, name VARCHAR(200) NOT NULL, parent_id BIGINT, local_foo BIGINT, PRIMARY KEY(id))', 5 => 'CREATE TABLE foo (id BIGSERIAL, name VARCHAR(200) NOT NULL, parent_id BIGINT, local_foo BIGINT, PRIMARY KEY(id))',
6 => 'CREATE TABLE bar (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))', 6 => 'CREATE TABLE bar (id BIGSERIAL, name VARCHAR(200), PRIMARY KEY(id))',
7 => 'ALTER TABLE foo_reference ADD CONSTRAINT FOREIGN KEY (foo1) REFERENCES foo(foo1, foo2) NOT DEFERRABLE INITIALLY IMMEDIATE', 7 => 'ALTER TABLE foo_reference ADD FOREIGN KEY (foo1) REFERENCES foo(id) NOT DEFERRABLE INITIALLY IMMEDIATE',
8 => 'ALTER TABLE foo_bar_record ADD CONSTRAINT FOREIGN KEY (fooId) REFERENCES foo(fooid, barid) NOT DEFERRABLE INITIALLY IMMEDIATE', 8 => 'ALTER TABLE foo_bar_record ADD FOREIGN KEY (fooId) REFERENCES foo(id) NOT DEFERRABLE INITIALLY IMMEDIATE',
9 => 'ALTER TABLE foo ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES foo(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE', 9 => 'ALTER TABLE foo ADD FOREIGN KEY (parent_id) REFERENCES foo(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE',
10 => 'ALTER TABLE foo ADD CONSTRAINT FOREIGN KEY (local_foo) REFERENCES foo_locally_owned(id) ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE', 10 => 'ALTER TABLE foo ADD FOREIGN KEY (local_foo) REFERENCES foo_locally_owned(id) ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE',
)); ));
} }
} }
......
...@@ -50,6 +50,14 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase ...@@ -50,6 +50,14 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase
$node2->getNode()->insertAsLastChildOf($node); $node2->getNode()->insertAsLastChildOf($node);
} }
public function testLftRgtValues()
{
$treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree();
$root = $treeMngr->fetchRoot();
$this->assertEqual(1, $root['lft']);
$this->assertEqual(4, $root['rgt']);
}
public function testGetDescendants() public function testGetDescendants()
{ {
$treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree();
......
...@@ -336,7 +336,7 @@ $test->addTestCase(new Doctrine_Search_TestCase()); ...@@ -336,7 +336,7 @@ $test->addTestCase(new Doctrine_Search_TestCase());
//$test->addTestCase(new Doctrine_AuditLog_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase());
//$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase()); $test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
// Cache tests // Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment