cvs: pear /MDB2_Schema/MDB2 Schema.php /MDB2_Schema/MDB2/Schema Parser2.php
| From: | Igor Feghali | Date: | Mon, 20 Aug 2007 03:15:42 +0000 |
| Subject: | cvs: pear /MDB2_Schema/MDB2 Schema.php /MDB2_Schema/MDB2/Schema Parser2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-48470@lists.php.net to get a copy of this message | ||
ifeghali Mon Aug 20 03:15:42 2007 UTC
Modified files:
/pear/MDB2_Schema/MDB2 Schema.php
/pear/MDB2_Schema/MDB2/Schema Parser2.php
Log:
- now validating foreign key referencing fields
- now validating foreign key referenced fields
- now validating index fields
http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema.php?r1=1.115&r2=1.116&diff_format=u Index: pear/MDB2_Schema/MDB2/Schema.php diff -u pear/MDB2_Schema/MDB2/Schema.php:1.115 pear/MDB2_Schema/MDB2/Schema.php:1.116 --- pear/MDB2_Schema/MDB2/Schema.php:1.115 Fri Aug 17 00:58:05 2007 +++ pear/MDB2_Schema/MDB2/Schema.php Mon Aug 20 03:15:41 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Schema.php,v 1.115 2007/08/17 00:58:05 ifeghali Exp $ +// $Id: Schema.php,v 1.116 2007/08/20 03:15:41 ifeghali Exp $ // require_once 'MDB2.php'; @@ -480,6 +480,7 @@ } } + $keys = array(); $indexes = $this->db->manager->listTableIndexes($table_name); if (PEAR::isError($indexes)) { return $indexes; @@ -497,16 +498,7 @@ return $definition; } - /** - * The first parameter is used to verify if there are duplicated - * indices which we can guarantee that won't happen when reverse engineering - */ - $result = $val->validateIndex(array(), $definition, $index_name); - if (PEAR::isError($result)) { - return $result; - } - - $table_definition['indexes'][$index_name] = $definition; + $keys[$index_name] = $definition; } } @@ -527,31 +519,74 @@ return $definition; } - if (array_key_exists('foreign', $definition) - && $definition['foreign'] - ) { + $keys[$constraint_name] = $definition; + } + } + + foreach ($keys as $key_name => $definition) { + if (array_key_exists('foreign', $definition) + && $definition['foreign'] + ) { + /** + * The first parameter is used to verify if there are duplicated + * foreign keys which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateConstraint(array(), $definition, $key_name); + if (PEAR::isError($result)) { + return $result; + } + + foreach ($definition['fields'] as $field_name => $field) { /** * The first parameter is used to verify if there are duplicated - * foreign keys which we can guarantee that won't happen when reverse engineering + * referencing fields which we can guarantee that won't happen when reverse engineering */ - $result = $val->validateConstraint(array(), $definition, $constraint_name); + $result = $val->validateConstraintField(array(), $field_name); if (PEAR::isError($result)) { return $result; } - $table_definition['constraints'][$constraint_name] = $definition; - } else { + $definition['fields'][$field_name] = ''; + } + + foreach ($definition['references']['fields'] as $field_name => $field) { /** * The first parameter is used to verify if there are duplicated - * foreign keys which we can guarantee that won't happen when reverse engineering + * referenced fields which we can guarantee that won't happen when reverse engineering */ - $result = $val->validateIndex(array(), $definition, $constraint_name); + $result = $val->validateConstraintReferencedField(array(), $field_name); if (PEAR::isError($result)) { return $result; } - $table_definition['indexes'][$constraint_name] = $definition; + $definition['references']['fields'][$field_name] = ''; + } + + $table_definition['constraints'][$key_name] = $definition; + } else { + /** + * The first parameter is used to verify if there are duplicated + * indices which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateIndex(array(), $definition, $key_name); + if (PEAR::isError($result)) { + return $result; } + + foreach ($definition['fields'] as $field_name => $field) { + /** + * The first parameter is used to verify if there are duplicated + * index fields which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateIndexField(array(), $field, $field_name); + if (PEAR::isError($result)) { + return $result; + } + + $definition['fields'][$field_name] = $field; + } + + $table_definition['indexes'][$key_name] = $definition; } } http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema/Parser2.php?r1=1.6&r2=1.7&diff_format=u Index: pear/MDB2_Schema/MDB2/Schema/Parser2.php diff -u pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.6 pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.7 --- pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.6 Fri Aug 17 01:02:28 2007 +++ pear/MDB2_Schema/MDB2/Schema/Parser2.php Mon Aug 20 03:15:41 2007 @@ -42,7 +42,7 @@ // | Author: Igor Feghali <ifeghali@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Parser2.php,v 1.6 2007/08/17 01:02:28 ifeghali Exp $ +// $Id: Parser2.php,v 1.7 2007/08/20 03:15:41 ifeghali Exp $ // require_once 'XML/Unserializer.php'; @@ -334,6 +334,12 @@ if (!empty($field['sorting'])) { $this->field['sorting'] = $field['sorting']; } + + $result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->index['fields'][$this->field_name] = $this->field; } } @@ -386,6 +392,11 @@ } if (!empty($constraint['field']) && is_array($constraint['field'])) { foreach($constraint['field'] as $field) { + $result = $this->val->validateConstraintField($this->constraint['fields'], $field); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->constraint['fields'][$field] = ''; } } @@ -401,6 +412,11 @@ if (!empty($constraint['references']['field']) && is_array($constraint['references']['field'])) { foreach($constraint['references']['field'] as $field) { + $result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $field); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->constraint['references']['fields'][$field] = ''; } }
http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema.php?r1=1.115&r2=1.116&diff_format=u Index: pear/MDB2_Schema/MDB2/Schema.php diff -u pear/MDB2_Schema/MDB2/Schema.php:1.115 pear/MDB2_Schema/MDB2/Schema.php:1.116 --- pear/MDB2_Schema/MDB2/Schema.php:1.115 Fri Aug 17 00:58:05 2007 +++ pear/MDB2_Schema/MDB2/Schema.php Mon Aug 20 03:15:41 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Schema.php,v 1.115 2007/08/17 00:58:05 ifeghali Exp $ +// $Id: Schema.php,v 1.116 2007/08/20 03:15:41 ifeghali Exp $ // require_once 'MDB2.php'; @@ -480,6 +480,7 @@ } } + $keys = array(); $indexes = $this->db->manager->listTableIndexes($table_name); if (PEAR::isError($indexes)) { return $indexes; @@ -497,16 +498,7 @@ return $definition; } - /** - * The first parameter is used to verify if there are duplicated - * indices which we can guarantee that won't happen when reverse engineering - */ - $result = $val->validateIndex(array(), $definition, $index_name); - if (PEAR::isError($result)) { - return $result; - } - - $table_definition['indexes'][$index_name] = $definition; + $keys[$index_name] = $definition; } } @@ -527,31 +519,74 @@ return $definition; } - if (array_key_exists('foreign', $definition) - && $definition['foreign'] - ) { + $keys[$constraint_name] = $definition; + } + } + + foreach ($keys as $key_name => $definition) { + if (array_key_exists('foreign', $definition) + && $definition['foreign'] + ) { + /** + * The first parameter is used to verify if there are duplicated + * foreign keys which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateConstraint(array(), $definition, $key_name); + if (PEAR::isError($result)) { + return $result; + } + + foreach ($definition['fields'] as $field_name => $field) { /** * The first parameter is used to verify if there are duplicated - * foreign keys which we can guarantee that won't happen when reverse engineering + * referencing fields which we can guarantee that won't happen when reverse engineering */ - $result = $val->validateConstraint(array(), $definition, $constraint_name); + $result = $val->validateConstraintField(array(), $field_name); if (PEAR::isError($result)) { return $result; } - $table_definition['constraints'][$constraint_name] = $definition; - } else { + $definition['fields'][$field_name] = ''; + } + + foreach ($definition['references']['fields'] as $field_name => $field) { /** * The first parameter is used to verify if there are duplicated - * foreign keys which we can guarantee that won't happen when reverse engineering + * referenced fields which we can guarantee that won't happen when reverse engineering */ - $result = $val->validateIndex(array(), $definition, $constraint_name); + $result = $val->validateConstraintReferencedField(array(), $field_name); if (PEAR::isError($result)) { return $result; } - $table_definition['indexes'][$constraint_name] = $definition; + $definition['references']['fields'][$field_name] = ''; + } + + $table_definition['constraints'][$key_name] = $definition; + } else { + /** + * The first parameter is used to verify if there are duplicated + * indices which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateIndex(array(), $definition, $key_name); + if (PEAR::isError($result)) { + return $result; } + + foreach ($definition['fields'] as $field_name => $field) { + /** + * The first parameter is used to verify if there are duplicated + * index fields which we can guarantee that won't happen when reverse engineering + */ + $result = $val->validateIndexField(array(), $field, $field_name); + if (PEAR::isError($result)) { + return $result; + } + + $definition['fields'][$field_name] = $field; + } + + $table_definition['indexes'][$key_name] = $definition; } } http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema/Parser2.php?r1=1.6&r2=1.7&diff_format=u Index: pear/MDB2_Schema/MDB2/Schema/Parser2.php diff -u pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.6 pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.7 --- pear/MDB2_Schema/MDB2/Schema/Parser2.php:1.6 Fri Aug 17 01:02:28 2007 +++ pear/MDB2_Schema/MDB2/Schema/Parser2.php Mon Aug 20 03:15:41 2007 @@ -42,7 +42,7 @@ // | Author: Igor Feghali <ifeghali@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Parser2.php,v 1.6 2007/08/17 01:02:28 ifeghali Exp $ +// $Id: Parser2.php,v 1.7 2007/08/20 03:15:41 ifeghali Exp $ // require_once 'XML/Unserializer.php'; @@ -334,6 +334,12 @@ if (!empty($field['sorting'])) { $this->field['sorting'] = $field['sorting']; } + + $result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->index['fields'][$this->field_name] = $this->field; } } @@ -386,6 +392,11 @@ } if (!empty($constraint['field']) && is_array($constraint['field'])) { foreach($constraint['field'] as $field) { + $result = $this->val->validateConstraintField($this->constraint['fields'], $field); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->constraint['fields'][$field] = ''; } } @@ -401,6 +412,11 @@ if (!empty($constraint['references']['field']) && is_array($constraint['references']['field'])) { foreach($constraint['references']['field'] as $field) { + $result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $field); + if (PEAR::isError($result)) { + return $this->raiseError($result->getUserinfo()); + } + $this->constraint['references']['fields'][$field] = ''; } }