fixed some bugs with CSV exportations

This commit is contained in:
Loïc Chapeaux
2001-08-20 10:22:33 +00:00
parent 8517bb530c
commit d8cd66c506
4 changed files with 46 additions and 10 deletions

View File

@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
$Id$
$Source$
2001-08-20 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* tbl_properties.php3; tbl_dump.php3; lib.inc.php3; lang/*: fixed some bugs
with CSV exportations and added a Ms Excel CSV specific choice (because
we know Excel does not support <cr> in data). Thanks to
Fran<61>ois <outils@altern.org>.
2001-08-19 Olivier M<>ller <om@omnis.ch>
* db_readdump.php3: if file contains mutiple queries, only show this line:
"Your SQL-query has been executed successfully: The content of your file
@@ -40,7 +46,7 @@ $Source$
netscape3) and an other one with netscape 3 thanks to
Fran<61>ois <outils@altern.org>.
* left.php3; lang/*: checks if databases from $cfgServers[1]['only_db']
exits before displaying them at the left frame and take into account
exists before displaying them at the left frame and take into account
the case where there is no usable databases.
* Documentation.html: various updates.

View File

@@ -191,7 +191,7 @@ if (!defined('__LIB_INC__')){
else if (isset($cfgServers[$server])) {
$cfgServer = $cfgServers[$server];
// The user can work with only one database
// The user can work with only some databases
if (isset($cfgServer['only_db']) && !empty($cfgServer['only_db'])) {
if (is_array($cfgServer['only_db'])) {
$dblist = $cfgServer['only_db'];
@@ -1539,16 +1539,22 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
* @param string the table name
* @param integer the offset on this table
* @param integer the last row to get
* @param string the separation string
* @param string the field separator character
* @param string the optionnal "enclosed by" character
* @param string the handler (function) to call. It must accept one
* parameter ($sql_insert)
*
* @global string whether to obtain an excel compatible csv format or a
* simple csv one
*
* @return boolean always true
*/
function get_table_csv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $handler)
function get_table_csv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $enc_by, $handler)
{
// Handles the separator character
if (empty($sep)) {
global $what;
// Handles the "separator" and the optionnal "enclosed by" characters
if (empty($sep) || $what == 'excel') {
$sep = ';';
}
else {
@@ -1557,6 +1563,15 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
}
$sep = str_replace('\\t', "\011", $sep);
}
if (empty($enc_by) || $what == 'excel') {
$enc_by = '"';
}
else {
if (get_magic_quotes_gpc()) {
$enc_by = stripslashes($enc_by);
}
$enc_by = str_replace('&quot;', '"', $enc_by);
}
// Defines the offsets to use
if ($limit_from > 0) {
@@ -1584,6 +1599,15 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
$schema_insert .= 'NULL';
}
else if ($row[$j] != '') {
if ($what == 'excel') {
$row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]);
$re_test = "$enc_by|$sep|\012";
} else {
$re_test = "[$enc_by$sep]";
}
if (ereg($re_test, $row[$j])) {
$row[$j] = $enc_by . str_replace($enc_by, $enc_by . $enc_by, $row[$j]) . $enc_by;
}
$schema_insert .= $row[$j];
}
else {

View File

@@ -44,7 +44,9 @@ function my_csvhandler($sql_insert)
global $tmp_buffer;
// Handles the EOL character
if (empty($add_character)) {
if ($GLOBALS['what'] == 'excel') {
$add_character = "\r\n";
} else if (empty($add_character)) {
$add_character = $GLOBALS['crlf'];
} else {
if (get_magic_quotes_gpc()) {
@@ -118,7 +120,7 @@ else {
$ext = 'bz2';
} else if (isset($gzip) && $gzip == 'gzip') {
$ext = 'gz';
} else if ($what == 'csv') {
} else if ($what == 'csv' || $what == 'excel') {
$ext = 'csv';
} else {
$ext = 'sql';
@@ -151,7 +153,7 @@ if ($num_tables == 0) {
// At least on table -> do the work
else {
// No csv format -> add some comments at the top
if ($what != 'csv') {
if ($what != 'csv' && $what != 'excel') {
$dump_buffer .= '# phpMyAdmin MySQL-Dump' . $crlf
. '# version ' . PHPMYADMIN_VERSION . $crlf
. '# http://phpwizard.net/phpMyAdmin/' . $crlf
@@ -216,7 +218,7 @@ else {
// 'csv' case
else {
$tmp_buffer = '';
get_table_csv($db, $table, $limit_from, $limit_to, $separator, 'my_csvhandler');
get_table_csv($db, $table, $limit_from, $limit_to, $separator, $enclosed, 'my_csvhandler');
$dump_buffer .= $tmp_buffer;
} // end 'csv case
} // end building the dump

View File

@@ -675,8 +675,12 @@ echo "\n";
<?php echo $strStrucData; ?>&nbsp;&nbsp;<br />
<input type="radio" name="what" value="dataonly" />
<?php echo $strDataOnly; ?>&nbsp;&nbsp;<br />
<input type="radio" name="what" value="excel" />
<?php echo $strStrucExcelCSV; ?>&nbsp;&nbsp;<br />
<input type="radio" name="what" value="csv" />
<?php echo $strStrucCSV;?>&nbsp;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strFields . ' '. $strEnclosedBy; ?>&nbsp;
<input type="text" name="enclosed" size="1" value="&quot;" />&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strFields . ' '. $strTerminatedBy; ?>&nbsp;
<input type="text" name="separator" size="2" value=";" />&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strLines . ' '. $strTerminatedBy; ?>&nbsp;