App-DBBrowser

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        - Bugfix in SQLite's 'bit_length': return bits not bytes.
        - Bugfix in HAVING clause with operator 'LIKE col': use group results as arguments.
        - Bugfixes in 'col_function' and print history.
        - Union "All tables": don't include system tables.


2.035    2018-12-20
        - "DBD::MariaDB" database plugin.

2.034    2018-12-19
        - New option "guess data type".
        - Update option "auto increment column".
        - Bugfix in "insert_into" menu.
        - Filename extension: max length from 3 to 4.
        - Select columns: allow to select more than one column at a time.

2.033    2018-12-10
        - "Term::Choose" minimum version: '1.638'.
        - "Term::TablePrint" mininum version: '0.104'.

2.032    2018-12-09

bin/db-browser  view on Meta::CPAN

=item

Auto Increment

Enabling I<Auto Increment> makes the 'auto-increment primary key' option available when creating a table.

=item

Data Type Guessing

When this option is enabled and a table is created, C<SQL::Type::Guess> is used to guess the data types. These data types
are then used as defaults when the user is prompted for data types.

=item

Encode data for type guessing

If enabled, the data passed to C<SQL::Type::Guess> is encoded.

The setting of this option can affect the size of C<max> in C<varchar(max)> if strings contain multibyte characters.

=back

=head3 Add Form Fields

=over

lib/App/DBBrowser/CreateDropAttach/CreateTable.pm  view on Meta::CPAN

    return $column_names;
}


sub __edit_column_types {
    my ( $sf, $sql, $source, $data_types ) = @_;
    my $tf = Term::Form->new( $sf->{i}{tf_default} );
    my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
    my $dbms = $sf->{i}{dbms};
    my $fields;
    if ( ! %$data_types && $sf->{o}{create}{data_type_guessing} ) {
        $ax->print_sql_info( $ax->get_sql_info( $sql ), 'Column data types: guessing ... ' );
        my $header = $sql->{insert_col_names}; #
        my $table  = $sql->{insert_args};
        my $encoding;
        if ( $sf->{o}{create}{encode_for_data_type_guessing} ) { # MSSQL DB2 Oracle
            $encoding = $source->{source_type} eq 'plain' ? 'locale' : $sf->{o}{insert}{file_encoding};
        }
        my @aoh;
        if ( length $encoding ) {
            for my $row ( @$table ) {
                push @aoh, { map { $header->[$_] => Encode::encode( $encoding, $row->[$_] ) } 0 .. $#$header };
            }
        }
        else {
            for my $row ( @$table ) {
                push @aoh, { map { $header->[$_] => $row->[$_] } 0 .. $#$header };
            }
        }
        require SQL::Type::Guess;
        my $g = SQL::Type::Guess->new();
        $g->guess( @aoh );
        my $tmp = $g->column_type;
        $data_types = { map { $_ => uc( $tmp->{$_} ) } keys %$tmp };
    }
    if ( defined $data_types ) {
        $fields = [ map { [ $_, $data_types->{$_} ] } @{$sql->{insert_col_names}} ];
    }
    else {
        $fields = [ map { [ $_, '' ] } @{$sql->{insert_col_names}} ];
    }
    my $read_only = []; ##

lib/App/DBBrowser/Options/Defaults.pm  view on Meta::CPAN

            empty_to_null_plain      => 1,
            empty_to_null_file       => 1,
            data_source_create_table => 2,
            data_source_insert       => 2,
            show_hidden_files        => 0,
            file_filter              => '',
        },
        create => {
            default_ai_column_name         => 'Id',
            option_ai_column_enabled       => 0,
            data_type_guessing             => 1,
            encode_for_data_type_guessing  => 0,
            table_constraint_rows          => 0,
            table_option_rows              => 0,
            view_name_prefix               => '',
        },
        split => {
            record_sep    => '\n',
            record_l_trim => '',
            record_r_trim => '',
            field_sep     => ',',
            field_l_trim  => '\s+',

lib/App/DBBrowser/Options/Defaults.pm  view on Meta::CPAN

        },
    };
    if ( $driver eq 'SQLite' ) {
        $defaults->{connect_attr}{sqlite_see_if_its_a_number} = 1;
        $defaults->{connect_attr}{sqlite_string_mode}         = 5;
        $defaults->{connect_attr}{sqlite_busy_timeout}        = 30000;
    }
    elsif ( $driver eq 'mysql' ) {
        $defaults->{connect_attr}{mysql_enable_utf8}        = 0;
        $defaults->{connect_attr}{mysql_enable_utf8mb4}     = 1;
        $defaults->{connect_attr}{mysql_bind_type_guessing} = 1;
    }
    elsif ( $driver eq 'MariaDB' ) {
        $defaults->{connect_attr}{mariadb_bind_type_guessing} = 1;
    }
    elsif ( $driver eq 'Pg' ) {
        $defaults->{connect_attr}{pg_enable_utf8} = -1;
    }
    elsif ( $driver eq 'Firebird' ) {
        $defaults->{connect_attr}{ib_enable_utf8} = 1;
        $defaults->{connect_attr}{ib_dialect}     = '';
        $defaults->{connect_attr}{ib_role}        = '';
        $defaults->{connect_attr}{ib_charset}     = 'UTF8';
    }

lib/App/DBBrowser/Options/Menus.pm  view on Meta::CPAN

        #];
        push @$sub_menu_set_attributes,
            #[ 'sqlite_string_mode',         "- sqlite_string_mode",    $sqlite_string_mode_values ],
            [ 'sqlite_string_mode',         "- sqlite_string_mode",         [ 0, 1, undef, undef, 4, 5, 6 ] ], # undef not seen by the user
            [ 'sqlite_see_if_its_a_number', "- sqlite_see_if_its_a_number", [ $no, $yes ] ];
    }
    elsif ( $driver eq 'mysql' ) {
        push @$sub_menu_set_attributes,
            [ 'mysql_enable_utf8',        "- mysql_enable_utf8",        [ $no, $yes ] ],
            [ 'mysql_enable_utf8mb4',     "- mysql_enable_utf8mb4",     [ $no, $yes ] ],
            [ 'mysql_bind_type_guessing', "- mysql_bind_type_guessing", [ $no, $yes ] ];
    }
    elsif ( $driver eq 'MariaDB' ) {
        push @$sub_menu_set_attributes,
            [ 'mariadb_bind_type_guessing', "- mariadb_bind_type_guessing", [ $no, $yes ] ];
    }
    elsif ( $driver eq 'Pg' ) {
        push @$sub_menu_set_attributes,
            [ 'pg_enable_utf8', "- pg_enable_utf8", [ $no, $yes ] ];
    }
    elsif ( $driver eq 'Firebird' ) {
        push @$items_read_attributes,
            { name => 'ib_dialect', text => "- ib_dialect" },
            { name => 'ib_role',    text => "- ib_role" },
            { name => 'ib_charset', text => "- ib_charset" };

lib/App/DBBrowser/Options/Menus.pm  view on Meta::CPAN

    return;
}


