/** * Convert the native MySQL Field type to the closest matching equivalent field type supported by the DBMS. * INTEGER and TINYTEXT colums need to be further processed due to MySQL limitations / non-standard features. * * @param string $fieldSQL * @return string */ public function getEquivalentFieldDefinition($fieldSQL) { if (!preg_match('/^([a-z0-9]+)(\\(([^\\)]+)\\))?(.*)/', $fieldSQL, $components)) { return $fieldSQL; } $metaType = $this->dbmsSpecifics->getMetaFieldType($components[1]); $replacementType = $this->dbmsSpecifics->getNativeFieldType($metaType); $replacementLength = $components[2]; $replacementExtra = ''; // MySQL INT types support a display length that has no effect on the // actual range of values that can be stored, normalize to the default // display length returned by DBAL. if (substr($metaType, 0, 1) === 'I') { $replacementLength = $this->dbmsSpecifics->getNativeFieldLength($replacementType, $components[3]); } // MySQL TINYTEXT is equivalent to VARCHAR(255) DEFAULT NULL. MySQL TEXT // columns can not have a default value in contrast to VARCHAR, so the // `default NULL` gets appended to avoid false-positive schema changes. if ($components[1] === 'tinytext') { $replacementLength = '(255)'; if (false !== stripos($components[0], ' NOT NULL')) { $replacementExtra = ' default \'\''; } else { $replacementExtra = ' default NULL'; } } return str_replace($components[1] . $components[2], strtolower($replacementType) . $replacementLength, $components[0]) . $replacementExtra; }
/** * Return MetaType for native MySQL field type * * @param string $t native type as reported as in mysqldump files * @return string Meta type (currently ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8 */ public function MySQLMetaType($t) { GeneralUtility::logDeprecatedFunction(); return $this->dbmsSpecifics->getMetaFieldType($t); }
/** * @test * @param string $nativeType * @param string $expected * @dataProvider determineMetaTypeProvider */ public function determineMetaTypeFromNativeType($nativeType, $expected) { $result = $this->subject->getMetaFieldType($nativeType); $this->assertSame($expected, $result); }