my $view = $result->{'views'}{ $view_name };
my @flds = map { $_->{'alias'} || $_->{'name'} }
@{ $view->{'select'}{'columns'} || [] };
+ my @from = map { $_->{'alias'} || $_->{'name'} }
+ @{ $view->{'from'}{'tables'} || [] };
$schema->add_view(
name => $view_name,
sql => $view->{'sql'},
order => $view->{'order'},
fields => \@flds,
-# from => $view->{'from'}{'tables'},
-# where => $view->{'from'}{'where'},
-# options => $view->{'options'}
+ tables => \@from,
+ options => $view->{'options'}
);
}
our $VERSION = '1.59';
__PACKAGE__->_attributes( qw/
- name sql fields schema order
+ name sql fields schema order tables options
/);
=pod
return wantarray ? @flds : \@flds;
}
+sub tables {
+
+=pod
+
+=head2 tables
+
+Gets and set the tables the SELECT mentions. Accepts a string, list or
+arrayref; returns an array or array reference. Will unique the table
+names and keep them in order by the first occurrence of a field name.
+
+ $view->tables('foo');
+ $view->tables('foo', 'bar');
+ $view->tables( 'foo, bar' );
+ $view->tables( [ 'foo', 'bar' ] );
+ $view->tables( qw[ foo bar ] );
+
+ my @tables = $view->tables;
+
+=cut
+
+ my $self = shift;
+ my $tables = parse_list_arg( @_ );
+
+ if ( @$tables ) {
+ my ( %unique, @unique );
+ for my $t ( @$tables ) {
+ next if $unique{ $t }++;
+ push @unique, $t;
+ }
+
+ $self->{'tables'} = \@unique;
+ }
+
+ my @tbls = @{ $self->{'tables'} || [] };
+
+ return wantarray ? @tbls : \@tbls;
+}
+
+sub options {
+
+=pod
+
+=head2 options
+
+Gets and sets a list of options on the view.
+
+ $view->options('ALGORITHM=UNDEFINED');
+
+ my @options = $view->options;
+
+=cut
+
+ my $self = shift;
+ my $options = parse_list_arg( @_ );
+
+ if ( @$options ) {
+ my ( %unique, @unique );
+ for my $o ( @$options, @{ $self->{'options'} || [] } ) {
+ next if $unique{ $o }++;
+ push @unique, $o;
+ }
+
+ $self->{'options'} = \@unique;
+ }
+
+ my @opts = @{ $self->{'options'} || [] };
+
+ return wantarray ? @opts : \@opts;
+}
+
sub is_valid {
=pod
# charset table option
#
{
- my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003});
+ my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50013});
my $data = parse($tr,
q[
DELIMITER ;;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`cmdomain`@`localhost` SQL SECURITY DEFINER */
+ /*!50014 DEFINER=`BOGUS` */
/*! VIEW `vs_asset` AS
select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
`cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
is( $view1->name, 'vs_asset', 'Found "vs_asset" view' );
is( $view2->name, 'vs_asset2', 'Found "vs_asset2" view' );
is( $view3->name, 'vs_asset3', 'Found "vs_asset3" view' );
- like($view1->sql, qr/ALGORITHM=UNDEFINED/, "Detected algorithm");
like($view1->sql, qr/vs_asset/, "Detected view vs_asset");
# KYC - commenting this out as I don't understand why this string
'First view has correct fields'
);
+ my @options = $view1->options;
+
+ is_deeply(
+ \@options,
+ [
+ 'ALGORITHM=UNDEFINED',
+ 'DEFINER=`cmdomain`@`localhost`',
+ 'SQL SECURITY DEFINER',
+ ],
+ 'Only version 50013 options parsed',
+ );
+
my @procs = $schema->get_procedures;
is( scalar @procs, 2, 'Right number of procedures (2)' );
my $proc1 = shift @procs;