MediaWiki  master
TinyIntType.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use Doctrine\DBAL\Platforms\AbstractPlatform;
6 use Doctrine\DBAL\Types\PhpIntegerMappingType;
7 use Doctrine\DBAL\Types\Type;
8 
12 class 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 }
Wikimedia\Rdbms\TinyIntType\TINYINT
const TINYINT
Definition: TinyIntType.php:13
Wikimedia\Rdbms\TinyIntType\getSQLDeclaration
getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
Definition: TinyIntType.php:15
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\TinyIntType\getName
getName()
Definition: TinyIntType.php:36
Wikimedia\Rdbms\TinyIntType\getCommonIntegerTypeDeclarationForMySQL
getCommonIntegerTypeDeclarationForMySQL(array $columnDef)
Definition: TinyIntType.php:27
Wikimedia\Rdbms\TinyIntType
Handling smallest integer data type.
Definition: TinyIntType.php:12