Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/RDBMSRules/MySQL.pm view on Meta::CPAN
{
if (defined $column->length)
{
Alzabo::Exception::RDBMSRules->throw( error => "Max display value is too long. Maximum allowed value is 255." )
if $column->length > 255;
Alzabo::Exception::RDBMSRules->throw( error => "Max display value specified without floating point precision." )
unless defined $column->precision;
Alzabo::Exception::RDBMSRules->throw( error =>
"Floating point precision is too high. The maximum value is " .
"30 or the maximum display size - 2, whichever is smaller." )
if $column->precision > 30 || $column->precision > ($column->length - $column->precision);
}
return;
}
if ( $column->type =~ /\A(?:DECIMAL|NUMERIC)\z/i )
{
Alzabo::Exception::RDBMSRules->throw( error => "Max display value is too long. Maximum allowed value is 255." )
if defined $column->length && $column->length > 255;
Alzabo::Exception::RDBMSRules->throw( error =>
"Floating point precision is too high. The maximum value is " .
"30 or the maximum display size - 2, whichever is smaller." )
if defined $column->precision && ($column->precision > 30 || $column->precision > ($column->length - 2) );
return;
}
if ( uc $column->type eq 'TIMESTAMP' )
{
Alzabo::Exception::RDBMSRules->throw( error => "Max display value is too long. Maximum allowed value is 14." )
if defined $column->length && $column->length > 14;
Alzabo::Exception::RDBMSRules->throw( error => $column->type . " columns cannot have a precision." )
if defined $column->precision;
return;
}
if ( $column->type =~ /\A(?:(?:NATIONAL\s+)?VAR)?(?:CHAR|BINARY)/i )
{
Alzabo::Exception::RDBMSRules->throw( error => "(VAR)CHAR and (VAR)BINARY columns must have a length provided." )
unless defined $column->length && $column->length > 0;
Alzabo::Exception::RDBMSRules->throw( error => "Max display value is too long. Maximum allowed value is 255." )
if $column->length > 255;
Alzabo::Exception::RDBMSRules->throw( error => $column->type . " columns cannot have a precision." )
if defined $column->precision;
return;
}
if ( uc $column->type eq 'YEAR' )
{
Alzabo::Exception::RDBMSRules->throw( error => "Valid values for the length specification are 2 or 4." )
if defined $column->length && ($column->length != 2 && $column->length != 4);
return;
}
Alzabo::Exception::RDBMSRules->throw( error => $column->type . " columns cannot have a length or precision." )
if defined $column->length || defined $column->precision;
}
# placeholder in case we decide to try to do something better later
sub validate_table_attribute { 1 }
sub validate_column_attribute
{
my $self = shift;
my %p = @_;
my $column = $p{column};
my $a = uc $p{attribute};
$a =~ s/\A\s//;
$a =~ s/\s\z//;
if ( $a eq 'UNSIGNED' || $a eq 'ZEROFILL' )
{
Alzabo::Exception::RDBMSRules->throw( error => "$a attribute can only be applied to numeric columns" )
unless $column->is_numeric;
return;
}
if ( $a eq 'AUTO_INCREMENT' )
{
Alzabo::Exception::RDBMSRules->throw( error => "$a attribute can only be applied to integer columns" )
unless $column->is_integer;
return;
}
if ($a eq 'BINARY')
{
Alzabo::Exception::RDBMSRules->throw( error => "$a attribute can only be applied to character columns" )
unless $column->is_character;
return;
}
return if $a =~ /\A(?:REFERENCES|UNIQUE\z)/i;
Alzabo::Exception::RDBMSRules->throw( error => "Unrecognized attribute: $a" );
}
sub validate_primary_key
{
my $self = shift;
my $col = shift;
Alzabo::Exception::RDBMSRules->throw( error => 'Blob columns cannot be part of a primary key' )
if $col->type =~ /\A(?:TINY|MEDIUM|LONG)?(?:BLOB|TEXT)\z/i;
}
sub validate_sequenced_attribute
{
my $self = shift;
my $col = shift;
Alzabo::Exception::RDBMSRules->throw( error => 'Non-integer columns cannot be sequenced' )
unless $col->is_integer;
Alzabo::Exception::RDBMSRules->throw( error => 'Only one sequenced column per table is allowed.' )
if grep { $_ ne $col && $_->sequenced } $col->table->columns;
}
sub validate_index
( run in 1.867 second using v1.01-cache-2.11-cpan-ceb78f64989 )