diff options
author | David M <davidmj@users.sourceforge.net> | 2007-02-16 00:46:21 +0000 |
---|---|---|
committer | David M <davidmj@users.sourceforge.net> | 2007-02-16 00:46:21 +0000 |
commit | caf5bfffd7e15b31f040746db1a18530b2a5642f (patch) | |
tree | d5e90c2b7799c3b5c02c11bfec3cfce2fe22a78c /phpBB/includes/acp/acp_database.php | |
parent | a014f237de59b30385f750b0b17b2f62622d8e00 (diff) | |
download | forums-caf5bfffd7e15b31f040746db1a18530b2a5642f.tar forums-caf5bfffd7e15b31f040746db1a18530b2a5642f.tar.gz forums-caf5bfffd7e15b31f040746db1a18530b2a5642f.tar.bz2 forums-caf5bfffd7e15b31f040746db1a18530b2a5642f.tar.xz forums-caf5bfffd7e15b31f040746db1a18530b2a5642f.zip |
#8146
- came up with an alternate chunking algorithm, it does not require additional calls to seek (it reads exactly what it needs to and does not need to look at the same piece of data twice) and may or may not be more optimal than the previous chunking algorithm (may be faster, may use more memory). For this reason, it is only used when the stream is not seekable (bzip2 is the only format that is not seekable)
git-svn-id: file:///svn/phpbb/trunk@6990 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acp/acp_database.php')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index f450d1a284..e1ec9fa8bc 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -355,14 +355,16 @@ class acp_database $seek = 'fseek'; $eof = 'feof'; $close = 'fclose'; + $fgetd = 'fgetd'; break; case 'sql.bz2': $fp = bzopen($file_name, 'r'); $read = 'bzread'; - $seek = 'bzseek'; + $seek = ''; $eof = 'feof'; $close = 'bzclose'; + $fgetd = 'fgetd_seekless'; break; case 'sql.gz': @@ -371,6 +373,7 @@ class acp_database $seek = 'gzseek'; $eof = 'gzeof'; $close = 'gzclose'; + $fgetd = 'fgetd'; break; } @@ -382,7 +385,7 @@ class acp_database case 'sqlite': while (!$eof($fp)) { - $db->sql_query(fgetd($fp, ";\n", $read, $seek, $eof)); + $db->sql_query($fgetd($fp, ";\n", $read, $seek, $eof)); } break; @@ -390,7 +393,7 @@ class acp_database $delim = ";\n"; while (!$eof($fp)) { - $query = trim(fgetd($fp, $delim, $read, $seek, $eof)); + $query = trim($fgetd($fp, $delim, $read, $seek, $eof)); if (substr($query, 0, 8) === 'SET TERM') { $delim = $query[9] . "\n"; @@ -403,11 +406,11 @@ class acp_database case 'postgres': while (!$eof($fp)) { - $query = trim(fgetd($fp, ";\n", $read, $seek, $eof)); + $query = trim($fgetd($fp, ";\n", $read, $seek, $eof)); $db->sql_query($query); if (substr($query, 0, 4) == 'COPY') { - while (($sub = fgetd($fp, "\n", $read, $seek, $eof)) !== '\.') + while (($sub = $fgetd($fp, "\n", $read, $seek, $eof)) !== '\.') { pg_put_line($db->db_connect_id, $sub . "\n"); } @@ -420,7 +423,7 @@ class acp_database case 'oracle': while (!$eof($fp)) { - $db->sql_query(fgetd($fp, "/\n", $read, $seek, $eof)); + $db->sql_query($fgetd($fp, "/\n", $read, $seek, $eof)); } break; @@ -428,7 +431,7 @@ class acp_database case 'mssql_odbc': while (!$eof($fp)) { - $db->sql_query(fgetd($fp, "GO\n", $read, $seek, $eof)); + $db->sql_query($fgetd($fp, "GO\n", $read, $seek, $eof)); } break; } @@ -2192,4 +2195,39 @@ function fgetd(&$fp, $delim, $read, $seek, $eof, $buffer = 8192) return false; } +function fgetd_seekless(&$fp, $delim, $read, $seek, $eof, $buffer = 8192) +{ + static $array = array(); + static $record = ''; + + if (!sizeof($array)) + { + while (!$eof($fp)) + { + if (strpos($record, $delim) !== false) + { + $array = explode($delim, $record); + $record = array_pop($array); + break; + } + else + { + $record .= $read($fp, $buffer); + } + } + if ($eof($fp) && strpos($record, $delim) !== false) + { + $array = explode($delim, $record); + $record = array_pop($array); + } + } + + if (sizeof($array)) + { + return array_shift($array); + } + + return false; +} + ?>
\ No newline at end of file |