Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snaphosts branch: doesn't export functions. #68

Open
hrach opened this issue Apr 16, 2017 · 3 comments
Open

Snaphosts branch: doesn't export functions. #68

hrach opened this issue Apr 16, 2017 · 3 comments
Assignees
Labels

Comments

@hrach
Copy link
Member

hrach commented Apr 16, 2017

This is caused by MySQLDump class from https://github.com/dg/MySQL-dump

(Signaly.cz are affected by this bug, local development loose invalidateAuthorizationCache functions)

@hrach hrach added the bug label Apr 16, 2017
@hrach
Copy link
Member Author

hrach commented Apr 16, 2017

@JanTvrdik JanTvrdik self-assigned this Apr 17, 2017
@JanTvrdik
Copy link
Member

You probably meant, https://github.com/nextras/db-exporter, importer is just better API for

/**
* Loads and executes SQL queries from given file. Taken from Adminer (Apache License), modified.
*
* @author Jakub Vrána
* @author Jan Tvrdík
* @author Michael Moravec
* @author Jan Skrasek
* @license Apache License
*
* @param string $path
* @return int number of executed queries
*/
public function loadFile($path)
{
$content = @file_get_contents($path);
if ($content === FALSE) {
throw new IOException("Cannot open file '$path'.");
}
$queryOffset = 0;
$parseOffset = 0;
$queries = 0;
$space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\\n]*\\n|--\\n)";
$spacesRe = "~^{$space}*\\z~";
$delimiter = ';';
$delimiterRe = "~^{$space}*DELIMITER\\s+(\\S+)~i";
$openRe = $this instanceof PgSqlDriver ? '[\'"]|/\*|-- |\z|\$[^$]*\$' : '[\'"`#]|/\*|-- |\z';
$parseRe = "(;|$openRe)";
$endReTable = [
'\'' => '(\'|\\\\.|\z)s',
'"' => '("|\\\\.|\z)s',
'/*' => '(\*/|\z)',
'[' => '(]|\z)',
];
while (TRUE) {
if (preg_match($delimiterRe, $content, $match, 0, $queryOffset)) {
$delimiter = $match[1];
$queryOffset += strlen($match[0]);
$parseOffset += strlen($match[0]);
$parseRe = '(' . preg_quote($delimiter) . "|$openRe)";
}
while (TRUE) {
preg_match($parseRe, $content, $match, PREG_OFFSET_CAPTURE, $parseOffset); // should always match
$found = $match[0][0];
$parseOffset = $match[0][1] + strlen($found);
if ($found === $delimiter) { // delimited query
$queryLength = $match[0][1] - $queryOffset;
break;
} elseif ($found) { // find matching quote or comment end
$endRe = isset($endReTable[$found]) ? $endReTable[$found] : '(' . (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\.") . '|\z)s';
while (preg_match($endRe, $content, $match, PREG_OFFSET_CAPTURE, $parseOffset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
$s = $match[0][0];
$parseOffset = $match[0][1] + strlen($s);
if ($s[0] !== '\\') {
continue 2;
}
}
} else { // last query or EOF
if (preg_match($spacesRe, substr($content, $queryOffset))) {
break 2;
} else {
$queryLength = $match[0][1] - $queryOffset;
break;
}
}
}
$q = substr($content, $queryOffset, $queryLength);
$queries++;
$this->dbal->exec($q);
$queryOffset = $parseOffset;
}
return $queries;
}

@hrach
Copy link
Member Author

hrach commented Apr 17, 2017

Yes :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants