public function getNativeDatatype($type, $length=null, $cast=false)
    {
        switch ($type) {
            case Column::TYPE_INTEGER:
                if ($length === null) {
                    $length = Column::DEFAULT_LENGTH_INTEGER;
                }
                switch ($length) {
                    case 16:
                        return 'SMALLINT';
                    case 32:
                        return 'INTEGER';
                    case 64:
                        return 'BIGINT';
                    default:
                        throw new \DomainException("Invalid length for type $type: $length");
                }
            case Column::TYPE_VARCHAR:
                if (!ctype_digit((string)$length) or $length < 1) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "VARCHAR($length)";
            case Column::TYPE_TIMESTAMP:
                return 'TIMESTAMP';
            case Column::TYPE_DATE:
                return 'DATE';
            case Column::TYPE_BOOL:
                return 'BOOLEAN';
            case Column::TYPE_BLOB:
                return 'BLOB';
            case Column::TYPE_DECIMAL:
                if (!preg_match('/^([0-9]+),([0-9]+)$/', $length, $components)) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                $precision = (integer)$components[1];
                $scale = (integer)$components[2];
                if ($precision < $scale) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "NUMERIC($precision,$scale)";
            case Column::TYPE_FLOAT:
                if ($length === null) {
                    $length = Column::DEFAULT_LENGTH_FLOAT;
                } elseif (!ctype_digit((string)$length) or $length < 1) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "FLOAT($length)";
            default:
                throw new \DomainException('Unsupported datatype: ' . $type);
        }
    }
public function getNativeDatatype($type, $length=null, $cast=false)
    {
        switch ($type) {
            case Column::TYPE_INTEGER:
                if ($length === null) {
                    $length = Column::DEFAULT_LENGTH_INTEGER;
                }
                switch ($length) {
                    case 16:
                        return 'SMALLINT';
                    case 32:
                        return 'INTEGER';
                    case 64:
                        return 'BIGINT';
                    default:
                        throw new \DomainException("Invalid length for type $type: $length");
                }
            case Column::TYPE_VARCHAR:
                if (!ctype_digit((string)$length) or $length < 1) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "VARCHAR($length)";
            case Column::TYPE_TIMESTAMP:
                return 'TIMESTAMP';
            case Column::TYPE_DATE:
                return 'DATE';
            case Column::TYPE_BOOL:
                return 'BOOLEAN';
            case Column::TYPE_BLOB:
                return 'BLOB';
            case Column::TYPE_DECIMAL:
                if (!preg_match('/^([0-9]+),([0-9]+)$/', $length, $components)) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                $precision = (integer)$components[1];
                $scale = (integer)$components[2];
                if ($precision < $scale) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "NUMERIC($precision,$scale)";
            case Column::TYPE_FLOAT:
                if ($length === null) {
                    $length = Column::DEFAULT_LENGTH_FLOAT;
                } elseif (!ctype_digit((string)$length) or $length < 1) {
                    throw new \InvalidArgumentException('Invalid length: ' . $length);
                }
                return "FLOAT($length)";
            default:
                throw new \DomainException('Unsupported datatype: ' . $type);
        }
    }
public function getNativeDatatype ( $ type , $ length = null , $ cast = false ) { switch ( $ type ) { case Column :: TYPE_INTEGER : if ( $ length === null ) { $ length = Column :: DEFAULT_LENGTH_INTEGER ; } switch ( $ length ) { case 16 : return 'SMALLINT' ; case 32 : return 'INTEGER' ; case 64 : return 'BIGINT' ; default : throw new \ DomainException ( "Invalid length for type $type: $length" ) ; } case Column :: TYPE_VARCHAR : if ( ! ctype_digit ( ( string ) $ length ) or $ length < 1 ) { throw new \ InvalidArgumentException ( 'Invalid length: ' . $ length ) ; } return "VARCHAR($length)" ; case Column :: TYPE_TIMESTAMP : return 'TIMESTAMP' ; case Column :: TYPE_DATE : return 'DATE' ; case Column :: TYPE_BOOL : return 'BOOLEAN' ; case Column :: TYPE_BLOB : return 'BLOB' ; case Column :: TYPE_DECIMAL : if ( ! preg_match ( '/^([0-9]+),([0-9]+)$/' , $ length , $ components ) ) { throw new \ InvalidArgumentException ( 'Invalid length: ' . $ length ) ; } $ precision = ( integer ) $ components [ 1 ] ; $ scale = ( integer ) $ components [ 2 ] ; if ( $ precision < $ scale ) { throw new \ InvalidArgumentException ( 'Invalid length: ' . $ length ) ; } return "NUMERIC($precision,$scale)" ; case Column :: TYPE_FLOAT : if ( $ length === null ) { $ length = Column :: DEFAULT_LENGTH_FLOAT ; } elseif ( ! ctype_digit ( ( string ) $ length ) or $ length < 1 ) { throw new \ InvalidArgumentException ( 'Invalid length: ' . $ length ) ; } return "FLOAT($length)" ; default : throw new \ DomainException ( 'Unsupported datatype: ' . $ type ) ; } }
Get DBMS-specific datatype for abstract NADA datatype
@param string $type One of \Nada\Column\AbstractColumn's TYPE_* constants
@param mixed $length Optional length modifier (default provided for some datatypes)
@param bool $cast The result is used for a typecast operation. Some DBMS require different specifiers for casts.
@return string SQL fragment representing the datatype
@throws \DomainException if the datatype is not supported for the current DBMS
@throws \InvalidArgumentException if $length is invalid
Get DBMS - specific datatype for abstract NADA datatype