added the "escaped by" option for exporting CSV files so default values for importing/exporting dumps are the same.

This commit is contained in:
Loïc Chapeaux
2001-08-29 18:57:34 +00:00
parent 6d4da778cb
commit 6d4ba8b40a
4 changed files with 22 additions and 19 deletions

View File

@@ -30,10 +30,11 @@ $Source$
* tbl_copy.php3; tbl_properties.php3: re-enabled the ability to copy a * tbl_copy.php3; tbl_properties.php3: re-enabled the ability to copy a
table to another database (bug #456434). Need to be tested with table to another database (bug #456434). Need to be tested with
MySQL < 3.23 releases. MySQL < 3.23 releases.
* lib.inc.php3, lines 1154-1170: added an option to display the whole value
of a text field in a javascript alert box thanks to "Opi" <opi@volny.cz>.
* lang/english.inc.php3: re-sorted and fixed some typos. * lang/english.inc.php3: re-sorted and fixed some typos.
* left.php3: fixed a js error with NS. * left.php3: fixed a js error with NS.
* lib.inc.php3; tbl_properties.php3; tbl.dump.php3: added the "escaped by"
option for exporting CSV files so default values for importing/exporting
dumps are the same.
2001-08-28 Lo<4C>c Chapeaux <lolo@phpheaven.net> 2001-08-28 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* lang/galician.inc.php3, select_lang.inc.php3: new Galician lang thanks to * lang/galician.inc.php3, select_lang.inc.php3: new Galician lang thanks to

View File

@@ -1152,20 +1152,11 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
echo ' <td align="center">[BLOB]</td>' . "\n"; echo ' <td align="center">[BLOB]</td>' . "\n";
} else { } else {
if (strlen($row[$i]) > $GLOBALS['cfgLimitChars']) { if (strlen($row[$i]) > $GLOBALS['cfgLimitChars']) {
// loic1: added a link to display the whole text $row[$i] = substr($row[$i], 0, $GLOBALS['cfgLimitChars']) . '...';
// field in a js alert box
$alert = '';
$tmp = explode("\n", str_replace("\r", ' ', $row[$i]));
for ($j = 0; $j < count($tmp); $j++) {
$alert .= addslashes(str_replace('"', '&quot;', trim($tmp[$j]))) . '\n';
}
unset($tmp);
$row[$i] = ereg_replace("((\015\012)|(\015)|(\012))+", '<br />', htmlspecialchars($row[$i]));
$row[$i] = substr($row[$i], 0, $GLOBALS['cfgLimitChars'])
. '...&nbsp;'
. '[<a href="#" onclick="alert(\''. $alert . '\'); return false">+</a>]';
} }
// loic1 : displays <cr>/<lf>
if ($row[$i] != '') { if ($row[$i] != '') {
$row[$i] = ereg_replace("((\015\012)|(\015)|(\012))+", '<br />', htmlspecialchars($row[$i]));
echo ' <td>' . $row[$i] . '</td>' . "\n"; echo ' <td>' . $row[$i] . '</td>' . "\n";
} else { } else {
echo ' <td>&nbsp;</td>' . "\n"; echo ' <td>&nbsp;</td>' . "\n";
@@ -1607,7 +1598,7 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
* *
* @return boolean always true * @return boolean always true
*/ */
function get_table_csv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $enc_by, $handler) function get_table_csv($db, $table, $limit_from = 0, $limit_to = 0, $sep, $enc_by, $esc_by, $handler)
{ {
global $what; global $what;
@@ -1630,6 +1621,15 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
} }
$enc_by = str_replace('&quot;', '"', $enc_by); $enc_by = str_replace('&quot;', '"', $enc_by);
} }
if (empty($esc_by) || $what == 'excel') {
// double the "enclosed by" character
$esc_by = $enc_by;
}
else {
if (get_magic_quotes_gpc()) {
$esc_by = stripslashes($esc_by);
}
}
// Defines the offsets to use // Defines the offsets to use
if ($limit_from > 0) { if ($limit_from > 0) {
@@ -1663,7 +1663,7 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
$row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]); $row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]);
} }
$schema_insert .= $enc_by $schema_insert .= $enc_by
. str_replace($enc_by, $enc_by . $enc_by, $row[$j]) . str_replace($enc_by, $esc_by . $enc_by, $row[$j])
. $enc_by; . $enc_by;
} }
else { else {

View File

@@ -224,7 +224,7 @@ else {
} // end if } // end if
$tmp_buffer = ''; $tmp_buffer = '';
get_table_csv($db, $table, $limit_from, $limit_to, $separator, $enclosed, 'my_csvhandler'); get_table_csv($db, $table, $limit_from, $limit_to, $separator, $enclosed, $escaped, 'my_csvhandler');
$dump_buffer .= $tmp_buffer; $dump_buffer .= $tmp_buffer;
} // end 'csv case } // end 'csv case
} // end building the dump } // end building the dump

View File

@@ -695,10 +695,12 @@ echo "\n";
<?php echo $strStrucExcelCSV; ?>&nbsp;&nbsp;<br /> <?php echo $strStrucExcelCSV; ?>&nbsp;&nbsp;<br />
<input type="radio" name="what" value="csv" /> <input type="radio" name="what" value="csv" />
<?php echo $strStrucCSV;?>&nbsp;:<br /> <?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; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strFields . ' '. $strTerminatedBy; ?>&nbsp;
<input type="text" name="separator" size="2" value=";" />&nbsp;&nbsp;<br /> <input type="text" name="separator" size="2" value=";" />&nbsp;&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 . ' '. $strEscapedBy; ?>&nbsp;
<input type="text" name="escaped" size="2" value="\" />&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strLines . ' '. $strTerminatedBy; ?>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strLines . ' '. $strTerminatedBy; ?>&nbsp;
<input type="text" name="add_character" size="2" value="<?php echo ((which_crlf() == "\n") ? '\n' : '\r\n'); ?>" />&nbsp;&nbsp; <input type="text" name="add_character" size="2" value="<?php echo ((which_crlf() == "\n") ? '\n' : '\r\n'); ?>" />&nbsp;&nbsp;
</td> </td>