You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the function executes query by query and fails on one with incorrect syntax. This means that prior queries were executed. So we are left with a half-baked import. Either all or none of the queries should be executed. So maybe it would be a good idea to implement transactions into the import function?
Sorry if this is not how one should suggest this.
protected function import()
{
$query = '';
$this->pdo->beginTransaction();
try {
while (!feof($this->file)) {
$line = fgets($this->file);
$trim = trim($line);
if ($trim === '' || strpos($trim, '--') === 0 || strpos($trim, '/*') === 0) {
continue;
}
if (strpos($trim, 'DELIMITER ') === 0) {
$this->delimiter = substr($trim, 10);
continue;
}
$query .= $line;
if (substr($trim, strlen($this->delimiter) * -1) === $this->delimiter) {
$this->pdo->exec(substr(trim($query), 0, strlen($this->delimiter) * -1));
$query = '';
}
}
$this->pdo->commit();
} catch (\PDOException $e) {
$this->pdo->rollBack();
// throws \PDOException as Exception to make things easier
throw new Exception($e->getMessage(), $e->getCode(), $e);
}
}
The text was updated successfully, but these errors were encountered:
Currently the function executes query by query and fails on one with incorrect syntax. This means that prior queries were executed. So we are left with a half-baked import. Either all or none of the queries should be executed. So maybe it would be a good idea to implement transactions into the import function?
Sorry if this is not how one should suggest this.
The text was updated successfully, but these errors were encountered: