diff --git a/ChangeLog b/ChangeLog index 080612c94..584c31592 100755 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ $Source$ * footer.inc.php3, lines 11-16: tried to fix bug #493200 - Problems with PHP 4.1.0. Actually the fix is to skip db connection closing if the script use persistent connections. + * tbl_dump.php3; libraries/build_dump.php3: data are no long bufferized by + the script if the user wants it to be displayed on screen or saved as a + text file. This may be helpfull for bug #448223 - Dump hangs. 2001-12-14 Loïc Chapeaux * user_details.php3: check/uncheck all links weren't working with js diff --git a/libraries/build_dump.lib.php3 b/libraries/build_dump.lib.php3 index bc0672612..26694708c 100644 --- a/libraries/build_dump.lib.php3 +++ b/libraries/build_dump.lib.php3 @@ -161,6 +161,8 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @global boolean whether to use backquotes to allow the use of special * characters in database, table and fields names or not + * @global integer the number of records + * @global integer the current record position * * @access private * @@ -171,11 +173,14 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ function PMA_getTableContentFast($db, $table, $add_query = '', $handler, $error_url) { global $use_backquotes; + global $rows_cnt; + global $current_row; $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); if ($result != FALSE) { $fields_cnt = mysql_num_fields($result); + $rows_cnt = mysql_num_rows($result); // Checks whether the field is an integer or not for ($j = 0; $j < $fields_cnt; $j++) { @@ -201,11 +206,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required $replace = array('\0', '\n', '\r', '\Z'); - $is_first_row = TRUE; + $current_row = 0; @set_time_limit($GLOBALS['cfgExecTimeLimit']); while ($row = mysql_fetch_row($result)) { + $current_row++; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { $values[] = 'NULL'; @@ -225,30 +231,28 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ // Extended inserts case if (isset($GLOBALS['extended_ins'])) { - if ($is_first_row) { + if ($current_row == 1) { $insert_line = $schema_insert . implode(', ', $values) . ')'; - $is_first_row = FALSE; } else { - $insert_line = '(' . implode(', ', $values) . ')'; + $insert_line = '(' . implode(', ', $values) . ')'; } } // Other inserts case else { - $insert_line = $schema_insert . implode(', ', $values) . ')'; + $insert_line = $schema_insert . implode(', ', $values) . ')'; } unset($values); // Call the handler $handler($insert_line); - // loic1: send a fake header to bypass browser timeout - header('Expires: 0'); + // loic1: send a fake header to bypass browser timeout if data + // are bufferized + if (!empty($GLOBALS['ob_mode']) + || (isset($GLOBALS['zip']) || isset($GLOBALS['bzip']) || isset($GLOBALS['gzip']))) { + header('Expires: 0'); + } } // end while - - // Replace last comma by a semi-column in extended inserts case - if (isset($GLOBALS['extended_ins'])) { - $GLOBALS['tmp_buffer'] = ereg_replace(',([^,]*)$', ';\\1', $GLOBALS['tmp_buffer']); - } } // end if ($result != FALSE) mysql_free_result($result); @@ -276,6 +280,8 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @global boolean whether to use backquotes to allow the use of special * characters in database, table and fields names or not + * @global integer the number of records + * @global integer the current record position * * @access private * @@ -284,16 +290,19 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ function PMA_getTableContentOld($db, $table, $add_query = '', $handler, $error_url) { global $use_backquotes; + global $rows_cnt; + global $current_row; $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); - $i = 0; - $is_first_row = TRUE; + $current_row = 0; $fields_cnt = mysql_num_fields($result); + $rows_cnt = mysql_num_rows($result); @set_time_limit($GLOBALS['cfgExecTimeLimit']); // HaRa while ($row = mysql_fetch_row($result)) { + $current_row++; $table_list = '('; for ($j = 0; $j < $fields_cnt; $j++) { $table_list .= PMA_backquote(mysql_field_name($result, $j), $use_backquotes) . ', '; @@ -301,7 +310,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $table_list = substr($table_list, 0, -2); $table_list .= ')'; - if (isset($GLOBALS['extended_ins']) && !$is_first_row) { + if (isset($GLOBALS['extended_ins']) && $current_row > 1) { $schema_insert = '('; } else { if (isset($GLOBALS['showcolumns'])) { @@ -350,18 +359,16 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $schema_insert = ereg_replace(', $', '', $schema_insert); $schema_insert .= ')'; $handler(trim($schema_insert)); - ++$i; - // loic1: send a fake header to bypass browser timeout - header('Expires: 0'); + // loic1: send a fake header to bypass browser timeout if data are + // bufferized + if (!empty($GLOBALS['ob_mode']) + && (isset($GLOBALS['zip']) || isset($GLOBALS['bzip']) || isset($GLOBALS['gzip']))) { + header('Expires: 0'); + } } // end while mysql_free_result($result); - // Replace last comma by a semi-column in extended inserts case - if ($i > 0 && isset($GLOBALS['extended_ins'])) { - $GLOBALS['tmp_buffer'] = ereg_replace(',([^,]*)$', ';\\1', $GLOBALS['tmp_buffer']); - } - return TRUE; } // end of the 'PMA_getTableContentOld()' function @@ -511,6 +518,13 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ } // end for $handler(trim($schema_insert)); ++$i; + + // loic1: send a fake header to bypass browser timeout if data are + // bufferized + if (!empty($GLOBALS['ob_mode']) + && (isset($GLOBALS['zip']) || isset($GLOBALS['bzip']) || isset($GLOBALS['gzip']))) { + header('Expires: 0'); + } } // end while mysql_free_result($result); diff --git a/tbl_dump.php3 b/tbl_dump.php3 index 2fd120c82..49305532e 100755 --- a/tbl_dump.php3 +++ b/tbl_dump.php3 @@ -15,12 +15,18 @@ function PMA_myHandler($sql_insert) global $tmp_buffer; // Defines the end of line delimiter to use - $eol_dlm = (isset($GLOBALS['extended_ins'])) ? ',' : ';'; - // Result will be displays on screen + $eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt'])) + ? ',' + : ';'; + // Result has to be displayed on screen if (empty($GLOBALS['asfile'])) { - $tmp_buffer .= htmlspecialchars($sql_insert . $eol_dlm . $GLOBALS['crlf']); + echo htmlspecialchars($sql_insert . $eol_dlm . $GLOBALS['crlf']); } - // Result will be save in a file + // Result has to be saved in a text file + else if (!isset($GLOBALS['zip']) && !isset($GLOBALS['bzip']) && !isset($GLOBALS['gzip'])) { + echo $sql_insert . $eol_dlm . $GLOBALS['crlf']; + } + // Result will be saved in a *zipped file else { $tmp_buffer .= $sql_insert . $eol_dlm . $GLOBALS['crlf']; } @@ -45,11 +51,15 @@ function PMA_myCsvHandler($sql_insert) global $add_character; global $tmp_buffer; - // Result will be displays on screen + // Result has to be displayed on screen if (empty($GLOBALS['asfile'])) { - $tmp_buffer .= htmlspecialchars($sql_insert) . $add_character; + echo htmlspecialchars($sql_insert) . $add_character; } - // Result will be save in a file + // Result has to be saved in a text file + else if (!isset($GLOBALS['zip']) && !isset($GLOBALS['bzip']) && !isset($GLOBALS['gzip'])) { + echo $sql_insert . $add_character; + } + // Result will be saved in a *zipped file else { $tmp_buffer .= $sql_insert . $add_character; } @@ -223,6 +233,11 @@ else { if (!isset($limit_from) || !isset($limit_to)) { $limit_from = $limit_to = 0; } + // loic1: display data if they aren't bufferized + if (!isset($zip) && !isset($bzip) && !isset($gzip)) { + echo $dump_buffer; + $dump_buffer = ''; + } PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url); $dump_buffer .= $tmp_buffer; } // end if @@ -230,7 +245,8 @@ else { } // end if-else } // end while - // Don't remove, it makes easier to select & copy frombrowser - staybyte + // staybyte: don't remove, it makes easier to select & copy from + // browser $dump_buffer .= $crlf; } // end 'no csv' case @@ -286,7 +302,7 @@ else if (isset($gzip) && $gzip == 'gzip') { echo gzencode($dump_buffer); } } -// 4. on screen +// 4. on screen or as a text file else { echo $dump_buffer; }