mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 22:18:40 +00:00
remove db prefix
This commit is contained in:
parent
3439fd57ff
commit
3b24e6c3d7
|
|
@ -25,15 +25,6 @@ namespace phpOMS\DataStorage;
|
||||||
interface DataStorageConnectionInterface
|
interface DataStorageConnectionInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Get prefix.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getPrefix() : string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to datastorage.
|
* Connect to datastorage.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ final class DatabasePool implements DataStoragePoolInterface
|
||||||
* Create database.
|
* Create database.
|
||||||
*
|
*
|
||||||
* @param string $key Database key
|
* @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
|
* @return bool
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,6 @@ abstract class GrammarAbstract
|
||||||
*/
|
*/
|
||||||
protected string $or = 'OR';
|
protected string $or = 'OR';
|
||||||
|
|
||||||
/**
|
|
||||||
* Table prefix.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected string $tablePrefix = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special keywords.
|
* Special keywords.
|
||||||
*
|
*
|
||||||
|
|
@ -165,57 +157,29 @@ abstract class GrammarAbstract
|
||||||
return 'Y-m-d H:i:s';
|
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.
|
* Expressionize elements.
|
||||||
*
|
*
|
||||||
* @param array $elements Elements
|
* @param array $elements Elements
|
||||||
* @param string $prefix Prefix for table
|
* @param bool $column Is column?
|
||||||
* @param bool $column Is column?
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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 = '';
|
$expression = '';
|
||||||
|
|
||||||
foreach ($elements as $key => $element) {
|
foreach ($elements as $key => $element) {
|
||||||
if (\is_string($element) && $element !== '*') {
|
if (\is_string($element) && $element !== '*') {
|
||||||
$prefix = \stripos($element, '.') !== false || $column ? $prefix : '';
|
$expression .= $this->compileSystem($element) . (\is_string($key) ? ' as ' . $key : '') . ', ';
|
||||||
$expression .= $this->compileSystem($element, $prefix) . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', ';
|
|
||||||
} elseif (\is_string($element) && $element === '*') {
|
} elseif (\is_string($element) && $element === '*') {
|
||||||
$expression .= '*, ';
|
$expression .= '*, ';
|
||||||
} elseif ($element instanceof \Closure) {
|
} elseif ($element instanceof \Closure) {
|
||||||
$expression .= $element() . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', ';
|
$expression .= $element() . (\is_string($key) ? ' as ' . $key : '') . ', ';
|
||||||
} elseif ($element instanceof BuilderAbstract) {
|
} elseif ($element instanceof BuilderAbstract) {
|
||||||
$expression .= $element->toSql() . (\is_string($key) ? ' as ' . $prefix . $key : '') . ', ';
|
$expression .= $element->toSql() . (\is_string($key) ? ' as ' . $key : '') . ', ';
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
}
|
}
|
||||||
|
|
@ -230,20 +194,17 @@ abstract class GrammarAbstract
|
||||||
* A system is a table, a sub query or special keyword.
|
* A system is a table, a sub query or special keyword.
|
||||||
*
|
*
|
||||||
* @param string $system System
|
* @param string $system System
|
||||||
* @param string $prefix Prefix for table
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected function compileSystem(string $system, string $prefix = '') : string
|
protected function compileSystem(string $system) : string
|
||||||
{
|
{
|
||||||
$identifier = $this->systemIdentifier;
|
$identifier = $this->systemIdentifier;
|
||||||
|
|
||||||
// don't prefix special keywords e.g. COUNT(*)
|
|
||||||
foreach ($this->specialKeywords as $keyword) {
|
foreach ($this->specialKeywords as $keyword) {
|
||||||
if (\strrpos($system, $keyword, -\strlen($system)) !== false) {
|
if (\strrpos($system, $keyword, -\strlen($system)) !== false) {
|
||||||
$prefix = '';
|
|
||||||
$identifier = '';
|
$identifier = '';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -256,7 +217,6 @@ abstract class GrammarAbstract
|
||||||
foreach ($split as $key => $system) {
|
foreach ($split as $key => $system) {
|
||||||
$fullSystem .= '.'
|
$fullSystem .= '.'
|
||||||
. ($system !== '*' ? $identifier : '')
|
. ($system !== '*' ? $identifier : '')
|
||||||
. ($key === 0 && $system !== '*' ? $prefix : '')
|
|
||||||
. $system
|
. $system
|
||||||
. ($system !== '*' ? $identifier : '');
|
. ($system !== '*' ? $identifier : '');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user