diff --git a/ChangeLog b/ChangeLog index 4c32ead1e2..a4e9107595 100644 --- a/ChangeLog +++ b/ChangeLog @@ -114,6 +114,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 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( 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'), );