From e948ec2ac2b1bebc8791522ffa29bb385ab118b7 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 23 Aug 2003 18:50:52 +0000 Subject: [PATCH] analyzer and CONSTRAINT --- ChangeLog | 1 + libraries/sqlparser.lib.php3 | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 278041308..91a83a6a8 100755 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ $Source$ * lang/polish: Updated, thanks to Jakub Wilk (ubanus). * lang/swedish: Updated, thanks to Björn T. Hallberg (bth). * lang/greek: update, thanks to Kyriakos Xagoraris (theremon) + * libraries/sqlparser.lib.php3: extract the CONSTRAINTs for FOREIGN KEYs 2003-08-21 Marc Delisle * tbl_relation.php3: improve variables, remove some code diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index 438f5c36f..3cb806d1e 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -747,7 +747,8 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { * lem9: foreign keys * ------------ * The CREATE TABLE may contain FOREIGN KEY clauses, so they get - * analyzed and ['foreign_keys'] is an array filled with the index list, + * analyzed and ['foreign_keys'] is an array filled with + * the constraint name, the index list, * the REFERENCES table name and REFERENCES index list. * * lem9: position_of_first_select @@ -1376,20 +1377,29 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $seen_foreign = FALSE; $seen_references = FALSE; + $seen_constraint = FALSE; $in_bracket = FALSE; $foreign_key_number = -1; for ($i = 0; $i < $size; $i++) { if ($arr[$i]['type'] == 'alpha_reservedWord') { $upper_data = strtoupper($arr[$i]['data']); + + if ($upper_data == 'CONSTRAINT') { + $foreign_key_number++; + $seen_foreign = FALSE; + $seen_references = FALSE; + $seen_constraint = TRUE; + } if ($upper_data == 'FOREIGN') { $seen_foreign = TRUE; $seen_references = FALSE; - $foreign_key_number++; + $seen_constraint = FALSE; } if ($upper_data == 'REFERENCES') { $seen_foreign = FALSE; $seen_references = TRUE; + $seen_constraint = FALSE; } } @@ -1406,6 +1416,11 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { if (($arr[$i]['type'] == 'quote_backtick')) { + if ($seen_constraint) { + // remove backquotes + $identifier = str_replace('`','',$arr[$i]['data']); + $foreign[$foreign_key_number]['constraint'] = $identifier; + } if ($seen_foreign && $in_bracket) { // remove backquotes $identifier = str_replace('`','',$arr[$i]['data']);