Remove old import process.

Minor coding stylo modifications.

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
This commit is contained in:
Hugues Peccatte 2014-10-25 12:38:11 +02:00
parent 35bbe992d0
commit dec77b5796

View File

@ -371,10 +371,13 @@ class ImportSql extends ImportPlugin
}
$query = $this->_stringFunctionsToUse['substr'](
$data, 0, $positionDelimiter + $this->_stringFunctionsToUse['strlen']($this->_delimiter)
$data,
0,
$positionDelimiter + $this->_stringFunctionsToUse['strlen']($this->_delimiter)
);
$data = $this->_stringFunctionsToUse['substr'](
$data, $positionDelimiter + $this->_stringFunctionsToUse['strlen']($this->_delimiter)
$data,
$positionDelimiter + $this->_stringFunctionsToUse['strlen']($this->_delimiter)
);
$data = ltrim($data);
PMA_importRunQuery(
@ -388,323 +391,8 @@ class ImportSql extends ImportPlugin
$query = null;
}
//$data = trim($data);
PMA_importRunQuery(
'',
$data,
false,
$sql_data
);
PMA_importRunQuery('', '', false, $sql_data);
return;
while (! ($GLOBALS['finished'] && $posInQueryString >= $len)
&& ! $error
&& ! $timeout_passed
) {
$data = PMA_importGetNextChunk();
if ($data === false) {
// subtract data we didn't handle yet and stop processing
$GLOBALS['offset'] -= /*overload*/mb_strlen($query);
break;
} elseif ($data === true) {
// Handle rest of buffer
} else {
// Append new data to buffer
$query .= $data;
// free memory
unset($data);
// Do not parse string when we're not at the end
// and don't have ; inside
if (/*overload*/mb_strpos($query, $sql_delimiter, $posInQueryString) === false
&& ! $GLOBALS['finished']
) {
continue;
}
}
// Convert CR (but not CRLF) to LF otherwise all queries
// may not get executed on some platforms
$query = preg_replace("/\r($|[^\n])/", "\n$1", $query);
// Current length of our buffer
$len = /*overload*/mb_strlen($query);
// Grab some SQL queries out of it
while ($posInQueryString < $len) {
$found_delimiter = false;
// Find first interesting character
$old_i = $posInQueryString;
// this is about 7 times faster that looking for each sequence i
// one by one with strpos()
$posPattern = /*overload*/mb_preg_strpos(
'/(\'|"|#|-- |\/\*|`|(?i)(?<![A-Z0-9_])'
. $delimiter_keyword . ')/',
$query,
$posInQueryString
);
if (false !== $posPattern) {
// in $matches, index 0 contains the match for the complete
// expression but we don't use it
$first_position = $posPattern;
} else {
$first_position = $big_value;
}
// the cost of doing this one with preg_match() would be too high
$first_sql_delimiter = /*overload*/mb_strpos(
$query,
$sql_delimiter,
$posInQueryString
);
if ($first_sql_delimiter === false) {
$first_sql_delimiter = $big_value;
} else {
$found_delimiter = true;
}
// set $i to the position of the first quote,
// comment.start or delimiter found
$posInQueryString = min($first_position, $first_sql_delimiter);
if ($posInQueryString == $big_value) {
// none of the above was found in the string
$posInQueryString = $old_i;
if (! $GLOBALS['finished']) {
break;
}
// at the end there might be some whitespace...
if (trim($query) == '') {
$query = '';
$len = 0;
break;
}
// We hit end of query, go there!
$posInQueryString = /*overload*/mb_strlen($query) - 1;
}
// Grab current character
//$ch = $buffer[$i]; //Don't use this syntax, because of UTF8 strings
$ch = /*overload*/mb_substr($query, $posInQueryString, 1);
// Quotes
if (strpos('\'"`', $ch) !== false) {
$quote = $ch;
$endq = false;
while (! $endq) {
// Find next quote
$posQuote = /*overload*/mb_strpos($query, $quote, $posInQueryString + 1);
/*
* Behave same as MySQL and accept end of query as end
* of backtick.
* I know this is sick, but MySQL behaves like this:
*
* SELECT * FROM `table
*
* is treated like
*
* SELECT * FROM `table`
*/
if ($posQuote === false && $quote == '`'
&& $found_delimiter
) {
$posQuote = $first_sql_delimiter - 1;
} elseif ($posQuote === false) {// No quote? Too short string
// We hit end of string => unclosed quote,
// but we handle it as end of query
list($endq, $posInQueryString) = $this
->getEndQuoteAndPos($len, $endq, $posInQueryString);
$found_delimiter = false;
break;
}
// Was not the quote escaped?
$posEscape = $posQuote - 1;
while (/*overload*/mb_substr($query, $posEscape, 1) == '\\') {
$posEscape--;
}
// Even count means it was not escaped
$endq = (((($posQuote - 1) - $posEscape) % 2) == 0);
// Skip the string
$posInQueryString = $posQuote;
if ($first_sql_delimiter < $posQuote) {
$found_delimiter = false;
}
}
if (! $endq) {
break;
}
$posInQueryString++;
// Aren't we at the end?
if ($GLOBALS['finished'] && $posInQueryString == $len) {
$posInQueryString--;
} else {
continue;
}
}
// Not enough data to decide
if ((($posInQueryString == ($len - 1) && ($ch == '-' || $ch == '/'))
|| ($posInQueryString == ($len - 2) && (($ch == '-'
&& /*overload*/mb_substr($query, $posInQueryString + 1, 1) == '-')
|| ($ch == '/'
&& /*overload*/mb_substr($query, $posInQueryString + 1, 1) == '*'))))
&& ! $GLOBALS['finished']
) {
break;
}
// Comments
if ($ch == '#'
|| ($posInQueryString < ($len - 1) && $ch == '-'
&& /*overload*/mb_substr($query, $posInQueryString + 1, 1) == '-'
&& (($posInQueryString < ($len - 2)
&& /*overload*/mb_substr($query, $posInQueryString + 2, 1) <= ' ')
|| ($posInQueryString == ($len - 1) && $GLOBALS['finished'])))
|| ($posInQueryString < ($len - 1) && $ch == '/'
&& /*overload*/mb_substr($query, $posInQueryString + 1, 1) == '*')
) {
// Copy current string to SQL
if ($start_pos != $posInQueryString) {
$sql .= /*overload*/mb_substr(
$query,
$start_pos,
$posInQueryString - $start_pos
);
}
// Skip the rest
$start_of_comment = $posInQueryString;
// do not use PHP_EOL here instead of "\n", because the export
// file might have been produced on a different system
$posInQueryString = /*overload*/mb_strpos(
$query,
$ch == '/' ? '*/' : "\n",
$posInQueryString
);
// didn't we hit end of string?
if ($posInQueryString === false) {
if ($GLOBALS['finished']) {
$posInQueryString = $len - 1;
} else {
break;
}
}
// Skip *
if ($ch == '/') {
$posInQueryString++;
}
// Skip last char
$posInQueryString++;
// We need to send the comment part in case we are defining
// a procedure or function and comments in it are valuable
$sql .= /*overload*/mb_substr(
$query,
$start_of_comment,
$posInQueryString - $start_of_comment
);
// Next query part will start here
$start_pos = $posInQueryString;
// Aren't we at the end?
if ($posInQueryString == $len) {
$posInQueryString--;
} else {
continue;
}
}
// Change delimiter, if redefined, and skip it
// (don't send to server!)
if (($posInQueryString + $length_of_delimiter_keyword < $len)
&& /*overload*/mb_strtoupper(
/*overload*/mb_substr($query, $posInQueryString, $length_of_delimiter_keyword)
) == $delimiter_keyword
) {
// look for EOL on the character immediately after 'DELIMITER '
// (see previous comment about PHP_EOL)
$new_line_pos = /*overload*/mb_strpos(
$query,
"\n",
$posInQueryString + $length_of_delimiter_keyword
);
// it might happen that there is no EOL
if (false === $new_line_pos) {
$new_line_pos = $len;
}
$sql_delimiter = /*overload*/mb_substr(
$query,
$posInQueryString + $length_of_delimiter_keyword,
$new_line_pos - $posInQueryString - $length_of_delimiter_keyword
);
$posInQueryString = $new_line_pos + 1;
// Next query part will start here
$start_pos = $posInQueryString;
continue;
}
// End of SQL
if ($found_delimiter
|| ($GLOBALS['finished']
&& ($posInQueryString == $len - 1))
) {
$tmp_sql = $sql;
if ($start_pos < $len) {
$length_to_grab = $posInQueryString - $start_pos;
if (! $found_delimiter) {
$length_to_grab++;
}
$tmp_sql .= /*overload*/mb_substr(
$query,
$start_pos,
$length_to_grab
);
unset($length_to_grab);
}
// Do not try to execute empty SQL
if (! preg_match('/^([\s]*;)*$/', trim($tmp_sql))) {
$sql = $tmp_sql;
PMA_importRunQuery(
$sql,
/*overload*/mb_substr(
$query,
0,
$posInQueryString + /*overload*/mb_strlen($sql_delimiter)
),
false,
$sql_data
);
$query = /*overload*/mb_substr(
$query,
$posInQueryString + /*overload*/mb_strlen($sql_delimiter)
);
// Reset parser:
$len = /*overload*/mb_strlen($query);
$sql = '';
$posInQueryString = 0;
$start_pos = 0;
// Any chance we will get a complete query?
//if ((strpos($buffer, ';') === false)
//&& ! $GLOBALS['finished']) {
if (/*overload*/mb_strpos($query, $sql_delimiter) === false
&& ! $GLOBALS['finished']
) {
break;
}
} else {
$posInQueryString++;
$start_pos = $posInQueryString;
}
}
} // End of parser loop
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery(
'',
/*overload*/mb_substr($query, 0, $len),
false,
$sql_data
);
//Commit any possible data in buffers
PMA_importRunQuery('', $data, false, $sql_data);
PMA_importRunQuery('', '', false, $sql_data);
}