App-DBBrowser
view release on metacpan or search on metacpan
lib/App/DBBrowser/Table.pm view on Meta::CPAN
);
$ax->print_sql_info( $info );
if ( ! defined $idx || ! defined $menu->[$idx] ) {
for my $key ( keys %{$changed} ) {
if ( $changed->{$key} ) {
$changed = {};
$ax->reset_sql( $sql );
next CUSTOMIZE;
}
}
return;
}
if ( $sf->{o}{G}{menu_memory} ) {
if ( $old_idx == $idx && ! $ENV{TC_RESET_AUTO_UP} ) {
$old_idx = 1;
next CUSTOMIZE;
}
$old_idx = $idx;
}
my $sub_stmt = $menu->[$idx];
if ( $sub_stmt eq $select ) {
my $ret = $sb->select( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $distinct ) {
my $ret = $sb->distinct( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $where ) {
my $ret = $sb->where( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $group_by ) {
my $ret = $sb->group_by( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $having ) {
my $ret = $sb->having( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $order_by ) {
my $ret = $sb->order_by( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $limit ) {
my $ret = $sb->limit( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sub_stmt eq $offset ) {
my $ret = $sb->offset( $sql );
$changed->{$sub_stmt} = $ret;
}
elsif ( $sql->{aggregate_mode} && ! @{$sql->{selected_cols}} ) { ##
$ax->print_error_message( "No columns selected!", $info );
next CUSTOMIZE;
}
elsif ( $sub_stmt eq $hidden ) {
if ( ! eval {
require App::DBBrowser::Table::InsertUpdateDelete;
my $write = App::DBBrowser::Table::InsertUpdateDelete->new( $sf->{i}, $sf->{o}, $sf->{d} );
my $backup_sql = $ax->clone_data( $sql );
$write->table_write_access( $sql );
# reset $sql else 'bu_where_stmt' from a delete/update could remain in $sql
$ax->reset_sql( $sql );
for my $key ( keys %$backup_sql ) {
$sql->{$key} = $backup_sql->{$key};
}
1 }
) {
$ax->print_error_message( $@ );
}
$sf->{d}{stmt_types} = [ 'Select' ];
$old_idx = 1;
}
elsif ( $sub_stmt eq $return_statement ) {
my $bu_cte_history = [ @{$sf->{d}{cte_history}} ];
$sf->{d}{cte_history} = [];
# empty the cte_history else every substatemnt
# would contain the cte clauses.
my $statement = $ax->get_stmt( $sql, 'Select', 'prepare' );
$sf->{d}{cte_history} = $bu_cte_history;
return $statement;
}
elsif ( $sub_stmt eq $export ) {
if ( ! eval {
$sf->__export( $sql );
1 }
) {
$ax->print_error_message( $@ );
next CUSTOMIZE;
}
}
elsif ( $sub_stmt eq $print_table || $sub_stmt eq $hidden_print ) {
local $| = 1;
print hide_cursor(); # safety
print clear_screen();
print 'Computing:' . "\r" if $sf->{o}{table}{progress_bar};
my $all_arrayref;
if ( ! eval {
$all_arrayref = $sf->select_statement_results( $sql );
1 }
) {
$ax->print_error_message( $@ );
next CUSTOMIZE;
}
my $tp = Term::TablePrint->new( $sf->{o}{table} );
if ( ! $sf->{o}{G}{warnings_table_print} ) {
local $SIG{__WARN__} = sub {};
$tp->print_table( $all_arrayref, { footer => $sf->{d}{table_footer} } );
}
else {
$tp->print_table( $all_arrayref, { footer => $sf->{d}{table_footer} } );
}
}
}
}
sub select_statement_results {
my ( $sf, $sql ) = @_;
my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
my $statement = $ax->get_stmt( $sql, 'Select', 'prepare' );
unshift @{$sf->{d}{table_print_history}}, $statement;
if ( $#{$sf->{d}{table_print_history}} > 50 ) {
$#{$sf->{d}{table_print_history}} = 50;
}
( run in 0.670 second using v1.01-cache-2.11-cpan-39bf76dae61 )