Skip to content

Commit

Permalink
Helpers::loadFromFile improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 9, 2017
1 parent 1490a9e commit 6f1637a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,21 @@ public static function loadFromFile(Connection $connection, $file): int
$delimiter = ';';
$sql = '';
$pdo = $connection->getPdo(); // native query without logging
while (!feof($handle)) {
$s = rtrim((string) fgets($handle));
while (($s = fgets($handle)) !== FALSE) {
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 6f1637a

Please sign in to comment.