From 0af8b665999dbd781fdd025fa0ab082975b18fb5 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Wed, 3 Mar 2010 17:46:21 +0000 Subject: [PATCH] [2.0][DDC-389] Fixed the PHPDriver that was causing a fatal error when classes uses inheritance type join. Thanks Tiago Ferreira for report and patch. --- .../DBAL/Tools/Cli/Tasks/RunSqlTask.php | 55 ++++++++++++++++++- lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php | 2 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Tools/Cli/Tasks/RunSqlTask.php b/lib/Doctrine/DBAL/Tools/Cli/Tasks/RunSqlTask.php index 5b6bb7b95..5100c9c64 100644 --- a/lib/Doctrine/DBAL/Tools/Cli/Tasks/RunSqlTask.php +++ b/lib/Doctrine/DBAL/Tools/Cli/Tasks/RunSqlTask.php @@ -99,7 +99,60 @@ class RunSqlTask extends AbstractTask $arguments = $this->getArguments(); if (isset($arguments['file'])) { - //TODO + $em = $this->getConfiguration()->getAttribute('em'); + $conn = $em->getConnection(); + $printer = $this->getPrinter(); + + $fileNames = (array) $arguments['file']; + + foreach ($fileNames as $fileName) { + if ( ! file_exists($fileName)) { + throw new CliException(sprintf('The SQL file [%s] does not exist.', $fileName)); + } else if ( ! is_readable($fileName)) { + throw new CliException(sprintf('The SQL file [%s] does not have read permissions.', $fileName)); + } + + $printer->write('Processing file [' . $fileName . ']... '); + $sql = file_get_contents($fileName); + + if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { + // PDO Drivers + try { + $lines = 0; + + $stmt = $conn->prepare($sql); + $stmt->execute(); + + do { + // Required due to "MySQL has gone away!" issue + $stmt->fetch(); + $stmt->closeCursor(); + + $lines++; + } while ($stmt->nextRowset()); + + $printer->writeln(sprintf('%d statements executed!', $lines)); + } catch (\PDOException $e) { + $printer->writeln('error!') + ->writeln($e->getMessage()); + } + } else { + // Non-PDO Drivers (ie. OCI8 driver) + $stmt = $conn->prepare($sql); + $rs = $stmt->execute(); + + if ($rs) { + $printer->writeln('OK!'); + } else { + $error = $stmt->errorInfo(); + + $printer->writeln('error!') + ->writeln($error['message']); + } + + $stmt->closeCursor(); + } + } } else if (isset($arguments['sql'])) { $em = $this->getConfiguration()->getAttribute('em'); diff --git a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php index 8be5c031f..c4bde7bb7 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php @@ -121,7 +121,7 @@ class PhpDriver implements Driver { $path = $this->_classPaths[$className]; - include $path; + require_once $path; } /**