diff --git a/ChangeLog b/ChangeLog index b30051d2b..cbf532ca9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -61,6 +61,8 @@ $Id$ - bug #2966752 [setup] Allow to configure changes tracking in setup script. + patch #2981165 [edit] Optionally disable the Type column, thanks to Brian Douglass - bhdouglass ++ patch #2984058 [edit] Buttons for quicky creating common SQL queries, thanks + to sutharshan. 3.3.3.0 (not yet released) - patch #2982480 [navi] Do not group if there would be one table in group, diff --git a/js/functions.js b/js/functions.js index c2e8b6303..699a0fe11 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1304,6 +1304,51 @@ function setSelectOptions(the_form, the_select, do_check) return true; } // end of the 'setSelectOptions()' function + +/** + * Create quick sql statements. + * + */ +function insertQuery(queryType) { + var myQuery = document.sqlform.sql_query; + var myListBox = document.sqlform.dummy; + var query = ""; + var table = document.sqlform.table.value; + + if (myListBox.options.length > 0) { + sql_box_locked = true; + var chaineAj = ""; + var valDis = ""; + var editDis = ""; + var NbSelect = 0; + for (var i=0; i < myListBox.options.length; i++) { + NbSelect++; + if (NbSelect > 1) { + chaineAj += ", "; + valDis += ","; + editDis += ","; + } + chaineAj += myListBox.options[i].value; + valDis += "[value-" + NbSelect + "]"; + editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]"; + } + if (queryType == "selectall") { + query = "SELECT * FROM `" + table + "` WHERE 1"; + } else if (queryType == "select") { + query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1"; + } else if (queryType == "insert") { + query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")"; + } else if (queryType == "update") { + query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1"; + } else if(queryType == "delete") { + query = "DELETE FROM `" + table + "` WHERE 1"; + } + document.sqlform.sql_query.value = query; + sql_box_locked = false; + } +} + + /** * Inserts multiple fields. * diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index f66b7e86d..2ba049094 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -296,6 +296,16 @@ function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter .' rows="' . $height . '"' .' dir="' . $GLOBALS['text_dir'] . '"' .$auto_sel . $locking . '>' . htmlspecialchars($query) . '' . "\n"; + // Add buttons to generate query easily for select all,single select,insert,update and delete + if(count($fields_list)) { + ?> + ' id='selectall' onclick='insertQuery(this.id)' /> + ' id='select' onclick='insertQuery(this.id)' /> + ' id='insert' onclick='insertQuery(this.id)' /> + ' id='update' onclick='insertQuery(this.id)' /> + ' id='delete' onclick='insertQuery(this.id)' /> + ' . "\n"; echo '