mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
remove db prefix
This commit is contained in:
parent
b2f17234fa
commit
3439fd57ff
|
|
@ -40,16 +40,6 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
*/
|
||||
protected $con = null;
|
||||
|
||||
/**
|
||||
* Database prefix.
|
||||
*
|
||||
* The database prefix name for unique table names
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* Database data.
|
||||
*
|
||||
|
|
@ -126,18 +116,6 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
return (int) $this->dbdata['port'] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table prefix.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPrefix() : string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object destructor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -47,20 +47,10 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
*/
|
||||
public \PDO $con;
|
||||
|
||||
/**
|
||||
* Database prefix.
|
||||
*
|
||||
* The database prefix name for unique table names
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* Database data.
|
||||
*
|
||||
* @var array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string}
|
||||
* @var array{db:string, database:string}|array{db:string, host:string, port:int, login:string, password:string, database:string}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected array $dbdata;
|
||||
|
|
@ -149,18 +139,6 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
return (int) ($this->dbdata['port'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table prefix.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPrefix() : string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -180,7 +158,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
/**
|
||||
* Connect to database
|
||||
*
|
||||
* @param null|array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param null|array{db:string, database:string}|array{db:string, host:string, port:int, login:string, password:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class ConnectionFactory
|
|||
*
|
||||
* Overwrites current connection if existing
|
||||
*
|
||||
* @param array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param array{db:string, database:string}|array{db:string, host:string, port:int, login:string, password:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @return ConnectionAbstract
|
||||
*
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ final class MysqlConnection extends ConnectionAbstract
|
|||
*
|
||||
* Creates the database object and overwrites all default values.
|
||||
*
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ final class PostgresConnection extends ConnectionAbstract
|
|||
*
|
||||
* Creates the database object and overwrites all default values.
|
||||
*
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ final class SQLiteConnection extends ConnectionAbstract
|
|||
*
|
||||
* Creates the database object and overwrites all default values.
|
||||
*
|
||||
* @param array{db:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param array{db:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -60,7 +60,7 @@ final class SQLiteConnection extends ConnectionAbstract
|
|||
/**
|
||||
* Connect to database
|
||||
*
|
||||
* @param null|array{db:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param null|array{db:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ final class SqlServerConnection extends ConnectionAbstract
|
|||
*
|
||||
* Creates the database object and overwrites all default values.
|
||||
*
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
|
||||
* @param array{db:string, host:string, port:int, login:string, password:string, database:string} $dbdata the basic database information for establishing a connection
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace phpOMS\DataStorage\Database\Query;
|
|||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\Algorithm\Graph\DependencyResolver;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
|
|
@ -28,12 +29,6 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
|||
* @todo Orange-Management/phpOMS#33
|
||||
* Implement missing grammar & builder functions
|
||||
* Missing elements are e.g. sum, merge etc.
|
||||
*
|
||||
* @todo Orange-Management/phpOMS#194
|
||||
* Automatically set prefix during construction
|
||||
* When constructing the QueryBuilder or SchemaBuilder the connection is passed.
|
||||
* The connection holds information about the table prefix, yet I force developers to pass a prefix after the builder initialization.
|
||||
* This should be done automatically!
|
||||
*/
|
||||
class Builder extends BuilderAbstract
|
||||
{
|
||||
|
|
@ -374,9 +369,54 @@ class Builder extends BuilderAbstract
|
|||
*/
|
||||
public function toSql() : string
|
||||
{
|
||||
if (!empty($this->joins)) {
|
||||
$this->resolveJoinDependencies();
|
||||
}
|
||||
|
||||
return $this->grammar->compileQuery($this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resolves join dependencies
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function resolveJoinDependencies() : void
|
||||
{
|
||||
// create dependencies
|
||||
$dependencies = [];
|
||||
foreach ($this->joins as $table => $join) {
|
||||
$dependencies[$table] = [];
|
||||
|
||||
foreach ($this->ons[$table] as $on) {
|
||||
if (\stripos($on['column'], '.')) {
|
||||
$dependencies[$table][] = \explode('.', $on['column'])[0];
|
||||
}
|
||||
|
||||
if (\stripos($on['value'], '.')) {
|
||||
$dependencies[$table][] = \explode('.', $on['value'])[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$resolved = DependencyResolver::resolve($dependencies);
|
||||
|
||||
// cyclomatic dependencies
|
||||
if ($resolved === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$temp = $this->joins;
|
||||
$this->joins = [];
|
||||
foreach ($resolved as $table) {
|
||||
$this->joins[$table] = $temp[$table];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set raw query.
|
||||
*
|
||||
|
|
@ -1085,11 +1125,7 @@ class Builder extends BuilderAbstract
|
|||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
if ($alias === null) {
|
||||
$this->joins[] = ['type' => $type, 'table' => $table];
|
||||
} else {
|
||||
$this->joins[$alias] = ['type' => $type, 'table' => $table];
|
||||
}
|
||||
$this->joins[$alias ?? $table] = ['type' => $type, 'table' => $table, 'alias' => $alias];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -1278,12 +1314,13 @@ class Builder extends BuilderAbstract
|
|||
* @param null|string|array $operator Comparison operator
|
||||
* @param null|string|array $values Values to compare with
|
||||
* @param string|array $boolean Concatonator
|
||||
* @param null|string $table Table this belongs to
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function on($columns, $operator = null, $values = null, $boolean = 'and') : self
|
||||
public function on($columns, $operator = null, $values = null, $boolean = 'and', string $table = null) : self
|
||||
{
|
||||
if ($operator !== null && !\is_array($operator) && !\in_array(\strtolower($operator), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
|
|
@ -1298,15 +1335,14 @@ class Builder extends BuilderAbstract
|
|||
|
||||
$joinCount = \count($this->joins) - 1;
|
||||
$i = 0;
|
||||
$table ??= \array_keys($this->joins)[$joinCount];
|
||||
|
||||
foreach ($columns as $key => $column) {
|
||||
foreach ($columns as $column) {
|
||||
if (isset($operator[$i]) && !\in_array(\strtolower($operator[$i]), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
// ons needs to have the same key as the join for the grammar to work
|
||||
// since alias are possible this is necessary
|
||||
$this->ons[\array_keys($this->joins)[$joinCount]][] = [
|
||||
$this->ons[$table][] = [
|
||||
'column' => $column,
|
||||
'operator' => $operator[$i],
|
||||
'value' => $values[$i],
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class Grammar extends GrammarAbstract
|
|||
*/
|
||||
protected function compileSelects(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix(), false);
|
||||
$expression = $this->expressionizeTableColumn($columns, false);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
@ -156,7 +156,7 @@ class Grammar extends GrammarAbstract
|
|||
*/
|
||||
protected function compileUpdates(Builder $query, array $table) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($table, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($table);
|
||||
|
||||
if ($expression === '') {
|
||||
return '';
|
||||
|
|
@ -192,7 +192,7 @@ class Grammar extends GrammarAbstract
|
|||
*/
|
||||
protected function compileFrom(Builder $query, array $table) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($table, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($table);
|
||||
|
||||
if ($expression === '') {
|
||||
return '';
|
||||
|
|
@ -250,10 +250,7 @@ class Grammar extends GrammarAbstract
|
|||
}
|
||||
|
||||
if (\is_string($element['column'])) {
|
||||
// No prefix if it is ONLY a field
|
||||
$prefix = \stripos($element['column'], '.') === false ? '' : $query->getPrefix();
|
||||
|
||||
$expression .= $this->compileSystem($element['column'], $prefix);
|
||||
$expression .= $this->compileSystem($element['column']);
|
||||
} elseif ($element['column'] instanceof \Closure) {
|
||||
$expression .= $element['column']();
|
||||
} elseif ($element['column'] instanceof Builder) {
|
||||
|
|
@ -263,10 +260,10 @@ class Grammar extends GrammarAbstract
|
|||
}
|
||||
|
||||
if (isset($element['value'])) {
|
||||
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix());
|
||||
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value']);
|
||||
} else {
|
||||
$operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
|
||||
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix());
|
||||
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);
|
||||
}
|
||||
|
||||
return $expression;
|
||||
|
|
@ -317,9 +314,8 @@ class Grammar extends GrammarAbstract
|
|||
/**
|
||||
* Compile value.
|
||||
*
|
||||
* @param Builder $query Query builder
|
||||
* @param mixed $value Value
|
||||
* @param string $prefix Prefix in case value is a table
|
||||
* @param Builder $query Query builder
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return string returns a string representation of the value
|
||||
*
|
||||
|
|
@ -327,7 +323,7 @@ class Grammar extends GrammarAbstract
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function compileValue(Builder $query, $value, string $prefix = '') : string
|
||||
protected function compileValue(Builder $query, $value) : string
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return $query->quote($value);
|
||||
|
|
@ -337,7 +333,7 @@ class Grammar extends GrammarAbstract
|
|||
$values = '';
|
||||
|
||||
foreach ($value as $val) {
|
||||
$values .= $this->compileValue($query, $val, $prefix) . ', ';
|
||||
$values .= $this->compileValue($query, $val) . ', ';
|
||||
}
|
||||
|
||||
return '(' . \rtrim($values, ', ') . ')';
|
||||
|
|
@ -410,18 +406,18 @@ class Grammar extends GrammarAbstract
|
|||
{
|
||||
$expression = '';
|
||||
|
||||
foreach ($joins as $key => $join) {
|
||||
foreach ($joins as $table => $join) {
|
||||
$expression .= $join['type'] . ' ';
|
||||
|
||||
if (\is_string($join['table'])) {
|
||||
$expression .= $this->compileSystem($join['table'], $query->getPrefix()) . (\is_string($key) ? ' as ' . $query->getPrefix() . $key : '');
|
||||
$expression .= $this->compileSystem($join['table']) . (\is_string($join['alias']) ? ' as ' . $join['alias'] : '');
|
||||
} elseif ($join['table'] instanceof \Closure) {
|
||||
$expression .= $join['table']() . (\is_string($key) ? ' as ' . $query->getPrefix() . $key : '');
|
||||
$expression .= $join['table']() . (\is_string($join['alias']) ? ' as ' . $join['alias'] : '');
|
||||
} elseif ($join['table'] instanceof Builder) {
|
||||
$expression .= '(' . \rtrim($join['table']->toSql(), ';') . ')' . (\is_string($key) ? ' as ' . $query->getPrefix() . $key : '');
|
||||
$expression .= '(' . \rtrim($join['table']->toSql(), ';') . ')' . (\is_string($join['alias']) ? ' as ' . $join['alias'] : '');
|
||||
}
|
||||
|
||||
$expression .= $this->compileOn($query, $query->ons[$key]) . ' ';
|
||||
$expression .= $this->compileOn($query, $query->ons[$join['alias'] ?? $table]) . ' ';
|
||||
}
|
||||
|
||||
$expression = \rtrim($expression, ', ');
|
||||
|
|
@ -481,7 +477,7 @@ class Grammar extends GrammarAbstract
|
|||
$element['column'] = $query->from[0] . '.' . $element['column'];
|
||||
}
|
||||
|
||||
$expression .= $this->compileSystem($element['column'], $query->getPrefix());
|
||||
$expression .= $this->compileSystem($element['column']);
|
||||
} elseif ($element['column'] instanceof \Closure) {
|
||||
$expression .= $element['column']();
|
||||
} elseif ($element['column'] instanceof Builder) {
|
||||
|
|
@ -491,7 +487,10 @@ class Grammar extends GrammarAbstract
|
|||
}
|
||||
|
||||
if (isset($element['value'])) {
|
||||
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileSystem($element['value'], $query->getPrefix());
|
||||
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileSystem($element['value']);
|
||||
} else {
|
||||
$operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
|
||||
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);
|
||||
}
|
||||
|
||||
return $expression;
|
||||
|
|
@ -512,7 +511,7 @@ class Grammar extends GrammarAbstract
|
|||
$expression = '';
|
||||
|
||||
foreach ($groups as $group) {
|
||||
$expression .= $this->compileSystem($group, $query->getPrefix()) . ', ';
|
||||
$expression .= $this->compileSystem($group) . ', ';
|
||||
}
|
||||
|
||||
$expression = \rtrim($expression, ', ');
|
||||
|
|
@ -536,7 +535,7 @@ class Grammar extends GrammarAbstract
|
|||
|
||||
foreach ($orders as $key => $order) {
|
||||
foreach ($order as $column) {
|
||||
$expression .= $this->compileSystem($column, $query->getPrefix()) . ', ';
|
||||
$expression .= $this->compileSystem($column) . ', ';
|
||||
}
|
||||
|
||||
$expression = \rtrim($expression, ', ');
|
||||
|
|
@ -588,7 +587,7 @@ class Grammar extends GrammarAbstract
|
|||
*/
|
||||
protected function compileInto(Builder $query, $table) : string
|
||||
{
|
||||
return 'INSERT INTO ' . $this->compileSystem($table, $query->getPrefix());
|
||||
return 'INSERT INTO ' . $this->compileSystem($table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -656,7 +655,7 @@ class Grammar extends GrammarAbstract
|
|||
$vals = '';
|
||||
|
||||
foreach ($values as $column => $value) {
|
||||
$expression = $this->expressionizeTableColumn([$column], $query->getPrefix(), false);
|
||||
$expression = $this->expressionizeTableColumn([$column], false);
|
||||
|
||||
$vals .= $expression . ' = ' . $this->compileValue($query, $value) . ', ';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class MicrosoftGrammar extends Grammar
|
|||
*/
|
||||
protected function compileRandom(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class MysqlGrammar extends Grammar
|
|||
*/
|
||||
protected function compileRandom(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class OracleGrammar extends Grammar
|
|||
*/
|
||||
protected function compileRandom(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class PostgresGrammar extends Grammar
|
|||
*/
|
||||
protected function compileRandom(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class SQLiteGrammar extends Grammar
|
|||
*/
|
||||
protected function compileRandom(Builder $query, array $columns) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -129,7 +129,6 @@ class Builder extends QueryBuilder
|
|||
public static function createFromSchema(array $definition, ConnectionAbstract $connection) : self
|
||||
{
|
||||
$builder = new self($connection);
|
||||
$builder->prefix($connection->prefix);
|
||||
$builder->createTable($definition['name'] ?? '');
|
||||
|
||||
foreach ($definition['fields'] as $name => $def) {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class Grammar extends QueryGrammar
|
|||
*/
|
||||
protected function compileCreateTable(BuilderAbstract $query, string $table) : string
|
||||
{
|
||||
return 'CREATE TABLE ' . $this->expressionizeTableColumn([$table], $query->getPrefix());
|
||||
return 'CREATE TABLE ' . $this->expressionizeTableColumn([$table]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,7 +147,7 @@ class Grammar extends QueryGrammar
|
|||
*/
|
||||
protected function compileDropDatabase(BuilderAbstract $query, string $table) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn([$table], $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn([$table]);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
@ -168,7 +168,7 @@ class Grammar extends QueryGrammar
|
|||
*/
|
||||
protected function compileDropTable(BuilderAbstract $query, string $table) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn([$table], $query->getPrefix());
|
||||
$expression = $this->expressionizeTableColumn([$table]);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class MysqlGrammar extends Grammar
|
|||
$builder->select('*')
|
||||
->from('information_schema.columns')
|
||||
->where('table_schema', '=', $query->getConnection()->getDatabase())
|
||||
->andWhere('table_name', '=', $query->getPrefix() . $table);
|
||||
->andWhere('table_name', '=' . $table);
|
||||
|
||||
return \rtrim($builder->toSql(), ';');
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ class MysqlGrammar extends Grammar
|
|||
$keys = '';
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name], '') . ' ' . $field['type'];
|
||||
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name]) . ' ' . $field['type'];
|
||||
|
||||
if (isset($field['default']) || ($field['default'] === null && isset($field['null']) && $field['null'])) {
|
||||
$fieldQuery .= ' DEFAULT ' . $this->compileValue($query, $field['default']);
|
||||
|
|
@ -113,19 +113,19 @@ class MysqlGrammar extends Grammar
|
|||
$fieldQuery .= ',';
|
||||
|
||||
if (isset($field['primary']) && $field['primary']) {
|
||||
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name], '') . '),';
|
||||
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['unique']) && $field['unique']) {
|
||||
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name], '') . '),';
|
||||
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['foreignTable'], $field['foreignKey'])
|
||||
&& !empty($field['foreignTable']) && !empty($field['foreignKey'])
|
||||
) {
|
||||
$keys .= ' FOREIGN KEY (' . $this->expressionizeTableColumn([$name], '') . ') REFERENCES '
|
||||
. $this->expressionizeTableColumn([$field['foreignTable']], $query->getPrefix())
|
||||
. ' (' . $this->expressionizeTableColumn([$field['foreignKey']], '') . '),';
|
||||
$keys .= ' FOREIGN KEY (' . $this->expressionizeTableColumn([$name]) . ') REFERENCES '
|
||||
. $this->expressionizeTableColumn([$field['foreignTable']])
|
||||
. ' (' . $this->expressionizeTableColumn([$field['foreignKey']]) . '),';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user