mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 21:38:54 +00:00
- Avoid creating backups that we can't restore :)
git-svn-id: file:///svn/phpbb/trunk@7141 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
484946e0d7
commit
51b2105b0b
1 changed files with 88 additions and 22 deletions
|
@ -625,23 +625,25 @@ class mysql_extractor extends base_extractor
|
|||
{
|
||||
$field_set[] = $field[$j]->name;
|
||||
}
|
||||
|
||||
|
||||
$search = array("\\", "'", "\x00", "\x0a", "\x0d", "\x1a", '"');
|
||||
$replace = array("\\\\", "\\'", '\0', '\n', '\r', '\Z', '\\"');
|
||||
$fields = implode(', ', $field_set);
|
||||
$sql_data = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
|
||||
$first_set = true;
|
||||
$query_len = 0;
|
||||
$max_len = get_usable_memory();
|
||||
|
||||
while ($row = mysqli_fetch_row($result))
|
||||
{
|
||||
$values = array();
|
||||
if ($first_set)
|
||||
{
|
||||
$sql_data .= '(';
|
||||
$query = $sql_data . '(';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_data .= ',(';
|
||||
$query .= ',(';
|
||||
}
|
||||
|
||||
for ($j = 0; $j < $fields_cnt; $j++)
|
||||
|
@ -659,18 +661,27 @@ class mysql_extractor extends base_extractor
|
|||
$values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
|
||||
}
|
||||
}
|
||||
$sql_data .= implode(', ', $values) . ')';
|
||||
$query .= implode(', ', $values) . ')';
|
||||
|
||||
$this->flush($sql_data);
|
||||
|
||||
$sql_data = '';
|
||||
$first_set = false;
|
||||
$query_len += strlen($query);
|
||||
if ($query_len > $max_len)
|
||||
{
|
||||
$this->flush($query . ";\n\n");
|
||||
$query = '';
|
||||
$query_len = 0;
|
||||
$first_set = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$first_set = false;
|
||||
}
|
||||
}
|
||||
mysqli_free_result($result);
|
||||
|
||||
if (!$first_set)
|
||||
// check to make sure we have nothing left to flush
|
||||
if (!$first_set && $query)
|
||||
{
|
||||
$this->flush(";\n\n");
|
||||
$this->flush($query . ";\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -702,20 +713,21 @@ class mysql_extractor extends base_extractor
|
|||
$search = array("\\", "'", "\x00", "\x0a", "\x0d", "\x1a", '"');
|
||||
$replace = array("\\\\", "\\'", '\0', '\n', '\r', '\Z', '\\"');
|
||||
$fields = implode(', ', $field_set);
|
||||
$sql_data = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
|
||||
|
||||
$first_set = true;
|
||||
$sql_data = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
|
||||
$first_set = true;
|
||||
$query_len = 0;
|
||||
$max_len = get_usable_memory();
|
||||
|
||||
while ($row = mysql_fetch_row($result))
|
||||
{
|
||||
$values = array();
|
||||
if ($first_set)
|
||||
{
|
||||
$sql_data .= '(';
|
||||
$query = $sql_data . '(';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_data .= ',(';
|
||||
$query .= ',(';
|
||||
}
|
||||
|
||||
for ($j = 0; $j < $fields_cnt; $j++)
|
||||
|
@ -733,18 +745,27 @@ class mysql_extractor extends base_extractor
|
|||
$values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
|
||||
}
|
||||
}
|
||||
$sql_data .= implode(', ', $values) . ')';
|
||||
$query .= implode(', ', $values) . ')';
|
||||
|
||||
$this->flush($sql_data);
|
||||
|
||||
$sql_data = '';
|
||||
$first_set = false;
|
||||
$query_len += strlen($query);
|
||||
if ($query_len > $max_len)
|
||||
{
|
||||
$this->flush($query . ";\n\n");
|
||||
$query = '';
|
||||
$query_len = 0;
|
||||
$first_set = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$first_set = false;
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
|
||||
if (!$first_set)
|
||||
// check to make sure we have nothing left to flush
|
||||
if (!$first_set && $query)
|
||||
{
|
||||
$this->flush(";\n\n");
|
||||
$this->flush($query . ";\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2061,6 +2082,51 @@ class firebird_extractor extends base_extractor
|
|||
}
|
||||
}
|
||||
|
||||
// get how much space we allow for a chunk of data, very similar to phpMyAdmin's way of doing things ;-) (hey, we only do this for MySQL anyway :P)
|
||||
function get_usable_memory()
|
||||
{
|
||||
$val = trim(@ini_get('memory_limit'));
|
||||
|
||||
if (preg_match('/(\\d+)([mkg]?)/i', $val, $regs))
|
||||
{
|
||||
$memory_limit = (int) $regs[1];
|
||||
switch ($regs[2])
|
||||
{
|
||||
|
||||
case 'k':
|
||||
case 'K':
|
||||
$memory_limit *= 1024;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
$memory_limit *= 1048576;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
$memory_limit *= 1073741824;
|
||||
break;
|
||||
}
|
||||
|
||||
// how much memory PHP requires at the start of export (it is really a little less)
|
||||
if ($memory_limit > 6100000)
|
||||
{
|
||||
$memory_limit -= 6100000;
|
||||
}
|
||||
|
||||
// allow us to consume half of the total memory available
|
||||
$memory_limit /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the buffer to 1M if we have no clue how much memory PHP will give us :P
|
||||
$memory_limit = 1048576;
|
||||
}
|
||||
|
||||
return $memory_limit;
|
||||
}
|
||||
|
||||
function sanitize_data_mssql($text)
|
||||
{
|
||||
$data = preg_split('/[\n\t\r\b\f]/', $text);
|
||||
|
|
Loading…
Add table
Reference in a new issue