diff options
author | David M <davidmj@users.sourceforge.net> | 2007-03-07 03:27:20 +0000 |
---|---|---|
committer | David M <davidmj@users.sourceforge.net> | 2007-03-07 03:27:20 +0000 |
commit | 51b2105b0bcf8420762b316ea99a81b261fc256c (patch) | |
tree | 545750ecd335eaf2598bb3891e6c6851931be5ed /phpBB/includes/acp/acp_database.php | |
parent | 484946e0d7b8478229558166c0b76667a01e02ae (diff) | |
download | forums-51b2105b0bcf8420762b316ea99a81b261fc256c.tar forums-51b2105b0bcf8420762b316ea99a81b261fc256c.tar.gz forums-51b2105b0bcf8420762b316ea99a81b261fc256c.tar.bz2 forums-51b2105b0bcf8420762b316ea99a81b261fc256c.tar.xz forums-51b2105b0bcf8420762b316ea99a81b261fc256c.zip |
- Avoid creating backups that we can't restore :)
git-svn-id: file:///svn/phpbb/trunk@7141 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acp/acp_database.php')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 110 |
1 files changed, 88 insertions, 22 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index 1842ecd98f..9361b00f5b 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -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) . ')'; - - $this->flush($sql_data); + $query .= implode(', ', $values) . ')'; - $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) . ')'; - - $this->flush($sql_data); + $query .= implode(', ', $values) . ')'; - $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); |