*/
public function getColumns($tableName) {
$columns = [];
- $regex = new Regex('([a-z]+)\((.+)\)( unsigned)?', Regex::CASE_INSENSITIVE);
+ $regex = new Regex('([a-z]+)\((.+)\)', Regex::CASE_INSENSITIVE);
$sql = "SHOW COLUMNS FROM `".$tableName."`";
$statement = $this->dbObj->prepareStatement($sql);
$length = '';
$decimals = '';
$enumValues = '';
- $unsigned = false;
if (!empty($typeMatches)) {
$type = $typeMatches[1];
}
break;
}
-
- if (isset($typeMatches[3])) {
- $unsigned = true;
- }
}
$columns[] = ['name' => $row['Field'], 'data' => [
'default' => $row['Default'],
'autoIncrement' => $row['Extra'] == 'auto_increment' ? true : false,
'enumValues' => $enumValues,
- 'decimals' => $decimals,
- 'unsigned' => $unsigned
+ 'decimals' => $decimals
]];
}
// column type
$definition .= " ".$columnData['type'];
- if (!empty($columnData['unsigned'])) {
- $definition .= ' UNSIGNED';
- }
-
// column length and decimals
if (!empty($columnData['length'])) {
$definition .= "(".$columnData['length'].(!empty($columnData['decimals']) ? ",".$columnData['decimals'] : "").")";
$data['length'] = $this->getLength();
}
- if ($this instanceof IUnsignedDatabaseTableColumn) {
- $data['unsigned'] = $this->isUnsigned();
- }
-
return $data;
}
$column->length($data['length'] ?: null);
}
- if ($column instanceof IUnsignedDatabaseTableColumn) {
- $column->unsigned($data['unsigned'] ?? false);
- }
-
return $column;
}
}
* @package WoltLabSuite\Core\System\Database\Table\Column
* @since 5.2
*/
-abstract class AbstractDecimalDatabaseTableColumn extends AbstractDatabaseTableColumn implements IDecimalsDatabaseTableColumn, IUnsignedDatabaseTableColumn {
+abstract class AbstractDecimalDatabaseTableColumn extends AbstractDatabaseTableColumn implements IDecimalsDatabaseTableColumn {
use TDecimalsDatabaseTableColumn;
- use TUnsignedDatabaseTableColumn;
}
* @package WoltLabSuite\Core\System\Database\Table\Column
* @since 5.2
*/
-abstract class AbstractIntDatabaseTableColumn extends AbstractDatabaseTableColumn implements IAutoIncrementDatabaseTableColumn, ILengthDatabaseTableColumn, IUnsignedDatabaseTableColumn {
+abstract class AbstractIntDatabaseTableColumn extends AbstractDatabaseTableColumn implements IAutoIncrementDatabaseTableColumn, ILengthDatabaseTableColumn {
use TAutoIncrementDatabaseTableColumn;
use TLengthDatabaseTableColumn;
- use TUnsignedDatabaseTableColumn;
/**
* @inheritDoc
public function getMaximumLength() {
return 20;
}
-
- /**
- * @inheritDoc
- */
- public function getMaximumUnsignedLength() {
- return 19;
- }
}
+++ /dev/null
-<?php
-namespace wcf\system\database\table\column;
-
-/**
- * Every database table column whose values can be unsigned must implement this interface.
- *
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Database\Table\Column
- * @since 5.2
- */
-interface IUnsignedDatabaseTableColumn extends IDatabaseTableColumn {
- /**
- * Returns `true` if the values of the database table column are unsigned.
- *
- * @return bool
- */
- public function isUnsigned();
-
- /**
- * Sets if the values of the database table column are unsigned and returns this column.
- *
- * @param bool $unsigned
- * @return $this
- */
- public function unsigned($unsigned = true);
-}
public function getMaximumLength() {
return 8;
}
-
- /**
- * @inheritDoc
- */
- public function getMaximumUnsignedLength() {
- return 7;
- }
}
* @return null|int
*/
public function getMaximumLength() {
- if ($this instanceof IUnsignedDatabaseTableColumn && $this->getMaximumUnsignedLength() !== null) {
- return $this->getMaximumUnsignedLength();
- }
-
- return null;
- }
-
- /**
- * Returns the maximum length value supported by the values of the column are unsigned values
- * or `null` if there is no such maximum.
- *
- * @return null|int
- */
- public function getMaximumUnsignedLength() {
return null;
}
+++ /dev/null
-<?php
-namespace wcf\system\database\table\column;
-
-/**
- * Provides default implementation of the methods of `IUnsignedDatabaseTableColumn`.
- *
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Database\Table\Column
- * @since 5.2
- */
-trait TUnsignedDatabaseTableColumn {
- /**
- * `true` if the values of the database table column are unsigned
- * @var bool
- */
- protected $unsigned = false;
-
- /**
- * Returns `true` if the values of the database table column are unsigned.
- *
- * @return bool
- */
- public function isUnsigned() {
- return $this->unsigned;
- }
-
- /**
- * Sets if the values of the database table column are unsigned and returns this column.
- *
- * @param bool $unsigned
- * @return $this
- */
- public function unsigned($unsigned = true) {
- $this->unsigned = $unsigned;
-
- return $this;
- }
-}