svn: /pear/packages/MDB2/trunk/ MDB2/Driver/Manager/mysql.php MDB2/Driver/Manager/mysqli.php package_mysql.php package_mysqli.php
| From: | Lorenzo Alberton | Date: | Sat, 26 Dec 2009 14:08:53 +0000 |
| Subject: | svn: /pear/packages/MDB2/trunk/ MDB2/Driver/Manager/mysql.php MDB2/Driver/Manager/mysqli.php package_mysql.php package_mysqli.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-58368@lists.php.net to get a copy of this message | ||
quipo Sat, 26 Dec 2009 14:08:53 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=292648
Log:
There is no NEW row in on DELETE trigger (fix error in FK constraint triggers)
Changed paths:
U pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysql.php
U pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysqli.php
U pear/packages/MDB2/trunk/package_mysql.php
U pear/packages/MDB2/trunk/package_mysqli.php
Modified: pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysql.php
===================================================================
--- pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysql.php 2009-12-26 14:07:00 UTC (rev 292647)
+++ pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysql.php 2009-12-26 14:08:53 UTC (rev 292648)
@@ -1100,14 +1100,20 @@
$null_values[] = $table_fields[$i] .' = NULL';
}
$conditions2 = array();
- for ($i=0; $i<count($referenced_fields); $i++) {
- $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <>
OLD.'.$referenced_fields[$i];
+ if ('NO ACTION' != $fkdef['ondelete']) {
+ // There is no NEW row in on DELETE trigger
+ for ($i=0; $i<count($referenced_fields); $i++) {
+ $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <>
OLD.'.$referenced_fields[$i];
+ }
}
- $restrict_action .= implode(' AND ', $conditions).') IS NOT
NULL'
- .' AND (' .implode(' OR ', $conditions2)
.')'
- .' THEN CALL
%s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
- .' END IF;';
+ $restrict_action .= implode(' AND ', $conditions).') IS NOT
NULL';
+ if (!empty($conditions2)) {
+ $restrict_action .= ' AND (' .implode(' OR ', $conditions2)
.')';
+ }
+ $restrict_action .= ' THEN CALL
%s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
+ .' END IF;';
+
$cascade_action_update = 'UPDATE '.$table_quoted.' SET
'.implode(', ', $new_values) .' WHERE '.implode(' AND ',
$conditions). ';';
$cascade_action_delete = 'DELETE FROM '.$table_quoted.' WHERE
'.implode(' AND ', $conditions). ';';
$setnull_action = 'UPDATE '.$table_quoted.' SET
'.implode(', ', $null_values).' WHERE '.implode(' AND ',
$conditions). ';';
Modified: pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysqli.php
===================================================================
--- pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysqli.php 2009-12-26 14:07:00 UTC (rev 292647)
+++ pear/packages/MDB2/trunk/MDB2/Driver/Manager/mysqli.php 2009-12-26 14:08:53 UTC (rev 292648)
@@ -1100,14 +1100,20 @@
$null_values[] = $table_fields[$i] .' = NULL';
}
$conditions2 = array();
- for ($i=0; $i<count($referenced_fields); $i++) {
- $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <>
OLD.'.$referenced_fields[$i];
+ if ('NO ACTION' != $fkdef['ondelete']) {
+ // There is no NEW row in on DELETE trigger
+ for ($i=0; $i<count($referenced_fields); $i++) {
+ $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <>
OLD.'.$referenced_fields[$i];
+ }
}
- $restrict_action .= implode(' AND ', $conditions).') IS NOT
NULL'
- .' AND (' .implode(' OR ', $conditions2)
.')'
- .' THEN CALL
%s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
- .' END IF;';
+ $restrict_action .= implode(' AND ', $conditions).') IS NOT
NULL';
+ if (!empty($conditions2)) {
+ $restrict_action .= ' AND (' .implode(' OR ', $conditions2)
.')';
+ }
+ $restrict_action .= ' THEN CALL
%s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
+ .' END IF;';
+
$cascade_action_update = 'UPDATE '.$table_quoted.' SET
'.implode(', ', $new_values) .' WHERE '.implode(' AND ',
$conditions). ';';
$cascade_action_delete = 'DELETE FROM '.$table_quoted.' WHERE
'.implode(' AND ', $conditions). ';';
$setnull_action = 'UPDATE '.$table_quoted.' SET
'.implode(', ', $null_values).' WHERE '.implode(' AND ',
$conditions). ';';
Modified: pear/packages/MDB2/trunk/package_mysql.php
===================================================================
--- pear/packages/MDB2/trunk/package_mysql.php 2009-12-26 14:07:00 UTC (rev 292647)
+++ pear/packages/MDB2/trunk/package_mysql.php 2009-12-26 14:08:53 UTC (rev 292648)
@@ -10,6 +10,7 @@
- fixed bug #16003: incorrect check for error after mysql_store_result
- fixed bug #16147: first prepared statement is emulated when using factory with mysql
- fixed bug #16669: hostspec is ignored when protocol is unix
+- There is no NEW row in on DELETE trigger (fix error in FK constraint triggers)
note:
- the multi_query test failes because this is not supported by ext/mysql
Modified: pear/packages/MDB2/trunk/package_mysqli.php
===================================================================
--- pear/packages/MDB2/trunk/package_mysqli.php 2009-12-26 14:07:00 UTC (rev 292647)
+++ pear/packages/MDB2/trunk/package_mysqli.php 2009-12-26 14:08:53 UTC (rev 292648)
@@ -9,6 +9,7 @@
- fixed bug #16003: incorrect check for error after mysqli_store_result
- fixed bug #16147: first prepared statement is emulated when using factory with mysql
- result->free() now works on multiple result sets
+- There is no NEW row in on DELETE trigger (fix error in FK constraint triggers)
open todo items:
- use a trigger to emulate setting default now()