Skip to content

Commit

Permalink
Fixed issue #4760: Lowered memory requirement for database dump on MySQL
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@9548 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 28, 2010
1 parent 5167f0b commit 02900a4
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions admin/dumpdb.php
Expand Up @@ -74,12 +74,12 @@ function defdump($tablename)
{
global $connect;
$def = "";
$def .="#------------------------------------------"."\n";
$def .="# Table definition for $tablename"."\n";
$def .="#------------------------------------------"."\n";
$def .= "DROP TABLE IF EXISTS $tablename;"."\n"."\n";
$def .= "CREATE TABLE $tablename ("."\n";
$result = db_execute_assoc("SHOW COLUMNS FROM $tablename") or die("Table $tablename not existing in database");
$def .="#\n";
$def .="# Table definition for {$tablename}"."\n";
$def .="#\n";
$def .= "DROP TABLE IF EXISTS {$tablename};"."\n"."\n";
$def .= "CREATE TABLE {$tablename} ("."\n";
$result = db_execute_assoc("SHOW COLUMNS FROM {$tablename}") or die("Table $tablename not existing in database");
while($row = $result->FetchRow())
{
$def .= " `$row[Field]` $row[Type]";
Expand Down Expand Up @@ -116,34 +116,41 @@ function datadump ($table) {

global $connect;

$result = "#------------------------------------------"."\n";
$result = "#\n";
$result .="# Table data for $table"."\n";
$result .="#------------------------------------------"."\n";
$result .="#\n";

$query = db_execute_num("select * from $table");
$num_fields = $query->FieldCount();
$aFieldNames= $connect->MetaColumnNames($table, true);
$sFieldNames= implode('`,`',$aFieldNames);
$numrow = $query->RecordCount();

while($row=$query->FetchRow()){
@set_time_limit(5);
$result .= "INSERT INTO ".$table." VALUES(";
for($j=0; $j<$num_fields; $j++) {
if (isset($row[$j]) && !is_null($row[$j]))
{
$row[$j] = addslashes($row[$j]);
$row[$j] = preg_replace("#\n#","\\n",$row[$j]);
$result .= "\"$row[$j]\"";
}
else
{
$result .= "NULL";
if ($numrow>0)
{
$result .= "INSERT INTO `{$table}` (`{$sFieldNames}`) VALUES";
while($row=$query->FetchRow()){
@set_time_limit(5);
$result .= "(";
for($j=0; $j<$num_fields; $j++) {
if (isset($row[$j]) && !is_null($row[$j]))
{
$row[$j] = addslashes($row[$j]);
$row[$j] = preg_replace("#\n#","\\n",$row[$j]);
$result .= "\"$row[$j]\"";
}
else
{
$result .= "NULL";
}

if ($j<($num_fields-1)) $result .= ",";
}

if ($j<($num_fields-1)) $result .= ",";
}
$result .= ");\n";
} // while
return $result . "\n\n\n";
$result .= "),\n";
} // while
$result=substr($result,0,-2);
}
return $result . ";\n\n";
}

?>

0 comments on commit 02900a4

Please sign in to comment.