cvs: pear /MDB2_Schema/MDB2 Schema.php
| From: | Lukas Smith | Date: | Fri, 14 Oct 2005 23:09:07 +0000 |
| Subject: | cvs: pear /MDB2_Schema/MDB2 Schema.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35559@lists.php.net to get a copy of this message | ||
lsmith Fri Oct 14 19:09:07 2005 EDT
Modified files:
/pear/MDB2_Schema/MDB2 Schema.php
Log:
- include definition for renamed fields in alterTable() calls
- split index and constraint API calls
http://cvs.php.net/diff.php/pear/MDB2_Schema/MDB2/Schema.php?r1=1.39&r2=1.40&ty=u
Index: pear/MDB2_Schema/MDB2/Schema.php
diff -u pear/MDB2_Schema/MDB2/Schema.php:1.39 pear/MDB2_Schema/MDB2/Schema.php:1.40
--- pear/MDB2_Schema/MDB2/Schema.php:1.39 Mon Oct 10 04:34:48 2005
+++ pear/MDB2_Schema/MDB2/Schema.php Fri Oct 14 19:09:03 2005
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Schema.php,v 1.39 2005/10/10 08:34:48 lsmith Exp $
+// $Id: Schema.php,v 1.40 2005/10/14 23:09:03 lsmith Exp $
//
require_once 'MDB2.php';
@@ -374,6 +374,7 @@
$this->warnings[] = $warning;
}
}
+ $index_definitions = array();
$indexes = $this->db->manager->listTableIndexes($table_name);
if (PEAR::isError($indexes)) {
return $indexes;
@@ -387,9 +388,28 @@
if (PEAR::isError($definition)) {
return $definition;
}
- $table_definition['indexes'][$index_name] = $definition;
+ $index_definitions[$index_name] = $definition;
}
}
+ $constraints = $this->db->manager->listTableConstraints($table_name);
+ if (PEAR::isError($constraints)) {
+ return $constraints;
+ }
+ if (is_array($constraints) && !empty($constraints)
+ && !array_key_exists('indexes', $table_definition)
+ ) {
+ $table_definition['indexes'] = array();
+ foreach ($constraints as $index_name) {
+ $definition =
$this->db->reverse->getTableConstraintsDefinition($table_name, $index_name);
+ if (PEAR::isError($definition)) {
+ return $definition;
+ }
+ $index_definitions[$index_name] = $definition;
+ }
+ }
+ if (!empty($index_definitions)) {
+ $table_definition['indexes'] = $index_definitions;
+ }
}
$sequences = $this->db->manager->listSequences();
@@ -432,7 +452,11 @@
foreach ($indexes as $index_name => $index) {
$errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_NOT_CAPABLE);
$this->db->expectError($errorcodes);
- $indexes = $this->db->manager->listTableIndexes($table_name);
+ if (array_key_exists('primary', $index)) {
+ $indexes = $this->db->manager->listTableConstraints($table_name);
+ } else {
+ $indexes = $this->db->manager->listTableIndexes($table_name);
+ }
$this->db->popExpect();
if (PEAR::isError($indexes)) {
if (!MDB2::isError($indexes, $errorcodes)) {
@@ -443,7 +467,11 @@
$this->db->debug('Index already exists: '.$index_name);
return MDB2_OK;
}
- $result = $this->db->manager->dropIndex($table_name, $index_name);
+ if (array_key_exists('primary', $index)) {
+ $result = $this->db->manager->dropConstraint($table_name,
$index_name);
+ } else {
+ $result = $this->db->manager->dropIndex($table_name, $index_name);
+ }
if (PEAR::isError($result)) {
return $result;
}
@@ -474,7 +502,11 @@
$this->db->manager->alterTable($table_name, $changes, false);
}
- $result = $this->db->manager->createIndex($table_name, $index_name, $index);
+ if (array_key_exists('primary', $index)) {
+ $result = $this->db->manager->createConstraint($table_name, $index_name,
$index);
+ } else {
+ $result = $this->db->manager->createIndex($table_name, $index_name,
$index);
+ }
if (PEAR::isError($result)) {
return $result;
}
@@ -891,7 +923,7 @@
}
if (array_key_exists($was_field_name, $previous_definition)) {
if ($was_field_name != $field_name) {
- $changes['rename'][$was_field_name] = array('name'
=> $field_name);
+ $changes['rename'][$was_field_name] = array('name'
=> $field_name, 'definition' => $field);
}
if (array_key_exists($was_field_name, $defined_fields)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_INVALID, null, null,
@@ -1270,11 +1302,11 @@
if (array_key_exists('change', $changes)) {
foreach ($changes['change'] as $index_name => $index) {
- $result = $this->db->manager->createIndex(
- $table_name,
- $index_name,
- $index
- );
+ if (array_key_exists('primary', $index)) {
+ $result = $this->db->manager->createConstraint($table_name,
$index_name, $index);
+ } else {
+ $result = $this->db->manager->createIndex($table_name, $index_name,
$index);
+ }
if (PEAR::isError($result)) {
return $result;
}
@@ -1283,11 +1315,11 @@
}
if (array_key_exists('add', $changes)) {
foreach ($changes['add'] as $index_name => $index) {
- $result = $this->db->manager->createIndex(
- $table_name,
- $index_name,
- $index
- );
+ if (array_key_exists('primary', $index)) {
+ $result = $this->db->manager->createConstraint($table_name,
$index_name, $index);
+ } else {
+ $result = $this->db->manager->createIndex($table_name, $index_name,
$index);
+ }
if (PEAR::isError($result)) {
return $result;
}
@@ -1296,10 +1328,11 @@
}
if (array_key_exists('remove', $changes)) {
foreach ($changes['remove'] as $index_name => $index) {
- $result = $this->db->manager->dropIndex(
- $table_name,
- $index_name
- );
+ if (array_key_exists('primary', $index)) {
+ $result = $this->db->manager->dropConstraint($table_name,
$index_name);
+ } else {
+ $result = $this->db->manager->dropIndex($table_name, $index_name);
+ }
if (PEAR::isError($result)) {
return $result;
}