remove db prefix

This commit is contained in:
Dennis Eichhorn 2020-03-12 18:11:43 +01:00
parent 3439fd57ff
commit 3b24e6c3d7
3 changed files with 8 additions and 57 deletions

View File

@ -25,15 +25,6 @@ namespace phpOMS\DataStorage;
interface DataStorageConnectionInterface
{
/**
* Get prefix.
*
* @return string
*
* @since 1.0.0
*/
public function getPrefix() : string;
/**
* Connect to datastorage.
*

View File

@ -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
*

View File

@ -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 : '');
}