App-DBBrowser

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

2.062    2019-02-21
        - Update options.
        - Update filter search and replace.

2.061    2019-02-12
        - Get data from file: update file search.
        - Create table: option to drop the table if the insert failed.
        - Code refactoring.

2.060    2019-02-10
        - Use String::Unescape to unescape options for Text::CSV.
        - Bugfix subqueries: replaced '&&' with '||'.

2.059    2019-02-10
        - Added the possibility to edit join conditions.

2.058    2019-02-09
        - Update input filter 'Search Replace'.

2.057    2019-02-07
        - Update file history.

META.json  view on Meta::CPAN

            "Getopt::Long" : "0",
            "JSON::MaybeXS" : "0",
            "List::MoreUtils" : "0.428",
            "List::MoreUtils::XS" : "0.428",
            "Pod::Usage" : "0",
            "SQL::Type::Guess" : "0",
            "Scalar::Util" : "0",
            "Spreadsheet::Read" : "0",
            "Storable" : "0",
            "String::Substitution" : "0",
            "String::Unescape" : "0",
            "Term::Choose" : "1.776",
            "Term::Choose::Util" : "0.145",
            "Term::Form" : "0.561",
            "Term::Form::ReadLine" : "0.561",
            "Term::TablePrint" : "0.174",
            "Text::CSV_XS" : "0",
            "bytes" : "0",
            "open" : "0",
            "perl" : "5.016",
            "strict" : "0",

META.yml  view on Meta::CPAN

  Getopt::Long: '0'
  JSON::MaybeXS: '0'
  List::MoreUtils: '0.428'
  List::MoreUtils::XS: '0.428'
  Pod::Usage: '0'
  SQL::Type::Guess: '0'
  Scalar::Util: '0'
  Spreadsheet::Read: '0'
  Storable: '0'
  String::Substitution: '0'
  String::Unescape: '0'
  Term::Choose: '1.776'
  Term::Choose::Util: '0.145'
  Term::Form: '0.561'
  Term::Form::ReadLine: '0.561'
  Term::TablePrint: '0.174'
  Text::CSV_XS: '0'
  bytes: '0'
  open: '0'
  perl: '5.016'
  strict: '0'

Makefile.PL  view on Meta::CPAN

        'FindBin'                    => 0,
        'Getopt::Long'               => 0,
        'JSON::MaybeXS'              => 0,
        'List::MoreUtils'            => '0.428',
        'List::MoreUtils::XS'        => '0.428',
        'Pod::Usage'                 => 0,
        'Scalar::Util'               => 0,
        'Spreadsheet::Read'          => 0,
        'Storable'                   => 0,
        'String::Substitution'       => 0,
        'String::Unescape'           => 0,
        'SQL::Type::Guess'           => 0,
        'Term::Choose'               => '1.776',
        'Term::Choose::Util'         => '0.145',
        'Term::Form'                 => '0.561',
        'Term::Form::ReadLine'       => '0.561',
        'Term::TablePrint'           => '0.174',
        'Text::CSV_XS'               => 0,
        %prereqs_os_specific,
    },
    dist  => {

bin/db-browser  view on Meta::CPAN


Set a maximum width of the expanded table row output. I<Max width expanded> set to C<0> means no maximum width. See
option L</Expand Table>.

=head3 Pad row edges

Add a space at the beginning and end of each table row.

=head3 Color

Enable support for color and text formatting escape sequences (SGR) by setting it to C<Enable>. Before the output, a
reset (C<\e[0m>) is added at the end of each row.

=head3 Truncate Fractions First

If the terminal width is insufficient and I<Trunc fract first> is enabled, the first step to reduce the column width is
to truncate the fraction part of numbers to 2 decimal places.

=head3 Truncate Column Threshold

Columns with a width below or equal to I<Trunc col threshold> are only trimmed if it is still necessary to reduce the

bin/db-browser  view on Meta::CPAN

=item

Automatically detects the separation character for CSV files.

=back

=back

=head3 CSV Options In a

Set C<sep_char>, C<quote_char>, C<escape_char>, C<eol> and C<comment_str>. If left empty, default values are used. For
details on these options, refer to L<Text::CSV_XS>.

=head3 CSV Options In b

Set C<allow_loose_escapes>, C<allow_loose_quotes>, C<allow_whitespace>, C<blank_is_undef>, C<binary>, C<decode_utf8>,
C<empty_is_undef> and C<skip_empty_rows>. For meanings of these options, refer to L<Text::CSV_XS>.

=head3 Settings 'split'

=over

=item

Record Separator

bin/db-browser  view on Meta::CPAN

If enabled, the file extension C<csv> is automatically added to the file name.

=item Default File Name

If enabled, the table name will be used as the default file name.

=back

=head3 CSV Options Out a

Set C<sep_char>, C<quote_char>, C<escape_char>, C<eol> and C<undef_str>.

If left empty, default values are used except for C<eol>, which is then set to C<$/> (input record separator).

For the meaning of the different options, see L<Text::CSV_XS>.

=head3 CSV Options Out b

Set C<always_quote>, C<binary>, C<escape_null>, C<quote_binary>, C<quote_empty> and C<quote_space>.

For the meaning of the different options, see L<Text::CSV_XS>.

=head3 File Encoding Out

The encoding of the exported CSV file.

=head2 Miscellaneous

=head3 Menu Memory

bin/db-browser  view on Meta::CPAN

=head2 Decoded Strings

C<db-browser> expects decoded strings.

Non-mappable characters can disrupt the output.

=head2 Terminal

Requires a terminal with a monospaced font supporting the printed characters.

The terminal must comprehend ANSI escape sequences. For MSWin32, C<App::DBBrowser> utilizes L<Win32::Console::ANSI> to
emulate an ANSI console for the C<db-browser>.

=head2 Permissions

To browse the database, schema, table lists and table content, the user must possess the necessary database privileges
for fetching the requested data.

C<db-browser> expects an existing home directory with read and write permissions for the user of the C<db-browser>.

=head1 CREDITS

lib/App/DBBrowser/GetContent/Parse.pm  view on Meta::CPAN

App::DBBrowser::GetContent::Parse;

use warnings;
use strict;
use 5.016;

use Encode qw( decode );

use Encode::Locale    qw();
#use Spreadsheet::Read qw( ReadData rows ); # required
#use String::Unescape  qw( unescape );      # required
#use Text::CSV_XS      qw();                # required

use Term::Choose           qw();
use Term::Choose::LineFold qw( line_fold );
use Term::Choose::Screen   qw( clear_screen );
use Term::Choose::Util     qw( get_term_size unicode_sprintf insert_sep );
use Term::Form             qw();

use App::DBBrowser::Opt::Set;

lib/App/DBBrowser/GetContent/Parse.pm  view on Meta::CPAN

    print 'Parsing file ... ' . "\r";
}


sub parse_with_Text_CSV {
    my ( $sf, $sql, $fh ) = @_;
    my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
    my $tc = Term::Choose->new( $sf->{i}{tc_default} );
    $sf->__print_waiting_str;
    seek $fh, 0, 0;
    require String::Unescape;
    my $options = {
        map { $_ => String::Unescape::unescape( $sf->{o}{csv_in}{$_} ) }
        # grep length: keep the default value if the option is set to ''
        grep { length $sf->{o}{csv_in}{$_} }
        keys %{$sf->{o}{csv_in}}
    };
    require Text::CSV_XS;
    my $csv = Text::CSV_XS->new( $options ) or die Text::CSV_XS->error_diag();
    $csv->callbacks( error => sub {
        my ( $code, $str, $pos, $rec, $fld ) = @_;
        if ( $code == 2012 ) {
            # no warnings for end of data.

lib/App/DBBrowser/GetContent/Parse.pm  view on Meta::CPAN

                $old_idx = 0;
                next IRS;
            }
            $old_idx = $idx;
        }
        if ( $menu->[$idx] eq $reparse ) {
            my $opt_set = App::DBBrowser::Opt::Set->new( $sf->{i}, $sf->{o} );
            $sf->{o} = $opt_set->set_options( 'import' );
            return -1;
        }
        require String::Unescape;
        $/ = String::Unescape::unescape( $irs[$idx-@pre] );
        $sf->__print_waiting_str;
        seek $fh, 0, 0;
        my @rows = grep { ! /^\s+\z/ } <$fh>;
        chomp @rows;
        my $fields_set = [ [ 'Col count', ], [ 'Sep width', ], ];

        SETTINGS: while ( 1 ) {
            my $info = $sf->__print_template_info( \@rows, 7 + @$fields_set );
            # Fill_form
            my $form_set = $tf->fill_form(

lib/App/DBBrowser/Opt/Get.pm  view on Meta::CPAN

            record_r_trim => '',
            field_sep     => ',',
            field_l_trim  => '\s+',
            field_r_trim  => '\s+',
        },
        csv_in => {
            auto_diag => 1,  # not an option, always 1

            sep_char    => ',',
            quote_char  => '"',
            escape_char => '"',
            eol         => '',
            comment_str => '',

            allow_loose_escapes => 0,
            allow_loose_quotes  => 0,
            allow_whitespace    => 0,
            blank_is_undef      => 1,
            binary              => 1,
            decode_utf8         => 1,
            empty_is_undef      => 0,
            skip_empty_rows     => 0,
        },
        export => {
            export_dir       => $sf->{i}{home_dir},
            add_extension    => 0,
            default_filename => 0,
            file_encoding    => 'UTF-8',
        },
        csv_out => {
            auto_diag => 1,  # not an option, always 1

            sep_char    => ',',
            quote_char  => '"',
            escape_char => '"',
            eol         => '',
            undef_str   => '',

            always_quote => 0,
            binary       => 1,
            escape_null  => 1,
            quote_binary => 1,
            quote_empty  => 0,
            quote_space  => 1,
        },
    };
    return $defaults if ! $section;
    return $defaults->{$section} if ! $key;
    return $defaults->{$section}{$key};
}

lib/App/DBBrowser/Opt/Set.pm  view on Meta::CPAN

                $sf->__choose_a_number_wrap( $section, $opt, $prompt, $digits, 0 );
            }
            elsif ( $opt eq '_pad_row_edges' ) {
                my $prompt = '"Pad row edges"';
                my $sub_menu = [
                    [ 'pad_row_edges', "- Pad row edges with a space.", [ $no, $yes ] ]
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }
            elsif ( $opt eq '_color' ) {
                my $prompt = '"ANSI color escapes"';
                my $sub_menu = [
                    [ 'color', "- ANSI color escapes", [ $no, $yes ] ]
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }
            elsif ( $opt eq '_binary_filter' ) {
                my $prompt = 'How to print arbitrary binray data';
                my $sub_menu = [
                    [ 'binary_filter', "- Binary filter", [ $no, 'BNRY', 'Hexadecimal' ] ]
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }

lib/App/DBBrowser/Opt/Set.pm  view on Meta::CPAN

                my $prompt = 'How to parse input files';
                my $sub_menu = [
                    [ 'parse_mode_input_file', "- Use", [ 'Text::CSV', 'split', 'Template', 'Spreadsheet::Read' ] ],
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }
            elsif ( $opt eq '_csv_in_char' ) {
                my $items = [
                    { name => 'sep_char',    prompt => "sep_char   " },
                    { name => 'quote_char',  prompt => "quote_char " },
                    { name => 'escape_char', prompt => "escape_char" },
                    { name => 'eol',         prompt => "eol        " },
                    { name => 'comment_str', prompt => "comment_str" },
                ];
                my $prompt = 'Text::CSV_XS read options a';
                $sf->__group_readline( $section, $items, $prompt );
            }
            elsif ( $opt eq '_csv_in_options' ) {
                my $prompt = 'Text::CSV_XS read options b';
                my $sub_menu = [
                    [ 'allow_loose_escapes', "- allow_loose_escapes", [ $no, $yes ] ],
                    [ 'allow_loose_quotes',  "- allow_loose_quotes",  [ $no, $yes ] ],
                    [ 'allow_whitespace',    "- allow_whitespace",    [ $no, $yes ] ],
                    [ 'blank_is_undef',      "- blank_is_undef",      [ $no, $yes ] ],
                    [ 'binary',              "- binary",              [ $no, $yes ] ],
                    [ 'decode_utf8',         "- decode_utf8",         [ $no, $yes ] ],
                    [ 'empty_is_undef',      "- empty_is_undef",      [ $no, $yes ] ],
                    [ 'skip_empty_rows',     "- skip_empty_rows",     [ $no, $yes ] ],
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }

lib/App/DBBrowser/Opt/Set.pm  view on Meta::CPAN

                my $items = [
                    { name => 'file_encoding', prompt => "Encoding CSV file" },
                ];
                my $prompt = 'Data to CSV-files';
                $sf->__group_readline( $section, $items, $prompt );
            }
            elsif ( $opt eq '_csv_out_char' ) {
                my $items = [
                    { name => 'sep_char',    prompt => "sep_char   " },
                    { name => 'quote_char',  prompt => "quote_char " },
                    { name => 'escape_char', prompt => "escape_char" },
                    { name => 'eol',         prompt => "eol        " },
                    { name => 'undef_str',   prompt => "undef_str"   },
                ];
                my $prompt = 'Text::CSV_XS write options a';
                $sf->__group_readline( $section, $items, $prompt );
            }
            elsif ( $opt eq '_csv_out_options' ) {
                my $prompt = 'Text::CSV_XS write options b';
                my $sub_menu = [
                    [ 'always_quote', "- always_quote", [ $no, $yes ] ],
                    [ 'binary',       "- binary",       [ $no, $yes ] ],
                    [ 'escape_null',  "- escape_null",  [ $no, $yes ] ],
                    [ 'quote_binary', "- quote_binary", [ $no, $yes ] ],
                    [ 'quote_empty',  "- quote_empty",  [ $no, $yes ] ],
                    [ 'quote_space',  "- quote_space",  [ $no, $yes ] ],
                ];
                $sf->__settings_menu_wrap( $section, $sub_menu, $prompt );
            }
            ##### misc #####
            elsif ( $opt eq '_menu_memory' ) {
                my $prompt = 'Your choice: ';
                my $sub_menu = [

lib/App/DBBrowser/Table.pm  view on Meta::CPAN

App::DBBrowser::Table;

use warnings;
use strict;
use 5.016;

use Cwd                   qw( realpath );
use Encode                qw( encode decode );
use File::Spec::Functions qw( catfile );

#use String::Unescape  qw( unescape );             # required
#use Text::CSV_XS      qw();                       # required

use Term::Choose         qw();
use Term::Choose::Screen qw( hide_cursor clear_screen );
use Term::Form::ReadLine qw();
use Term::TablePrint     qw();

use App::DBBrowser::Auxil;
use App::DBBrowser::Opt::Set;
use App::DBBrowser::Table::Substatement;

lib/App/DBBrowser/Table.pm  view on Meta::CPAN

    print 'Working ...' . "\r" if $sf->{o}{table}{progress_bar};
    my $all_arrayref = $sf->__selected_statement_result( $sql );
    my $open_mode;
    if ( length $sf->{o}{export}{file_encoding} ) {
        $open_mode = '>:encoding(' . $sf->{o}{export}{file_encoding} . ')';
    }
    else {
        $open_mode = '>';
    }
    open my $fh, $open_mode, $file_fs or die "$file_fs: $!";
    require String::Unescape;
    my $options = {
        map { $_ => String::Unescape::unescape( $sf->{o}{csv_out}{$_} ) }
        grep { length $sf->{o}{csv_out}{$_} } # keep the default value if the option is set to ''
        keys %{$sf->{o}{csv_out}}
    };
    if ( ! length $options->{eol} ) {
        $options->{eol} = $/; # for `eol` use `$/` as the default value
    }
    require Text::CSV_XS;
    my $csv = Text::CSV_XS->new( $options ) or die Text::CSV_XS->error_diag();
    $csv->print( $fh, $_ ) for @$all_arrayref;
    close $fh;



( run in 0.522 second using v1.01-cache-2.11-cpan-c21f80fb71c )