From 3d9de55aef2c41309de3caae5adf5864b33afd03 Mon Sep 17 00:00:00 2001 From: ayusun Date: Sun, 28 Apr 2013 20:48:14 +0530 Subject: [PATCH 1/2] Implementation of feature Request 1412 with Reduced Code duplication --- libraries/DisplayResults.class.php | 108 +++++++++++++++++++++-------- sql.php | 8 +++ 2 files changed, 89 insertions(+), 27 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 073df10a46..ef0b2f90a2 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -5156,6 +5156,63 @@ class PMA_DisplayResults } // end of the '_getPlacedTableNavigatoins()' function + /** + * Generates HTML to display the Create view in span tag + * + * @param array $analyzed_sql the analyzed Query + * @param string String with URL Parameters + * + * @return string + * + * @access private + * + * @see _getResultsOperations() + */ + private function getLinkForCreateView($analyzed_sql, $url_query) + { + $results_operations_html = ''; + if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) { + + $ajax_class = ' ajax'; + + $results_operations_html .= '' + . PMA_Util::linkOrButton( + 'view_create.php' . $url_query, + PMA_Util::getIcon( + 'b_views.png', __('Create view'), true + ), + array('class' => 'create_view' . $ajax_class), true, true, '' + ) + . '' . "\n"; + } + return $results_operations_html; + + } + + /** + * Calls the _getResultsOperations with $only_view as true + * + * @param array $analyzed_sql the analyzed Query + * + * @return string + * + * @access public + * + */ + public function getCreateViewQueryResultOp($analyzed_sql) + { + + $results_operations_html = ''; + $fake_display_mode = array(); + //calling to _getResultOperations with a fake display mode + //and setting only_view parameter to be true to generate just view + $results_operations_html .= $this->_getResultsOperations( + $fake_display_mode, + $analyzed_sql, + true + ); + return $results_operations_html; + } /** * Get operations that are available on results. @@ -5169,7 +5226,7 @@ class PMA_DisplayResults * * @see getTable() */ - private function _getResultsOperations($the_disp_mode, $analyzed_sql) + private function _getResultsOperations($the_disp_mode, $analyzed_sql, $only_view = false) { $results_operations_html = ''; @@ -5177,23 +5234,33 @@ class PMA_DisplayResults $header_shown = false; $header = '
' . __('Query results operations') . ''; - - if (($the_disp_mode[6] == '1') || ($the_disp_mode[9] == '1')) { - // Displays "printable view" link if required - if ($the_disp_mode[9] == '1') { - - if (!$header_shown) { - $results_operations_html .= $header; - $header_shown = true; - } - - $_url_params = array( + + $_url_params = array( 'db' => $this->__get('db'), 'table' => $this->__get('table'), 'printview' => '1', 'sql_query' => $this->__get('sql_query'), ); - $url_query = PMA_generate_common_url($_url_params); + $url_query = PMA_generate_common_url($_url_params); + + if (!$header_shown) { + $results_operations_html .= $header; + $header_shown = true; + } + // if empty result set was produced we need to + // show only view and not other options + if ($only_view == true) { + $results_operations_html .= $this->getLinkForCreateView($analyzed_sql,$url_query); + + if ($header_shown) { + $results_operations_html .= '

