Skip to content

Commit

Permalink
Helpers::loadFromFile improved whitespace handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 24, 2017
1 parent 1490a9e commit eda00f8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Database/Helpers.php
Expand Up @@ -193,21 +193,21 @@ public static function loadFromFile(Connection $connection, $file): int
$sql = '';
$pdo = $connection->getPdo(); // native query without logging
while (!feof($handle)) {
$s = rtrim((string) fgets($handle));
$s = (string) fgets($handle);
if (!strncasecmp($s, 'DELIMITER ', 10)) {
$delimiter = substr($s, 10);
$delimiter = trim(substr($s, 10));

} elseif (substr($s, -strlen($delimiter)) === $delimiter) {
$sql .= substr($s, 0, -strlen($delimiter));
} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
$sql .= substr($ts, 0, -strlen($delimiter));
$pdo->exec($sql);
$sql = '';
$count++;

} else {
$sql .= $s . "\n";
$sql .= $s;
}
}
if (trim($sql) !== '') {
if (rtrim($sql) !== '') {
$pdo->exec($sql);
$count++;
}
Expand Down

0 comments on commit eda00f8

Please sign in to comment.