diff options
Diffstat (limited to 'phpBB')
| -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);  | 
