cvs: pear /MDB2_Schema/MDB2/Schema Parser.php
| From: | Helgi �ormar �orbj�rnsson | Date: | Tue, 18 Oct 2005 17:58:28 +0000 |
| Subject: | cvs: pear /MDB2_Schema/MDB2/Schema Parser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35676@lists.php.net to get a copy of this message | ||
dufuz Tue Oct 18 13:58:28 2005 EDT
Modified files:
/pear/MDB2_Schema/MDB2/Schema Parser.php
Log:
Silent a "error" when there is auto increment and a primary key index defined on the
same field, since auto increment implies a primary key
http://cvs.php.net/diff.php/pear/MDB2_Schema/MDB2/Schema/Parser.php?r1=1.17&r2=1.18&ty=u
Index: pear/MDB2_Schema/MDB2/Schema/Parser.php
diff -u pear/MDB2_Schema/MDB2/Schema/Parser.php:1.17 pear/MDB2_Schema/MDB2/Schema/Parser.php:1.18
--- pear/MDB2_Schema/MDB2/Schema/Parser.php:1.17 Mon Oct 10 04:36:04 2005
+++ pear/MDB2_Schema/MDB2/Schema/Parser.php Tue Oct 18 13:58:25 2005
@@ -42,7 +42,7 @@
// | Author: Christian Dickmann <dickmann@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Parser.php,v 1.17 2005/10/10 08:36:04 lsmith Exp $
+// $Id: Parser.php,v 1.18 2005/10/18 17:58:25 dufuz Exp $
//
require_once 'XML/Parser.php';
@@ -187,13 +187,16 @@
if (!array_key_exists('was', $this->table)) {
$this->table['was'] = $this->table_name;
}
+
if (!$this->table_name) {
$this->raiseError('tables need names', null, $xp);
}
+
if (isset($this->database_definition['tables'][$this->table_name])) {
$this->raiseError('table "'.$this->table_name.'"
already exists', null, $xp);
}
- $primary = false;
+
+ $autoinc = $primary = false;
if (!array_key_exists('fields', $this->table)) {
$this->raiseError('tables need one or more fields', null, $xp);
} else {
@@ -202,7 +205,7 @@
if ($primary) {
$this->raiseError('there was already an autoincrement field in
"'.$this->table_name.'" before "'.$field_name.'"',
null, $xp);
} else {
- $primary = true;
+ $autoinc = $primary = true;
}
if (!$this->table['fields'][$field_name]['notnull'])
{
@@ -219,19 +222,32 @@
}
if (array_key_exists('indexes', $this->table)) {
foreach ($this->table['indexes'] as $name => $index) {
+ $skip_index = false;
if (array_key_exists('primary', $index) &&
$index['primary']) {
- if ($primary) {
- $this->raiseError('there was already an primary index or
autoincrement field in "'.$this->table_name.'" before
"'.$name.'"', null, $xp);
+ /*
+ * Lets see if we should skip this index since there is
+ * already a auto increment on this field this implying
+ * a primary key index.
+ */
+ if ($autoinc && count($index['fields']) == '1')
{
+ $skip_index = true;
} else {
- $primary = true;
+ if ($primary) {
+ $this->raiseError('there was already an primary index or
autoincrement field in "'.$this->table_name.'" before
"'.$name.'"', null, $xp);
+ } else {
+ $primary = true;
+ }
}
}
- foreach ($index['fields'] as $field_name => $field) {
- if (!isset($this->table['fields'][$field_name])) {
- $this->raiseError('index field
"'.$field_name.'" does not exist', null, $xp);
- } elseif (array_key_exists('primary', $index) &&
$index['primary']) {
-
if(!$this->table['fields'][$field_name]['notnull']) {
- $this->raiseError('all primary key fields must be defined
notnull in "'.$this->table_name.'"', null, $xp);
+
+ if (!$skip_index) {
+ foreach ($index['fields'] as $field_name => $field) {
+ if (!isset($this->table['fields'][$field_name])) {
+ $this->raiseError('index field
"'.$field_name.'" does not exist', null, $xp);
+ } elseif (array_key_exists('primary', $index) &&
$index['primary']) {
+ if
(!$this->table['fields'][$field_name]['notnull']) {
+ $this->raiseError('all primary key fields must be
defined notnull in "'.$this->table_name.'"', null, $xp);
+ }
}
}
}