sub group_create_table {
    my ( $sf, $info, $lo, $section, $sub_group ) = @_;
    if ( $sub_group eq '_enable_ct_opt' ) {
        my $prompt = 'Activate options';
        my $sub_menu = [
            [ 'option_ai_column_enabled',       "- Offer auto increment column",   [ $no, $yes ] ],
            [ 'data_type_guessing',             "- Data type guessing",            [ $no, $yes ] ],
            [ 'encode_for_data_type_guessing',  "- Encode for data type guessing", [ $no, $yes ] ],
        ];
        $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt );
    }
    elsif ( $sub_group eq '_add_ct_fields' ) {
        my $prompt = 'Add fields';
        my $sub_menu = [
            [ 'table_constraint_rows', "- Table constraint fields", [ 0 .. 9    ] ],
            [ 'table_option_rows',     "- Table option fields",     [ 0 .. 9    ] ],
        ];
        $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt );

lib/App/DBBrowser/Table/Extensions/ScalarFunctions/To/EpochTo.pm  view on Meta::CPAN

sub epoch_to {
    my ( $sf, $sql, $col, $func ) = @_;
    my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
    my $tc = Term::Choose->new( $sf->{i}{tc_default} );
    my $stmt = $sf->__select_stmt( $sql, $col, $col );
    my $epochs = $sf->{d}{dbh}->selectcol_arrayref( $stmt, { Columns => [1], MaxRows => 500 });
    my $info = $ax->get_sql_info( $sql );
    my $avail_h = get_term_height() - ( $info =~ tr/\n// + 10 ); # 10 = "\n" + col_name +  '...' + prompt + (4 menu) + empty row + footer
    my $max_examples = 50;
    $max_examples = ( minmax $max_examples, $avail_h, scalar( @$epochs ) )[0];
    my ( $function_stmt, $example_results ) = $sf->__guess_interval( $sql, $func, $col, $epochs, $max_examples, $info );

    while ( 1 ) {
        if ( ! defined $function_stmt ) {
            ( $function_stmt, $example_results ) = $sf->__choose_interval( $sql, $func, $col, $epochs, $max_examples, $info );
            if ( ! defined $function_stmt ) {
                return;
            }
            return $function_stmt;
        }
        my @info_rows = ( $col );

lib/App/DBBrowser/Table/Extensions/ScalarFunctions/To/EpochTo.pm  view on Meta::CPAN

    }
    my $stmt = $sf->__select_stmt( $sql, $function_stmt, $col );
    my $example_results = $sf->{d}{dbh}->selectcol_arrayref(
        $stmt,
        { Columns => [1], MaxRows => $max_examples }
    );
    return $function_stmt, [ map { $_ // 'undef' } @$example_results ];
}


sub __guess_interval {
    my ( $sf, $sql, $func, $col, $epochs, $max_examples ) = @_;
    my ( $function_stmt, $example_results );
    if ( ! eval {
        my %count;

        for my $epoch ( @$epochs ) {
            if ( ! looks_like_number( $epoch ) ) {
                return;
            }
            ++$count{length( $epoch )};



( run in 2.443 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )