MediaWiki REL1_39
TinyIntType.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use Doctrine\DBAL\Platforms\AbstractPlatform;
6use Doctrine\DBAL\Types\PhpIntegerMappingType;
7use Doctrine\DBAL\Types\Type;
8
12class TinyIntType extends Type implements PhpIntegerMappingType {
13 public const TINYINT = 'mwtinyint';
14
15 public function getSQLDeclaration( array $fieldDeclaration, AbstractPlatform $platform ) {
16 if ( $platform->getName() == 'mysql' ) {
17 if ( !empty( $fieldDeclaration['length'] ) && is_numeric( $fieldDeclaration['length'] ) ) {
18 $length = $fieldDeclaration['length'];
19 return "TINYINT($length)" . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration );
20 }
21 return 'TINYINT' . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration );
22 }
23
24 return $platform->getSmallIntTypeDeclarationSQL( $fieldDeclaration );
25 }
26
27 protected function getCommonIntegerTypeDeclarationForMySQL( array $columnDef ) {
28 $autoinc = '';
29 if ( !empty( $columnDef['autoincrement'] ) ) {
30 $autoinc = ' AUTO_INCREMENT';
31 }
32
33 return !empty( $columnDef['unsigned'] ) ? ' UNSIGNED' . $autoinc : $autoinc;
34 }
35
36 public function getName() {
37 return self::TINYINT;
38 }
39}
Handling smallest integer data type.
getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
getCommonIntegerTypeDeclarationForMySQL(array $columnDef)