From 07901644c4155980fe48e98a5a54bc232e6ed5eb Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 31 Aug 2003 11:48:38 +0000 Subject: [PATCH] ON DELETE ON UPDATE --- ChangeLog | 3 +++ libraries/sqlparser.lib.php3 | 38 +++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e774e00d0..469ac2896 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-08-31 Marc Delisle + * libraries/sqlparser.lib.php3: extract ON DELETE, ON UPDATE for FOREIGN KEYs + 2003-08-28 Alexander M. Turek * README: Updated php / MySQL versions. diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index 3cb806d1e..150b14014 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -749,7 +749,8 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { * The CREATE TABLE may contain FOREIGN KEY clauses, so they get * analyzed and ['foreign_keys'] is an array filled with * the constraint name, the index list, - * the REFERENCES table name and REFERENCES index list. + * the REFERENCES table name and REFERENCES index list, + * and ON UPDATE | ON DELETE clauses * * lem9: position_of_first_select * ------------------------ @@ -1382,6 +1383,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $foreign_key_number = -1; for ($i = 0; $i < $size; $i++) { + // DEBUG echo $arr[$i]['data'] . " " . $arr[$i]['type'] . "
"; if ($arr[$i]['type'] == 'alpha_reservedWord') { $upper_data = strtoupper($arr[$i]['data']); @@ -1401,6 +1403,40 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $seen_references = TRUE; $seen_constraint = FALSE; } + + + // [ON DELETE {CASCADE | SET NULL | NO ACTION | RESTRICT}] + // [ON UPDATE {CASCADE | SET NULL | NO ACTION | RESTRICT}] + + // but we set ['on_delete'] or ['on_cascade'] to + // CASCADE | SET_NULL | NO_ACTION | RESTRICT + + if ($upper_data == 'ON') { + unset($clause); + if ($arr[$i+1]['type'] == 'alpha_reservedWord') { + $second_upper_data = strtoupper($arr[$i+1]['data']); + if ($second_upper_data == 'DELETE') { + $clause = 'on_delete'; + } + if ($second_upper_data == 'UPDATE') { + $clause = 'on_update'; + } + if (isset($clause) && $arr[$i+2]['type'] == 'alpha_reservedWord') { + $third_upper_data = strtoupper($arr[$i+2]['data']); + if ($third_upper_data == 'CASCADE' + || $third_upper_data == 'RESTRICT') { + $value = $third_upper_data; + } elseif ($third_upper_data == 'SET' + || $third_upper_data == 'NO') { + if ($arr[$i+3]['type'] == 'alpha_reservedWord') { + $value = $third_upper_data . '_' . strtoupper($arr[$i+3]['data']); + } + } + $foreign[$foreign_key_number][$clause] = $value; + } + } + } + } if ($arr[$i]['type'] == 'punct_bracket_open_round') {