From 2309ef57d2065277339513590b24b02d4115cc39 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Wed, 9 Nov 2016 21:16:00 +0530 Subject: [PATCH 1/3] Add LEFT JOIN for different constraints If there are two or more columns in the same constraint (foreign key), we should use AND to concatenate the conditions on LEFT JOIN for both the columns Fix #12652 Signed-off-by: Deven Bansod --- js/pmd/history.js | 37 ++++++++++++++++++++++++++++--------- libraries/pmd_common.php | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/js/pmd/history.js b/js/pmd/history.js index 9f70c03d46..af44d4e780 100644 --- a/js/pmd/history.js +++ b/js/pmd/history.js @@ -658,6 +658,10 @@ function query_from() var key2; var key3; var parts1; + + // the constraints that have been used in the LEFT JOIN + var constraints_added = []; + for (i = 0; i < history_array.length; i++) { from_array.push(history_array[i].get_tab()); } @@ -666,6 +670,7 @@ function query_from() temp = tab_left.shift(); quer = '`' + temp + '`'; tab_used.push(temp); + // if master table (key2) matches with tab used get all keys and check if tab_left matches // after this check if master table (key2) matches with tab left then check if any foreign matches with master . for (i = 0; i < 2; i++) { @@ -677,11 +682,18 @@ function query_from() for (key3 in contr[K][key][key2]) { parts1 = contr[K][key][key2][key3][0].split("."); if (found(tab_left, parts1[1]) > 0) { - query += "\n" + 'LEFT JOIN '; - query += '`' + parts1[1] + '` ON '; - query += '`' + parts[1] + '`.`' + key3 + '` = '; - query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` '; - t_tab_left.push(parts1[1]); + if (found(constraints_added, key) > 0) { + query += ' AND ' + '`' + parts[1] + '`.`' + key3 + '` = '; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` '; + } else { + query += "\n" + 'LEFT JOIN '; + query += '`' + parts[1] + '` ON '; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = '; + query += '`' + parts[1] + '`.`' + key3 + '` '; + + constraints_added.push(key); + } + t_tab_left.push(parts[1]); } } } @@ -701,10 +713,17 @@ function query_from() for (key3 in contr[K][key][key2]) { parts1 = contr[K][key][key2][key3][0].split("."); if (found(tab_used, parts1[1]) > 0) { - query += "\n" + 'LEFT JOIN '; - query += '`' + parts[1] + '` ON '; - query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = '; - query += '`' + parts[1] + '`.`' + key3 + '` '; + if (found(constraints_added, key) > 0) { + query += ' AND ' + '`' + parts[1] + '`.`' + key3 + '` = '; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` '; + } else { + query += "\n" + 'LEFT JOIN '; + query += '`' + parts[1] + '` ON '; + query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = '; + query += '`' + parts[1] + '`.`' + key3 + '` '; + + constraints_added.push(key); + } t_tab_left.push(parts[1]); } } diff --git a/libraries/pmd_common.php b/libraries/pmd_common.php index 90ac20897c..c73b00a933 100644 --- a/libraries/pmd_common.php +++ b/libraries/pmd_common.php @@ -141,7 +141,7 @@ function PMA_getScriptContr() if ($row !== false) { foreach ($row['foreign_keys_data'] as $one_key) { foreach ($one_key['index_list'] as $index => $one_field) { - $con['C_NAME'][$i] = ''; + $con['C_NAME'][$i] = $one_key['constraint']; $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]); $con['DCN'][$i] = urlencode($one_field); $con['STN'][$i] = urlencode( From 3debbdd09b3b176bfb1686252ffc221de98e1eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 9 Nov 2016 18:05:41 +0100 Subject: [PATCH 2/3] Changelog entry for 12689 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 44b3fcc9e0..cb9044f32a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -82,6 +82,7 @@ phpMyAdmin - ChangeLog - issue #12674 Allow for proper MySQL-allowed strings as identifiers - issue #12651 Allow for partial dates on table insert page - issue #12681 Fixed designer with tables using special chars +- issue #12652 Fixed visual query builder for foreign keys with more fields 4.6.4 (2016-08-16) - issue [security] Weaknesses with cookie encryption, see PMASA-2016-29 From 7270a0c79547c9d6800373aa0aa6c4dbb54342d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 9 Nov 2016 18:07:21 +0100 Subject: [PATCH 3/3] Add missing punctionation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See PR #12686 Signed-off-by: Michal Čihař --- libraries/rte/rte_words.lib.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/rte/rte_words.lib.php b/libraries/rte/rte_words.lib.php index 3205c2e7fb..95fc5a1052 100644 --- a/libraries/rte/rte_words.lib.php +++ b/libraries/rte/rte_words.lib.php @@ -29,17 +29,17 @@ function PMA_RTE_getWord($index) 'export' => __('Export of routine %s'), 'human' => __('routine'), 'no_create' => __( - 'You do not have the necessary privileges to create a routine' + 'You do not have the necessary privileges to create a routine.' ), 'no_edit' => __( 'No routine with name %1$s found in database %2$s. ' - . 'You might be lacking the necessary privileges to edit this routine' + . 'You might be lacking the necessary privileges to edit this routine.' ), 'no_view' => __( 'No routine with name %1$s found in database %2$s. ' - . 'You might be lacking the necessary privileges to view/export this routine' + . 'You might be lacking the necessary privileges to view/export this routine.' ), - 'not_found' => __('No routine with name %1$s found in database %2$s'), + 'not_found' => __('No routine with name %1$s found in database %2$s.'), 'nothing' => __('There are no routines to display.'), 'title' => __('Routines'), ); @@ -51,9 +51,9 @@ function PMA_RTE_getWord($index) 'export' => __('Export of trigger %s'), 'human' => __('trigger'), 'no_create' => __( - 'You do not have the necessary privileges to create a trigger' + 'You do not have the necessary privileges to create a trigger.' ), - 'not_found' => __('No trigger with name %1$s found in database %2$s'), + 'not_found' => __('No trigger with name %1$s found in database %2$s.'), 'nothing' => __('There are no triggers to display.'), 'title' => __('Triggers'), ); @@ -65,9 +65,9 @@ function PMA_RTE_getWord($index) 'export' => __('Export of event %s'), 'human' => __('event'), 'no_create' => __( - 'You do not have the necessary privileges to create an event' + 'You do not have the necessary privileges to create an event.' ), - 'not_found' => __('No event with name %1$s found in database %2$s'), + 'not_found' => __('No event with name %1$s found in database %2$s.'), 'nothing' => __('There are no events to display.'), 'title' => __('Events'), );