"instance: Bad grammar");
}
-# my $parser_version = parse_mysql_version(
-# $translator->parser_args->{mysql_parser_version}, 'mysql'
-# ) || DEFAULT_PARSER_VERSION;
- my $parser_version = 30000;
+ my $translator = $self->translator;
+
+ my $parser_version = $translator->has_parser_args
+ ? $translator->engine_version($translator->parser_args->{mysql_parser_version}, 'mysql') || DEFAULT_PARSER_VERSION
+ : DEFAULT_PARSER_VERSION;
while ($data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es) { }
my $result = $parser->startrule($data);
die "Parse failed" unless defined $result;
- my $translator = $self->translator;
my $schema = $translator->schema;
$schema->name($result->{'database_name'}) if $result->{'database_name'};
$field->comments($fdata->{comments});
$table->add_column($field);
- $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
+ $field->is_primary_key(1) if $fdata->{is_primary_key};
my %extra;
for my $qual ( qw[ binary unsigned zerofill list collate ],
}
-# if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
-# my @cleaned_options;
-# my @ignore_opts = $self->parser_args->{'ignore_opts'}
-# ? split( /,/, $self->parser_args->{'ignore_opts'} )
-# : ();
-# if (@ignore_opts) {
-# my $ignores = { map { $_ => 1 } @ignore_opts };
-# foreach my $option (@options) {
-# # make sure the option isn't in ignore list
-# my ($option_key) = keys %$option;
-# if ( !exists $ignores->{$option_key} ) {
-# push @cleaned_options, $option;
-# }
-# }
-# } else {
-# @cleaned_options = @options;
-# }
-# $table->options( \@cleaned_options ) or die $table->error;
-# }
+ if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
+ my @cleaned_options;
+ my @ignore_opts = $translator->has_parser_args && $translator->parser_args->{'ignore_opts'}
+ ? split( /,/, $translator->parser_args->{'ignore_opts'} )
+ : ();
+ if (@ignore_opts) {
+ my $ignores = { map { $_ => 1 } @ignore_opts };
+ foreach my $option (@options) {
+ # make sure the option isn't in ignore list
+ my ($option_key) = keys %$option;
+ if ( !exists $ignores->{$option_key} ) {
+ push @cleaned_options, $option;
+ }
+ }
+ } else {
+ @cleaned_options = @options;
+ }
+ $table->options( \@cleaned_options ); # or die $table->error;
+ }
+ }
+
+ for my $proc_name ( keys %{ $result->{procedures} } ) {
+ my $procedure = Procedure->new({ name => $proc_name,
+ owner => $result->{procedures}->{$proc_name}->{owner},
+ sql => $result->{procedures}->{$proc_name}->{sql}
+ });
+ $schema->add_procedure($procedure);
+ }
+ for my $view_name ( keys %{ $result->{'views'} } ) {
+ my $view = View->new({
+ name => $view_name,
+ sql => $result->{'views'}->{$view_name}->{sql},
+ });
+ $schema->add_view($view);
+ }
+ for my $table_name (@tables) {
+ my $table = $schema->get_table($table_name);
+ my $tdata = $result->{tables}{ $table_name };
for my $cdata ( @{ $tdata->{constraints} || [] } ) {
my $constraint;
if (uc $cdata->{type} eq 'PRIMARY_KEY') {
$constraint = ForeignKey->new({ name => $cdata->{name} || '',
table => $table,
reference_table => $cdata->{reference_table},
- reference_columns => $cdata->{reference_fields},
+ defined $cdata->{reference_fields} ? (reference_columns => $cdata->{reference_fields}) : (),
on_delete => $cdata->{on_delete} || $cdata->{on_delete_do},
on_update => $cdata->{on_update} || $cdata->{on_update_do} });
$table->get_column($_)->is_foreign_key(1) for @{$cdata->{fields}};
$table->add_constraint($constraint);
}
}
-
- for my $proc_name ( keys %{ $result->{procedures} } ) {
- my $procedure = Procedure->new({ name => $proc_name,
- owner => $result->{procedures}->{$proc_name}->{owner},
- sql => $result->{procedures}->{$proc_name}->{sql}
- });
- $schema->add_procedure($procedure);
- }
-
- for my $view_name ( keys %{ $result->{'views'} } ) {
- my $view = View->new({
- name => $view_name,
- sql => $result->{'views'}->{$view_name}->{sql},
- });
- $schema->add_view($view);
- }
return 1;
}
}