diff --git a/js/sql.js b/js/sql.js
index 50fae3f2fe..e561ba5bf5 100644
--- a/js/sql.js
+++ b/js/sql.js
@@ -66,7 +66,7 @@ function getFieldName($this_field)
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('sql.js', function () {
- $('a.delete_row.ajax').unbind('click');
+ $('a.delete_row.ajax').die('click');
$('#bookmarkQueryForm').die('submit');
$('input#bkm_label').unbind('keyup');
$("#sqlqueryresults").die('makegrid');
@@ -104,7 +104,7 @@ AJAX.registerTeardown('sql.js', function () {
*/
AJAX.registerOnload('sql.js', function () {
// Delete row from SQL results
- $('a.delete_row.ajax').click(function (e) {
+ $('a.delete_row.ajax').live('click',function (e) {
e.preventDefault();
var question = $.sprintf(PMA_messages.strDoYouReally, $(this).closest('td').find('div').text());
var $link = $(this);
diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php
index d873f63fd0..80c7ce1c8f 100644
--- a/libraries/sql.lib.php
+++ b/libraries/sql.lib.php
@@ -1462,4 +1462,186 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil
isset($justBrowsing) ? $justBrowsing : null, $extra_data
);
}
-?>
+/**
+ * Delete related tranformatioinformationn information
+ *
+ * @param String $db current database
+ * @param String $table current table
+ * @param array $analyzed_sql analyzed sql query
+ *
+ * @return void
+ */
+function PMA_deleteTransformationInfo($db, $table, $analyzed_sql)
+{
+ include_once 'libraries/transformations.lib.php';
+ if ($analyzed_sql[0]['querytype'] == 'ALTER') {
+ if (stripos($analyzed_sql[0]['unsorted_query'], 'DROP') !== false) {
+ $drop_column = PMA_getColumnNameInColumnDropSql(
+ $analyzed_sql[0]['unsorted_query']
+ );
+
+ if ($drop_column != '') {
+ PMA_clearTransformations($db, $table, $drop_column);
+ }
+ }
+
+ } else if (($analyzed_sql[0]['querytype'] == 'DROP') && ($table != '')) {
+ PMA_clearTransformations($db, $table);
+ }
+}
+
+/**
+ * Function to get the message for the no rows returned case
+ *
+ * @param string $message_to_show message to show
+ * @param array $analyzed_sql_results analyzed sql results
+ * @param int $num_rows number of rows
+ *
+ * @return string $message
+ */
+function PMA_getMessageForNoRowsReturned($message_to_show, $analyzed_sql_results,
+$num_rows
+) {
+ if ($analyzed_sql_results['is_delete']) {
+ $message = PMA_Message::getMessageForDeletedRows($num_rows);
+ } elseif ($analyzed_sql_results['is_insert']) {
+ if ($analyzed_sql_results['is_replace']) {
+ // For replace we get DELETED + INSERTED row count,
+ // so we have to call it affected
+ $message = PMA_Message::getMessageForAffectedRows($num_rows);
+ } else {
+ $message = PMA_Message::getMessageForInsertedRows($num_rows);
+ }
+ $insert_id = $GLOBALS['dbi']->insertId();
+ if ($insert_id != 0) {
+ // insert_id is id of FIRST record inserted in one insert,
+ // so if we inserted multiple rows, we had to increment this
+ $message->addMessage('[br]');
+ // need to use a temporary because the Message class
+ // currently supports adding parameters only to the first
+ // message
+ $_inserted = PMA_Message::notice(__('Inserted row id: %1$d'));
+ $_inserted->addParam($insert_id + $num_rows - 1);
+ $message->addMessage($_inserted);
+ }
+ } elseif ($analyzed_sql_results['is_affected']) {
+ $message = PMA_Message::getMessageForAffectedRows($num_rows);
+
+ // Ok, here is an explanation for the !$is_select.
+ // The form generated by sql_query_form.lib.php
+ // and db_sql.php has many submit buttons
+ // on the same form, and some confusion arises from the
+ // fact that $message_to_show is sent for every case.
+ // The $message_to_show containing a success message and sent with
+ // the form should not have priority over errors
+ } elseif (! empty($message_to_show) && ! $analyzed_sql_results['is_select']) {
+ $message = PMA_Message::rawSuccess(htmlspecialchars($message_to_show));
+ } elseif (! empty($GLOBALS['show_as_php'])) {
+ $message = PMA_Message::success(__('Showing as PHP code'));
+ } elseif (isset($GLOBALS['show_as_php'])) {
+ /* User disable showing as PHP, query is only displayed */
+ $message = PMA_Message::notice(__('Showing SQL query'));
+ } elseif (! empty($GLOBALS['validatequery'])) {
+ $message = PMA_Message::notice(__('Validated SQL'));
+ } else {
+ $message = PMA_Message::success(
+ __('MySQL returned an empty result set (i.e. zero rows).')
+ );
+ }
+
+ if (isset($GLOBALS['querytime'])) {
+ $_querytime = PMA_Message::notice('(' . __('Query took %01.4f sec') . ')');
+ $_querytime->addParam($GLOBALS['querytime']);
+ $message->addMessage($_querytime);
+ }
+
+ return $message;
+}
+
+/**
+ * Function to send the Ajax response when no rows returned
+ *
+ * @param string $message message to be send
+ * @param array $analyzed_sql analyzed sql
+ * @param object $displayResultsObject DisplayResult instance
+ * @param bool $showSql whether to show sql or not
+ * @param array $extra_data extra data
+ *
+ * @return void
+ */
+function PMA_sendAjaxResponseForNoResultsReturned($message, $analyzed_sql,
+$displayResultsObject, $showSql, $extra_data
+) {
+ if ($showSql) {
+ $extra_data['sql_query'] = PMA_Util::getMessage(
+ $message, $GLOBALS['sql_query'], 'success'
+ );
+ }
+ if (isset($GLOBALS['reload']) && $GLOBALS['reload'] == 1) {
+ $extra_data['reload'] = 1;
+ $extra_data['db'] = $GLOBALS['db'];
+ }
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ // No need to manually send the message
+ // The Response class will handle that automatically
+ $query__type = PMA_DisplayResults::QUERY_TYPE_SELECT;
+ if ($analyzed_sql[0]['querytype'] == $query__type) {
+ $createViewHTML = $displayResultsObject->getCreateViewQueryResultOp(
+ $analyzed_sql
+ );
+ $response->addHTML($createViewHTML.'
');
+ }
+
+ $response->addJSON(isset($extra_data) ? $extra_data : array());
+ if (empty($_REQUEST['ajax_page_request'])) {
+ $response->addJSON('message', $message);
+ exit;
+ }
+}
+
+/**
+ * Function to respond back when the query returns zero rows
+ * This method is called when
+ * 1-> When browsing an empty table
+ * 2-> When executing a query on a non empty table which returns zero results
+ * 3-> When executing a query on an empty table
+ * 4-> When executing an INSERT, UPDATE, DEDETE query from the SQL tab
+ * 5-> When deleting a row from BROWSE tab
+ * 6-> When searching using the SEARCH tab which returns zero results
+ * 7-> When changing the structure of the table except change operation
+ *
+ * @param array $analyzed_sql_results analyzed sql results
+ * @param string $db current database
+ * @param string $table current table
+ * @param string $message_to_show message to show
+ * @param int $num_rows number of rows
+ * @param object $displayResultsObject DisplayResult instance
+ * @param array $extra_data extra data
+ * @param array $cfg configuration
+ *
+ * @return void
+ */
+function PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table,
+ $message_to_show, $num_rows, $displayResultsObject, $extra_data, $cfg
+) {
+ if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) {
+ PMA_deleteTransformationInfo(
+ $db, $table, $analyzed_sql_results['analyzed_sql']
+ );
+ }
+
+ $message = PMA_getMessageForNoRowsReturned(
+ isset($message_to_show) ? $message_to_show : null, $analyzed_sql_results,
+ $num_rows
+ );
+ if ($GLOBALS['is_ajax_request'] == true) {
+ PMA_sendAjaxResponseForNoResultsReturned($message,
+ $analyzed_sql_results['analyzed_sql'],
+ $displayResultsObject, $cfg['ShowSQL'],
+ isset($extra_data) ? $extra_data : null
+ );
+ }
+ exit();
+}
+?>
\ No newline at end of file
diff --git a/sql.php b/sql.php
index d04e2b5d97..53ce7ff605 100644
--- a/sql.php
+++ b/sql.php
@@ -222,150 +222,11 @@ list($result, $num_rows, $unlim_num_rows, $profiling_results,
// No rows returned -> move back to the calling page
if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) {
- // Delete related tranformation information
- if (PMA_isDeleteTransformationInfo($analyzed_sql_results)) {
- include_once 'libraries/transformations.lib.php';
- if ($analyzed_sql[0]['querytype'] == 'ALTER') {
- if (stripos($analyzed_sql[0]['unsorted_query'], 'DROP') !== false) {
- $drop_column = PMA_getColumnNameInColumnDropSql(
- $analyzed_sql[0]['unsorted_query']
- );
-
- if ($drop_column != '') {
- PMA_clearTransformations($db, $table, $drop_column);
- }
- }
-
- } else if (($analyzed_sql[0]['querytype'] == 'DROP') && ($table != '')) {
- PMA_clearTransformations($db, $table);
- }
- }
-
- if ($is_delete) {
- $message = PMA_Message::getMessageForDeletedRows($num_rows);
- } elseif ($is_insert) {
- if ($is_replace) {
- // For replace we get DELETED + INSERTED row count,
- // so we have to call it affected
- $message = PMA_Message::getMessageForAffectedRows($num_rows);
- } else {
- $message = PMA_Message::getMessageForInsertedRows($num_rows);
- }
- $insert_id = $GLOBALS['dbi']->insertId();
- if ($insert_id != 0) {
- // insert_id is id of FIRST record inserted in one insert,
- // so if we inserted multiple rows, we had to increment this
- $message->addMessage('[br]');
- // need to use a temporary because the Message class
- // currently supports adding parameters only to the first
- // message
- $_inserted = PMA_Message::notice(__('Inserted row id: %1$d'));
- $_inserted->addParam($insert_id + $num_rows - 1);
- $message->addMessage($_inserted);
- }
- } elseif ($is_affected) {
- $message = PMA_Message::getMessageForAffectedRows($num_rows);
-
- // Ok, here is an explanation for the !$is_select.
- // The form generated by sql_query_form.lib.php
- // and db_sql.php has many submit buttons
- // on the same form, and some confusion arises from the
- // fact that $message_to_show is sent for every case.
- // The $message_to_show containing a success message and sent with
- // the form should not have priority over errors
- } elseif (! empty($message_to_show) && ! $is_select) {
- $message = PMA_Message::rawSuccess(htmlspecialchars($message_to_show));
- } elseif (! empty($GLOBALS['show_as_php'])) {
- $message = PMA_Message::success(__('Showing as PHP code'));
- } elseif (isset($GLOBALS['show_as_php'])) {
- /* User disable showing as PHP, query is only displayed */
- $message = PMA_Message::notice(__('Showing SQL query'));
- } elseif (! empty($GLOBALS['validatequery'])) {
- $message = PMA_Message::notice(__('Validated SQL'));
- } else {
- $message = PMA_Message::success(
- __('MySQL returned an empty result set (i.e. zero rows).')
- );
- }
-
- if (isset($GLOBALS['querytime'])) {
- $_querytime = PMA_Message::notice('(' . __('Query took %01.4f sec') . ')');
- $_querytime->addParam($GLOBALS['querytime']);
- $message->addMessage($_querytime);
- }
-
- if ($GLOBALS['is_ajax_request'] == true) {
- if ($cfg['ShowSQL']) {
- $extra_data['sql_query'] = PMA_Util::getMessage(
- $message, $GLOBALS['sql_query'], 'success'
- );
- }
- if (isset($GLOBALS['reload']) && $GLOBALS['reload'] == 1) {
- $extra_data['reload'] = 1;
- $extra_data['db'] = $GLOBALS['db'];
- }
- $response = PMA_Response::getInstance();
- $response->isSuccess($message->isSuccess());
- // No need to manually send the message
- // The Response class will handle that automatically
- $query__type = PMA_DisplayResults::QUERY_TYPE_SELECT;
- if ($analyzed_sql[0]['querytype'] == $query__type) {
- $createViewHTML = $displayResultsObject->getCreateViewQueryResultOp(
- $analyzed_sql
- );
- $response->addHTML($createViewHTML.'
');
- }
-
- $response->addJSON(isset($extra_data) ? $extra_data : array());
- if (empty($_REQUEST['ajax_page_request'])) {
- $response->addJSON('message', $message);
- exit;
- }
- }
-
- if ($is_gotofile) {
- $goto = PMA_securePath($goto);
- // Checks for a valid target script
- $is_db = $is_table = false;
- if (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1') {
- $table = '';
- unset($url_params['table']);
- }
- include 'libraries/db_table_exists.lib.php';
-
- if (strpos($goto, 'tbl_') === 0 && ! $is_table) {
- if (strlen($table)) {
- $table = '';
- }
- $goto = 'db_sql.php';
- }
- if (strpos($goto, 'db_') === 0 && ! $is_db) {
- if (strlen($db)) {
- $db = '';
- }
- $goto = 'index.php';
- }
- // Loads to target script
- if (strlen($goto) > 0) {
- $active_page = $goto;
- include '' . $goto;
- } else {
- // Echo at least one character to prevent showing last page from history
- echo " ";
- }
-
- } else {
- // avoid a redirect loop when last record was deleted
- if (0 == $num_rows && 'sql.php' == $cfg['DefaultTabTable']) {
- $goto = str_replace('sql.php', 'tbl_structure.php', $goto);
- }
- PMA_sendHeaderLocation(
- $cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto)
- . '&message=' . urlencode($message)
- );
- } // end else
- exit();
- // end no rows returned
+ PMA_sendResponseForNoResultsReturned($analyzed_sql_results, $db, $table,
+ isset($message_to_show) ? $message_to_show : null,
+ $num_rows, $displayResultsObject, $extra_data, $cfg
+ );
+
} else {
$html_output='';
// At least one row is returned -> displays a table with results