From 3b24e6c3d710bc1495af617f4255babbc7a50c99 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 12 Mar 2020 18:11:43 +0100 Subject: [PATCH] remove db prefix --- .../DataStorageConnectionInterface.php | 9 ---- DataStorage/Database/DatabasePool.php | 2 +- DataStorage/Database/GrammarAbstract.php | 54 +++---------------- 3 files changed, 8 insertions(+), 57 deletions(-) diff --git a/DataStorage/DataStorageConnectionInterface.php b/DataStorage/DataStorageConnectionInterface.php index 370604d7c..c4f02b772 100644 --- a/DataStorage/DataStorageConnectionInterface.php +++ b/DataStorage/DataStorageConnectionInterface.php @@ -25,15 +25,6 @@ namespace phpOMS\DataStorage; interface DataStorageConnectionInterface { - /** - * Get prefix. - * - * @return string - * - * @since 1.0.0 - */ - public function getPrefix() : string; - /** * Connect to datastorage. * diff --git a/DataStorage/Database/DatabasePool.php b/DataStorage/Database/DatabasePool.php index 4f2ec1201..15fff6a3c 100644 --- a/DataStorage/Database/DatabasePool.php +++ b/DataStorage/Database/DatabasePool.php @@ -105,7 +105,7 @@ final class DatabasePool implements DataStoragePoolInterface * Create database. * * @param string $key Database key - * @param array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $config Database config data + * @param array{db:string, database:string}|array{db:string, host:string, port:int, login:string, password:string, database:string} $config Database config data * * @return bool * diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index 5feab3112..59ebe5ae5 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -66,14 +66,6 @@ abstract class GrammarAbstract */ protected string $or = 'OR'; - /** - * Table prefix. - * - * @var string - * @since 1.0.0 - */ - protected string $tablePrefix = ''; - /** * Special keywords. * @@ -165,57 +157,29 @@ abstract class GrammarAbstract return 'Y-m-d H:i:s'; } - /** - * Get table prefix. - * - * @return string - * - * @since 1.0.0 - */ - public function getTablePrefix() : string - { - return $this->tablePrefix; - } - - /** - * Set table prefix. - * - * @param string $prefix Table prefix - * - * @return void - * - * @since 1.0.0 - */ - public function setTablePrefix(string $prefix) : void - { - $this->tablePrefix = $prefix; - } - /** * Expressionize elements. * - * @param array $elements Elements - * @param string $prefix Prefix for table - * @param bool $column Is column? + * @param array $elements Elements + * @param bool $column Is column? * * @return string * * @since 1.0.0 */ - protected function expressionizeTableColumn(array $elements, string $prefix = '', bool $column = true) : string + protected function expressionizeTableColumn(array $elements, bool $column = true) : string { $expression = ''; foreach ($elements as $key => $element) { if (\is_string($element) && $element !== '*') { - $prefix = \stripos($element, '.') !== false || $column ? $prefix : ''; - $expression .= $this->compileSystem($element, $prefix) . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', '; + $expression .= $this->compileSystem($element) . (\is_string($key) ? ' as ' . $key : '') . ', '; } elseif (\is_string($element) && $element === '*') { $expression .= '*, '; } elseif ($element instanceof \Closure) { - $expression .= $element() . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', '; + $expression .= $element() . (\is_string($key) ? ' as ' . $key : '') . ', '; } elseif ($element instanceof BuilderAbstract) { - $expression .= $element->toSql() . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', '; + $expression .= $element->toSql() . (\is_string($key) ? ' as ' . $key : '') . ', '; } else { throw new \InvalidArgumentException(); } @@ -230,20 +194,17 @@ abstract class GrammarAbstract * A system is a table, a sub query or special keyword. * * @param string $system System - * @param string $prefix Prefix for table * * @return string * * @since 1.0.0 */ - protected function compileSystem(string $system, string $prefix = '') : string + protected function compileSystem(string $system) : string { $identifier = $this->systemIdentifier; - // don't prefix special keywords e.g. COUNT(*) foreach ($this->specialKeywords as $keyword) { if (\strrpos($system, $keyword, -\strlen($system)) !== false) { - $prefix = ''; $identifier = ''; break; @@ -256,7 +217,6 @@ abstract class GrammarAbstract foreach ($split as $key => $system) { $fullSystem .= '.' . ($system !== '*' ? $identifier : '') - . ($key === 0 && $system !== '*' ? $prefix : '') . $system . ($system !== '*' ? $identifier : ''); }