added an extended inserts option for dumps of data

This commit is contained in:
Loïc Chapeaux
2001-08-20 11:40:07 +00:00
parent c16d1d7760
commit a4d05729f1
5 changed files with 63 additions and 21 deletions

View File

@@ -6,10 +6,12 @@ $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<EFBFBD>ois <outils@altern.org>.
* db_details.php3; 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>.
- added an extended inserts option for dumps of data.
2001-08-19 Olivier M<>ller <om@omnis.ch>
* db_readdump.php3: if file contains mutiple queries, only show this line:

View File

@@ -458,6 +458,12 @@ if ($num_tables > 0) {
<?php echo $strCompleteInserts . "\n"; ?>
</td>
</tr>
<tr>
<td<?php echo $colspan; ?>>
<input type="checkbox" name="extended_ins" value="yes" />
<?php echo $strExtendedInserts . "\n"; ?>
</td>
</tr>
<?php
// Add backquotes checkbox
if (MYSQL_MAJOR_VERSION >= 3.23 && intval(MYSQL_MINOR_VERSION) >= 6) {
@@ -537,7 +543,7 @@ echo ' ' . '&nbsp;<input type="submit" value="' . $strGo . '" />' . "\n";
</form>
</li>
<!-- Drop table -->
<!-- Drop database -->
<li>
<a href="sql.php3?server=<?php echo $server; ?>&lang=<?php echo $lang; ?>&db=<?php echo $db; ?>&sql_query=<?php echo urlencode('DROP DATABASE ' . backquote($db)); ?>&zero_rows=<?php echo urlencode($strDatabase . ' ' . htmlspecialchars(backquote($db)) . ' ' . $strHasBeenDropped); ?>&goto=main.php3&back=db_details.php3&reload=true">
<?php echo $strDropDB . ' ' . htmlspecialchars($db); ?></a>

View File

@@ -1347,9 +1347,10 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
$result = mysql_query('SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query) or mysql_die();
if ($result != FALSE) {
$fields_cnt = mysql_num_fields($result);
// Checks whether the field is an integer or not
for ($j = 0; $j < mysql_num_fields($result); $j++) {
for ($j = 0; $j < $fields_cnt; $j++) {
$field_set[$j] = backquote(mysql_field_name($result, $j), $use_backquotes);
$type = mysql_field_type($result, $j);
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
@@ -1370,15 +1371,14 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
. ' VALUES (';
}
$field_count = mysql_num_fields($result);
$search = array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
$replace = array("\\n","\\r","\Z");
$search = array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
$replace = array("\\n","\\r","\Z");
$isFirstRow = TRUE;
@set_time_limit(1200); // 20 Minutes
while ($row = mysql_fetch_row($result)) {
for ($j = 0; $j < $field_count; $j++) {
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j])) {
$values[] = 'NULL';
} else if (!empty($row[$j])) {
@@ -1395,12 +1395,29 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
} // end if
} // end for
$insert_line = $schema_insert . implode(',', $values) . ')';
// Extended inserts case
if (isset($GLOBALS['extended_ins'])) {
if ($isFirstRow) {
$insert_line = $schema_insert . implode(',', $values) . ')';
$isFirstRow = FALSE;
} else {
$insert_line = '(' . implode(',', $values) . ')';
}
}
// Other inserts case
else {
$insert_line = $schema_insert . implode(',', $values) . ')';
}
unset($values);
// Call the handler
$handler($insert_line);
} // 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)
return TRUE;
@@ -1433,8 +1450,10 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
{
global $use_backquotes;
$result = mysql_query('SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query) or mysql_die();
$i = 0;
$result = mysql_query('SELECT * FROM ' . backquote($db) . '.' . backquote($table) . $add_query) or mysql_die();
$i = 0;
$isFirstRow = TRUE;
while ($row = mysql_fetch_row($result)) {
@set_time_limit(60); // HaRa
$table_list = '(';
@@ -1446,12 +1465,17 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
$table_list = substr($table_list, 0, -2);
$table_list .= ')';
if (isset($GLOBALS['showcolumns'])) {
$schema_insert = 'INSERT INTO ' . backquote(html_format($table), $use_backquotes)
. ' ' . html_format($table_list) . ' VALUES (';
if (isset($GLOBALS['extended_ins']) && !$isFirstRow) {
$schema_insert = '(';
} else {
$schema_insert = 'INSERT INTO ' . backquote(html_format($table), $use_backquotes)
. ' VALUES (';
if (isset($GLOBALS['showcolumns'])) {
$schema_insert = 'INSERT INTO ' . backquote(html_format($table), $use_backquotes)
. ' ' . html_format($table_list) . ' VALUES (';
} else {
$schema_insert = 'INSERT INTO ' . backquote(html_format($table), $use_backquotes)
. ' VALUES (';
}
$isFirstRow = FALSE;
}
for ($j = 0; $j < mysql_num_fields($result); $j++) {
@@ -1484,6 +1508,11 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
++$i;
} // end while
// 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 'get_table_content_old()' function
@@ -1692,6 +1721,7 @@ var errorMsg2 = '<?php echo(str_replace('\'', '\\\'', $GLOBALS['strNotValidNumbe
} // end of the 'split_sql_file()' function
/* ------------------------ The bookmark feature ----------------------- */
/**

View File

@@ -14,13 +14,15 @@ function my_handler($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
if (empty($GLOBALS['asfile'])) {
$tmp_buffer .= htmlspecialchars($sql_insert . ';' . $GLOBALS['crlf']);
$tmp_buffer .= htmlspecialchars($sql_insert . $eol_dlm . $GLOBALS['crlf']);
}
// Result will be save in a file
else {
$tmp_buffer .= $sql_insert . ';' . $GLOBALS['crlf'];
$tmp_buffer .= $sql_insert . $eol_dlm . $GLOBALS['crlf'];
}
} // end of the 'my_handler()' function

View File

@@ -691,6 +691,8 @@ echo "\n";
<?php echo $strStrucDrop; ?><br />
<input type="checkbox" name="showcolumns" value="yes" />
<?php echo $strCompleteInserts; ?><br />
<input type="checkbox" name="extended_ins" value="yes" />
<?php echo $strExtendedInserts; ?><br />
<?php
// Add backquotes checkbox
if (MYSQL_MAJOR_VERSION >= 3.23 && intval(MYSQL_MINOR_VERSION) >= 6) {