export results of SELECTs

This commit is contained in:
Marc Delisle
2003-01-19 13:48:15 +00:00
parent b179b000d3
commit a5c02eb41f
6 changed files with 78 additions and 21 deletions

View File

@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
$Id$
$Source$
2003-01-19 Marc Delisle <lem9@users.sourceforge.net>
* 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 <lem9@users.sourceforge.net>
* Documentation.html: faq 5.12 about OS X Safari problem
* tbl_move_copy.php3: typo (wrong back link)

View File

@@ -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 = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $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

View File

@@ -562,6 +562,14 @@ else {
echo '</p>' . "\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 ' <!-- Export -->' . "\n"
. ' <a href="tbl_properties_export.php3' . $url_query . '">' . $strExport . '</a>' . "\n";
}
// Bookmark Support if required
if ($disp_mode[7] == '1'
&& ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))

View File

@@ -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

View File

@@ -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;
}

View File

@@ -16,8 +16,19 @@ require('./tbl_properties_table_info.php3');
<?php echo $strViewDump . "\n"; ?>
</p>
<?php
if (isset($sql_query)) {
$sql_query = stripslashes($sql_query);
PMA_showMessage($GLOBALS['strSQLQuery']);
}
?>
<form method="post" action="tbl_dump.php3" name="tbl_dump">
<?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
<?php
echo ' ' . PMA_generate_common_hidden_inputs($db, $table);
if (isset($sql_query)) {
echo ' <input type="hidden" name="sql_query" value="' . urlencode($sql_query) . '" />';
}
?>
<table cellpadding="5" border="2" align="center">
<tr>