diff --git a/ChangeLog b/ChangeLog index f48530751..4a74ba98f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-01-19 Marc Delisle + * sql.php3, tbl_properties_export.php3, tbl_dump.php3, + tbl_move_copy.php3, libraries/build_dump.lib.php3: + Feature: Export results of SELECTs + (TODO: enable row limiting for the export) + 2003-01-17 Marc Delisle * Documentation.html: faq 5.12 about OS X Safari problem * tbl_move_copy.php3: typo (wrong back link) diff --git a/libraries/build_dump.lib.php3 b/libraries/build_dump.lib.php3 index de99c7e4a..45f3ec15f 100644 --- a/libraries/build_dump.lib.php3 +++ b/libraries/build_dump.lib.php3 @@ -177,6 +177,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * of every row. This handler must accept one parameter * ($sql_insert) * @param string the url to go back in case of error + * @param string the sql_query (optional) * * @return boolean always true * @@ -191,13 +192,18 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @author staybyte */ - function PMA_getTableContentFast($db, $table, $add_query = '', $handler, $error_url) + function PMA_getTableContentFast($db, $table, $add_query = '', $handler, $error_url, $sql_query) { global $use_backquotes; global $rows_cnt; global $current_row; - $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + if (!empty($sql_query)) { + $local_query = $sql_query; + PMA_mysql_select_db($db); + } else { + $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + } $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); if ($result != FALSE) { $fields_cnt = mysql_num_fields($result); @@ -306,6 +312,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * of every row. This handler must accept one parameter * ($sql_insert) * @param string the url to go back in case of error + * @param string the sql query (optional) * * @return boolean always true * @@ -318,13 +325,18 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @see PMA_getTableContent() */ - function PMA_getTableContentOld($db, $table, $add_query = '', $handler, $error_url) + function PMA_getTableContentOld($db, $table, $add_query = '', $handler, $error_url, $sql_query) { global $use_backquotes; global $rows_cnt; global $current_row; - $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + if (!empty($sql_query)) { + $local_query = $sql_query; + PMA_mysql_select_db($db); + } else { + $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + } $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); $current_row = 0; $fields_cnt = mysql_num_fields($result); @@ -429,6 +441,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * of every row. This handler must accept one parameter * ($sql_insert) * @param string the url to go back in case of error + * @param string the sql_query (optional) * * @access public * @@ -436,7 +449,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @author staybyte */ - function PMA_getTableContent($db, $table, $limit_from = 0, $limit_to = 0, $handler, $error_url) + function PMA_getTableContent($db, $table, $limit_from = 0, $limit_to = 0, $handler, $error_url, $sql_query) { // Defines the offsets to use if ($limit_to > 0 && $limit_from >= 0) { @@ -449,9 +462,9 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ // Call the working function depending on the php version if (PMA_PHP_INT_VERSION >= 40005) { - PMA_getTableContentFast($db, $table, $add_query, $handler, $error_url); + PMA_getTableContentFast($db, $table, $add_query, $handler, $error_url, $sql_query); } else { - PMA_getTableContentOld($db, $table, $add_query, $handler, $error_url); + PMA_getTableContentOld($db, $table, $add_query, $handler, $error_url, $sql_query); } } // end of the 'PMA_getTableContent()' function @@ -471,6 +484,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * @param string the handler (function) to call. It must accept one * parameter ($sql_insert) * @param string the url to go back in case of error + * @param string sql query (optional) * * @global string whether to obtain an excel compatible csv format or a * simple csv one @@ -479,7 +493,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @access public */ - function PMA_getTableCsv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $enc_by, $esc_by, $handler, $error_url) + function PMA_getTableCsv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $enc_by, $esc_by, $handler, $error_url, $sql_query) { global $what; @@ -539,7 +553,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ } // end if // Gets the data from the database - $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + if (!empty($sql_query)) { + $local_query = $sql_query; + PMA_mysql_select_db($db); + } else { + $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + } $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); $fields_cnt = mysql_num_fields($result); @@ -606,7 +625,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @access public */ - function PMA_getTableXML($db, $table, $limit_from = 0, $limit_to = 0, $crlf, $error_url) { + function PMA_getTableXML($db, $table, $limit_from = 0, $limit_to = 0, $crlf, $error_url, $sql_query) { $local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); for ($i = 0; $row = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $i++) { @@ -625,7 +644,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $add_query = ''; } - $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + if (!empty($sql_query)) { + $local_query = $sql_query; + PMA_mysql_select_db($db); + } else { + $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; + } $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); $buffer = ' ' . $crlf; while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) { @@ -659,12 +683,13 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * @param integer the last row to get * @param string the end of line sequence * @param string the url to go back in case of error + * @param string sql query (optional) * * @return string the LaTeX table environment * * @access public */ - function PMA_getTableLatex($db, $table, $environment, $limit_from, $limit_to, $crlf, $error_url) { + function PMA_getTableLatex($db, $table, $environment, $limit_from, $limit_to, $crlf, $error_url, $sql_query) { $local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); @@ -678,7 +703,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $tex_escape = array("$", "%", "{", "}", "&", "#", "_", "^"); - $local_query = 'select * from ' . PMA_backquote($db) . '.' . PMA_backquote($table); + if (!empty($sql_query)) { + $local_query = $sql_query; + PMA_mysql_select_db($db); + } else { + $local_query = 'select * from ' . PMA_backquote($db) . '.' . PMA_backquote($table); + } $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); $buffer = '\\begin{table} ' . $crlf diff --git a/sql.php3 b/sql.php3 index 4bb17e1d6..fff0a4bc3 100755 --- a/sql.php3 +++ b/sql.php3 @@ -562,6 +562,14 @@ else { echo '

' . "\n"; } + // Export link, if only one table + // (the url_query has extra parameters that won't be used to export) + if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) + && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) { + echo ' ' . "\n" + . ' ' . $strExport . '' . "\n"; + } + // Bookmark Support if required if ($disp_mode[7] == '1' && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark)) diff --git a/tbl_dump.php3 b/tbl_dump.php3 index f39d2f9b7..cb8a778f8 100755 --- a/tbl_dump.php3 +++ b/tbl_dump.php3 @@ -63,7 +63,6 @@ require('./libraries/common.lib.php3'); require('./libraries/build_dump.lib.php3'); require('./libraries/zip.lib.php3'); - /** * Defines the url to return to in case of error in a sql statement */ @@ -89,7 +88,7 @@ if (empty($asfile) /** - * Send headers depending on whether the user choosen to download a dump file + * Send headers depending on whether the user chose to download a dump file * or not */ // No download @@ -230,7 +229,7 @@ else { if (!isset($limit_from) || !isset($limit_to)) { $limit_from = $limit_to = 0; } - PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url); + PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url, (isset($sql_query)?urldecode($sql_query):'')); $dump_buffer .= $tmp_buffer; } // end if @@ -282,7 +281,8 @@ else { } if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $table . '|')) || (!isset($tmp_select) && !empty($table))) { - $dump_buffer .= PMA_getTableXML($db, $table, $limit_from, $limit_to, $crlf, $err_url); + $dump_buffer .= PMA_getTableXML($db, $table, $limit_from, $limit_to, $crlf, $err_url, + (isset($sql_query)?urldecode($sql_query):'')); } $i++; } @@ -319,7 +319,8 @@ else { || (!isset($tmp_select) && !empty($table))) { // to do: add option for the formatting ( c, l, r, p) - $dump_buffer .= PMA_getTableLatex($db, $table, $environment, $limit_from, $limit_to, $crlf, $err_url); + $dump_buffer .= PMA_getTableLatex($db, $table, $environment, $limit_from, $limit_to, $crlf, $err_url, + (isset($sql_query)?urldecode($sql_query):'')); } $i++; } @@ -343,7 +344,8 @@ else { } // end if $tmp_buffer = ''; - PMA_getTableCsv($db, $table, $limit_from, $limit_to, $separator, $enclosed, $escaped, 'PMA_myCsvHandler', $err_url); + PMA_getTableCsv($db, $table, $limit_from, $limit_to, $separator, $enclosed, $escaped, 'PMA_myCsvHandler', $err_url + , (isset($sql_query)?urldecode($sql_query):'')); $dump_buffer .= $tmp_buffer; } // end 'csv case } // end building the dump diff --git a/tbl_move_copy.php3 b/tbl_move_copy.php3 index 5cc750daa..b9f1ee092 100644 --- a/tbl_move_copy.php3 +++ b/tbl_move_copy.php3 @@ -108,7 +108,7 @@ if (isset($new_name) && trim($new_name) != '') { } // end MySQL >= 3.23 else { $sql_insert_data = ''; - PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url); + PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url,''); } // end MySQL < 3.23 $sql_query .= "\n\n" . $sql_insert_data; } diff --git a/tbl_properties_export.php3 b/tbl_properties_export.php3 index db85d3759..fff685df6 100755 --- a/tbl_properties_export.php3 +++ b/tbl_properties_export.php3 @@ -16,8 +16,19 @@ require('./tbl_properties_table_info.php3');

+
- + '; +} + ?>