App-DBBrowser
view release on metacpan or search on metacpan
lib/App/DBBrowser/Table/Extensions/ScalarFunctions/GetArguments.pm view on Meta::CPAN
my $tc = Term::Choose->new( $sf->{i}{tc_default} );
$prompt //= 'Column:';
my $info = $ax->get_sql_info( $sql ) . $ext->nested_func_info( $r_data );
my @pre = ( undef, $sf->{i}{menu_addition} );
while ( 1 ) {
# Choose
my $col = $tc->choose(
[ @pre, @$cols ],
{ %{$sf->{i}{lyt_h}}, info => $info, prompt => $prompt }
);
if ( ! defined $col ) {
return;
}
my $chosen_col;
if ( $col eq $sf->{i}{menu_addition} ) {
# recursion
my $complex_col = $ext->column( $sql, $clause, $r_data );
if ( ! defined $complex_col ) {
next;
}
$chosen_col = $complex_col;
}
elsif ( $sql->{aggregate_mode} && $clause =~ /^(?:select|having|order_by)\z/ ) {
my $sa = App::DBBrowser::Table::Substatement::Aggregate->new( $sf->{i}, $sf->{o}, $sf->{d} );
my $prep_aggr = $sa->get_prepared_aggr_func( $sql, $clause, $col, $r_data );
if ( ! length $prep_aggr ) {
next;
}
$chosen_col = $prep_aggr;
}
else {
$chosen_col = $col;
}
push @{$r_data->[-1]}, $chosen_col;
return $chosen_col;
}
}
sub sqlite_modifiers {
my ( $sf, $sql, $r_data ) = @_;
my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
my $tc = Term::Choose->new( $sf->{i}{tc_default} );
my $tr = Term::Form::ReadLine->new( $sf->{i}{tr_default} );
my $ext = App::DBBrowser::Table::Extensions->new( $sf->{i}, $sf->{o}, $sf->{d} );
my $history = [
'n days',
'n hours',
'n minutes',
'n seconds',
'n months',
'n years',
'[+-]YYYY-MM-DD HH:MM:SS.SSS',
'ceiling',
'floor',
'start of month',
'start of year',
'start of day',
'weekday n',
'unixepoch',
'julianday',
'auto',
'localtime',
'utc',
'subsec',
];
my @modifiers;
my ( $ok, $add_modifier ) = ( '-OK-', 'Add modifier' );
my @args_sofar = @{$r_data->[-1]};
while ( 1 ) {
$r_data->[-1] = [ @args_sofar, @modifiers ];
my $info = $ax->get_sql_info( $sql ) . $ext->nested_func_info( $r_data );
# Choose
my $choice = $tc->choose(
[ undef, $ok, $add_modifier ],
{ %{$sf->{i}{lyt_h}}, info => $info }
);
if ( ! defined $choice ) {
if ( @modifiers ) {
pop @modifiers;
next;
}
$r_data->[-1] = [ @args_sofar ];
return;
}
if ( $choice eq $ok ) {
$r_data->[-1] = [ @args_sofar, @modifiers ];
return join ',', @modifiers;
}
else {
my $modifier = $tr->readline(
'Modifier: ',
{ info => $info, history => $history }
);
$ax->print_sql_info( $info );
if ( ! length $modifier ) {
next;
}
push @modifiers, "'$modifier'";
}
}
}
1;
__END__
( run in 2.530 seconds using v1.01-cache-2.11-cpan-64ef6c95b5d )