/** * Gets the generic table column. * The $column parameter must contain: * - name * - type * - length * - precision * - scale * - unisgned * - fixed * - not_null * - default * - auto_increment * - comment * @param array $column The column. * @return Column The generic column. */ protected function getGenericColumn(array $column) : Column { $typeToken = '(),'; $databaseType = strtok($column['type'], $typeToken); $length = $precision = strtok($typeToken); $length = $precision = $length !== false ? (int) $length : null; $scale = strtok($typeToken); $scale = $scale !== false ? (int) $scale : null; $default = !empty($column['default']) ? $column['default'] : null; switch ($databaseType) { case 'decimal': case 'double': case 'float': case 'numeric': case 'real': $length = null; break; case 'bigint': case 'int': case 'integer': case 'smallint': case 'char': case 'longtext': case 'mediumint': case 'mediumtext': case 'string': case 'text': case 'tinytext': case 'varchar': $precision = null; $scale = null; break; default: $length = null; $precision = null; $scale = null; break; } return parent::getGenericColumn(['name' => $column['name'], 'type' => $databaseType, 'length' => $length, 'precision' => $precision, 'scale' => $scale, 'unsigned' => $column['unsigned'] ? true : null, 'fixed' => $databaseType === 'char' ? true : null, 'not_null' => $column['not_null'], 'default' => $default, 'auto_increment' => $column['auto_increment'] ? true : null, 'comment' => !empty($column['comment']) ? $column['comment'] : null]); }
/** * Gets the generic table column. * The $column parameter must contain: * - name * - type * - length * - precision * - scale * - unisgned * - fixed * - not_null * - default * - auto_increment * - comment * @param array $column The column. * @return Column The generic column. */ protected function getGenericColumn(array $column) : Column { $databaseType = $column['type']; $length = $precision = $scale = null; if (!in_array($databaseType, ['time', 'timestamp'])) { $typeToken = '(),'; strtok($column['full_type'], $typeToken); $length = $precision = strtok($typeToken); $length = $precision = $length !== false ? (int) $length : null; $scale = strtok($typeToken); $scale = $scale !== false ? (int) $scale : null; } $default = null; if ($column['default'] !== null) { if (preg_match('/^\'(.*)\'::character varying$/', $column['default'], $matches)) { $default = $matches[1]; } elseif (preg_match('/^\'(.*)\'::timestamp without time zone$/', $column['default'], $matches)) { $default = $matches[1]; } elseif (preg_match('/^\'(.*)\'::date$/', $column['default'], $matches)) { $default = $matches[1]; } elseif (preg_match('/^\'(.*)\'::time without time zone/', $column['default'], $matches)) { $default = $matches[1]; } else { $default = $column['default']; } } switch ($databaseType) { case 'decimal': case 'double': case 'double precision': case 'float': case 'float4': case 'float8': case 'money': case 'numeric': case 'real': $length = null; break; case 'char': case 'varchar': $precision = null; $scale = null; break; default: $length = null; $precision = null; $scale = null; break; } return parent::getGenericColumn(['name' => $column['name'], 'type' => $databaseType, 'length' => $length, 'precision' => $precision, 'scale' => $scale, 'unsigned' => null, 'fixed' => $databaseType === 'char' ? true : null, 'not_null' => $column['not_null'], 'default' => $default, 'auto_increment' => null, 'comment' => !empty($column['comment']) ? $column['comment'] : null]); }