diff --git a/src/WebinoDbDump/Db/Dump/Adapter.php b/src/WebinoDbDump/Db/Dump/Adapter.php index 8b0c3db..915cff4 100644 --- a/src/WebinoDbDump/Db/Dump/Adapter.php +++ b/src/WebinoDbDump/Db/Dump/Adapter.php @@ -3,19 +3,19 @@ * Webino (http://webino.sk) * * @link https://github.com/webino/WebinoDbDump/ for the canonical source repository - * @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk) + * @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk) + * @author Peter Bačinský * @license The BSD 3-Clause License */ namespace WebinoDbDump\Db\Dump; +use WebinoDbDump\Exception; use Zend\Db\Adapter\Adapter as DbAdapter; use Zend\Db\Adapter\AdapterInterface as DbAdapterInterface; /** * Database dump utility adapter - * - * @author Peter Bačinský */ class Adapter { @@ -53,9 +53,16 @@ public function getSchema() /** * @param string $sql * @return \Zend\Db\ResultSet\ResultSet + * @throws Exception\SqlQueryException */ public function executeQuery($sql) { - return $this->adapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE); + try { + return $this->adapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE); + } catch (\Exception $exc) { + throw new Exception\SqlQueryException( + PHP_EOL . $exc->getMessage() . PHP_EOL . $sql . PHP_EOL + ); + } } } diff --git a/src/WebinoDbDump/Db/Dump/Dump.php b/src/WebinoDbDump/Db/Dump/Dump.php index 0e2eb9e..7b32576 100644 --- a/src/WebinoDbDump/Db/Dump/Dump.php +++ b/src/WebinoDbDump/Db/Dump/Dump.php @@ -3,7 +3,8 @@ * Webino (http://webino.sk) * * @link https://github.com/webino/WebinoDbDump/ for the canonical source repository - * @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk) + * @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk) + * @author Peter Bačinský * @license The BSD 3-Clause License */ @@ -13,13 +14,12 @@ use WebinoDbDump\Db\Dump\Platform\PlatformInterface; use WebinoDbDump\Db\Sql\SqlFile; use WebinoDbDump\Db\Sql\SqlInterface; +use WebinoDbDump\Exception; use WebinoDbDump\Module; use Zend\Db\Adapter\AdapterInterface; /** * Database dump utility - * - * @author Peter Bačinský */ class Dump implements DumpInterface { @@ -49,6 +49,7 @@ public function __construct($adapter) /** * @param AdapterInterface|Adapter $adapter * @return $this + * @throws Exception\InvalidArgumentException */ protected function setAdapter($adapter) { @@ -56,8 +57,7 @@ protected function setAdapter($adapter) $adapter = new Adapter($adapter); } elseif (!($adapter instanceof Adapter)) { - // TODO exception - throw new \InvalidArgumentException('Expected Db\Adapter or Dump\Adapter'); + throw new Exception\InvalidArgumentException('Expected Db\Adapter or Dump\Adapter'); } $this->adapter = $adapter; @@ -99,15 +99,14 @@ public function setDumpPlatform(PlatformInterface $dumpPlatform = null) * * @param string $filePath * @return File - * @throws \RuntimeException + * @throws Exception\RuntimeException */ public function createOutputFile($filePath) { try { return new File($filePath, 'wb'); } catch (\Exception $exc) { - // TODO exception - throw new \RuntimeException( + throw new Exception\RuntimeException( sprintf('Can\'t open file for writing `%s`', $filePath), $exc->getCode(), $exc @@ -122,15 +121,14 @@ public function createOutputFile($filePath) * * @param string $filePath * @return SqlFile - * @throws \RuntimeException + * @throws Exception\RuntimeException */ public function createInputFile($filePath) { try { return new SqlFile($filePath, 'rb'); } catch (\Exception $exc) { - // TODO exception - throw new \RuntimeException( + throw new Exception\RuntimeException( sprintf('Can\'t open file for reading `%s`', $filePath), $exc->getCode(), $exc diff --git a/src/WebinoDbDump/Db/Dump/Platform/Mysql/Table/Columns.php b/src/WebinoDbDump/Db/Dump/Platform/Mysql/Table/Columns.php index e1945f2..e48be44 100644 --- a/src/WebinoDbDump/Db/Dump/Platform/Mysql/Table/Columns.php +++ b/src/WebinoDbDump/Db/Dump/Platform/Mysql/Table/Columns.php @@ -3,7 +3,8 @@ * Webino (http://webino.sk) * * @link https://github.com/webino/WebinoDbDump/ for the canonical source repository - * @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk) + * @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk) + * @author Peter Bačinský * @license The BSD 3-Clause License */ @@ -15,8 +16,6 @@ /** * Mysql database dump utility platform columns - * - * @author Peter Bačinský */ class Columns extends AbstractColumns implements ColumnsInterface { diff --git a/src/WebinoDbDump/Db/Dump/Table/AbstractTable.php b/src/WebinoDbDump/Db/Dump/Table/AbstractTable.php index ba06f5a..ed1c5e6 100644 --- a/src/WebinoDbDump/Db/Dump/Table/AbstractTable.php +++ b/src/WebinoDbDump/Db/Dump/Table/AbstractTable.php @@ -3,7 +3,8 @@ * Webino (http://webino.sk) * * @link https://github.com/webino/WebinoDbDump/ for the canonical source repository - * @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk) + * @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk) + * @author Peter Bačinský * @license The BSD 3-Clause License */ @@ -12,11 +13,10 @@ use SplFileObject as File; use WebinoDbDump\Db\Dump\Dump; use WebinoDbDump\Db\Dump\Adapter; +use WebinoDbDump\Exception; /** * Base class for a dump utility platform table - * - * @author Peter Bačinský */ abstract class AbstractTable { @@ -60,7 +60,7 @@ abstract protected function showColumns(); abstract protected function select(); /** - * @return TableColumnsInterface + * @return ColumnsInterface */ abstract protected function createColumns(); @@ -101,12 +101,12 @@ protected function setName($name) /** * @return bool + * @throws Exception\RuntimeException */ protected function isView() { if (null === $this->view) { - // TODO exception - throw new \RuntimeException('Don\'t know if is view'); + throw new Exception\RuntimeException('Don\'t know if is view'); } return $this->view; @@ -188,7 +188,7 @@ private function writeData(File $file) } /** - * @return TableColumnsInterface + * @return ColumnsInterface */ private function createColumnsInternal() { diff --git a/src/WebinoDbDump/Exception/ExceptionInterface.php b/src/WebinoDbDump/Exception/ExceptionInterface.php new file mode 100644 index 0000000..2b88064 --- /dev/null +++ b/src/WebinoDbDump/Exception/ExceptionInterface.php @@ -0,0 +1,18 @@ + + * @license The BSD 3-Clause License + */ + +namespace WebinoDbDump\Exception; + +/** + * Interface ExceptionInterface + */ +interface ExceptionInterface +{ +} diff --git a/src/WebinoDbDump/Exception/InvalidArgumentException.php b/src/WebinoDbDump/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..66ccf88 --- /dev/null +++ b/src/WebinoDbDump/Exception/InvalidArgumentException.php @@ -0,0 +1,18 @@ + + * @license The BSD 3-Clause License + */ + +namespace WebinoDbDump\Exception; + +/** + * Class InvalidArgumentException + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/src/WebinoDbDump/Exception/RuntimeException.php b/src/WebinoDbDump/Exception/RuntimeException.php new file mode 100644 index 0000000..d79351d --- /dev/null +++ b/src/WebinoDbDump/Exception/RuntimeException.php @@ -0,0 +1,18 @@ + + * @license The BSD 3-Clause License + */ + +namespace WebinoDbDump\Exception; + +/** + * Class RuntimeException + */ +class RuntimeException extends \RuntimeException implements ExceptionInterface +{ +} diff --git a/src/WebinoDbDump/Exception/SqlQueryException.php b/src/WebinoDbDump/Exception/SqlQueryException.php new file mode 100644 index 0000000..50d8223 --- /dev/null +++ b/src/WebinoDbDump/Exception/SqlQueryException.php @@ -0,0 +1,18 @@ + + * @license The BSD 3-Clause License + */ + +namespace WebinoDbDump\Exception; + +/** + * Class SqlQueryException + */ +class SqlQueryException extends \RuntimeException implements ExceptionInterface +{ +}