The branch, master has been updated via d2873126e10eff11ad68d2b4fb113379174dd4f7 (commit) from 12b5d8d20b08c25115e9e6b7c68865a8b191fdc5 (commit)
- Log ----------------------------------------------------------------- commit d2873126e10eff11ad68d2b4fb113379174dd4f7 Author: Michal Čihař mcihar@novell.com Date: Fri Apr 9 11:44:04 2010 +0200
patch #2984058 [edit] Buttons for quicky creating common SQL queries.
Thanks to sutharshan, but the patch was heavily modified.
-----------------------------------------------------------------------
Summary of changes: ChangeLog | 2 + js/functions.js | 45 ++++++++++++++++++++++++++++++++++++++ libraries/sql_query_form.lib.php | 10 ++++++++ 3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog index b30051d..cbf532c 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 c2e8b63..699a0fe 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 f66b7e8..2ba0490 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) . '</textarea>' . "\n"; + // Add buttons to generate query easily for select all,single select,insert,update and delete + if(count($fields_list)) { + ?> + <input type='button' value='<?php echo __('Select all'); ?>' id='selectall' onclick='insertQuery(this.id)' /> + <input type='button' value='<?php echo __('Select'); ?>' id='select' onclick='insertQuery(this.id)' /> + <input type='button' value='<?php echo __('Insert'); ?>' id='insert' onclick='insertQuery(this.id)' /> + <input type='button' value='<?php echo __('Update'); ?>' id='update' onclick='insertQuery(this.id)' /> + <input type='button' value='<?php echo __('Delete'); ?>' id='delete' onclick='insertQuery(this.id)' /> + <?php + } echo '</div>' . "\n";
echo '<script type="text/javascript">' . "\n"
hooks/post-receive