'; + } + return $results_operations_html; + } + + if (($the_disp_mode[6] == '1') || ($the_disp_mode[9] == '1')) { + // Displays "printable view" link if required + if ($the_disp_mode[9] == '1') { $results_operations_html .= PMA_Util::linkOrButton( @@ -5337,20 +5404,7 @@ class PMA_DisplayResults $header_shown = true; } - if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) { - - $ajax_class = ' ajax'; - - $results_operations_html .= '' - . PMA_Util::linkOrButton( - 'view_create.php' . $url_query, - PMA_Util::getIcon( - 'b_views.png', __('Create view'), true - ), - array('class' => 'create_view' . $ajax_class), true, true, '' - ) - . '' . "\n"; - } + $results_operations_html .= $this->getLinkForCreateView($analyzed_sql,$url_query); if ($header_shown) { $results_operations_html .= '
'; diff --git a/sql.php b/sql.php index f670b658a5..eed4f4800d 100644 --- a/sql.php +++ b/sql.php @@ -962,6 +962,14 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $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); From eec791dc0417ab0c7f36ec8e382ab3401b683ba3 Mon Sep 17 00:00:00 2001 From: ayusun Date: Sun, 28 Apr 2013 23:01:45 +0530 Subject: [PATCH 2/2] Edited changelog and applied PEAR standard. Feature Request 1412 --- ChangeLog | 1 + libraries/DisplayResults.class.php | 24 +++++++++++++----------- sql.php | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c2e874c14..538f9b8074 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.0.0.0 (not yet released) ++ rfe #1412 Creating a view from an empty set of results + Patch #3481047 for rfe #3480477 Insert as new row enhancement + Patch #3480999 Activate codemirror in the query window - Patch #3495284 XML Import - fix message and redirect diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index ef0b2f90a2..6d315adaec 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -5159,8 +5159,8 @@ class PMA_DisplayResults /** * Generates HTML to display the Create view in span tag * - * @param array $analyzed_sql the analyzed Query - * @param string String with URL Parameters + * @param array $analyzed_sql the analyzed Query + * @param string $url_query String with URL Parameters * * @return string * @@ -5168,7 +5168,7 @@ class PMA_DisplayResults * * @see _getResultsOperations() */ - private function getLinkForCreateView($analyzed_sql, $url_query) + private function _getLinkForCreateView($analyzed_sql, $url_query) { $results_operations_html = ''; if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) { @@ -5203,7 +5203,7 @@ class PMA_DisplayResults { $results_operations_html = ''; - $fake_display_mode = array(); + $fake_display_mode = array(); //calling to _getResultOperations with a fake display mode //and setting only_view parameter to be true to generate just view $results_operations_html .= $this->_getResultsOperations( @@ -5212,13 +5212,14 @@ class PMA_DisplayResults true ); return $results_operations_html; - } + } /** * Get operations that are available on results. * - * @param array $the_disp_mode the display mode - * @param array $analyzed_sql the analyzed query + * @param array $the_disp_mode the display mode + * @param array $analyzed_sql the analyzed query + * @param boolean $only_view Whether to show only view * * @return string $results_operations_html html content * @@ -5226,9 +5227,10 @@ class PMA_DisplayResults * * @see getTable() */ - private function _getResultsOperations($the_disp_mode, $analyzed_sql, $only_view = false) + private function _getResultsOperations( + $the_disp_mode, $analyzed_sql, $only_view = false + ) { - $results_operations_html = ''; $fields_meta = $this->__get('fields_meta'); // To safe use in foreach $header_shown = false; @@ -5250,7 +5252,7 @@ class PMA_DisplayResults // if empty result set was produced we need to // show only view and not other options if ($only_view == true) { - $results_operations_html .= $this->getLinkForCreateView($analyzed_sql,$url_query); + $results_operations_html .= $this->_getLinkForCreateView($analyzed_sql,$url_query); if ($header_shown) { $results_operations_html .= '
'; @@ -5404,7 +5406,7 @@ class PMA_DisplayResults $header_shown = true; } - $results_operations_html .= $this->getLinkForCreateView($analyzed_sql,$url_query); + $results_operations_html .= $this->_getLinkForCreateView($analyzed_sql,$url_query); if ($header_shown) { $results_operations_html .= '
'; diff --git a/sql.php b/sql.php index eed4f4800d..7b13d529db 100644 --- a/sql.php +++ b/sql.php @@ -963,7 +963,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // 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) { + if ($analyzed_sql[0]['querytype'] == $query__type) { $createViewHTML = $displayResultsObject->getCreateViewQueryResultOp( $analyzed_sql );