Footprintless-Plugin-Database

 view release on metacpan or  search on metacpan

lib/Footprintless/Plugin/Database/SqlShellAdapter.pm  view on Meta::CPAN

        );

        my $quit = 0;
        $sqlsh->install_cmds(
            {   qr/^help|\?$/ => \&_help,
                qr/^reload$/  => sub {
                    my ($self) = @_;
                    my $settings = $self->{settings};
                    if ( $settings->{Interactive} ) {
                        exec( $^X, $0, @args );
                        exit 0;
                    }
                    return 1;
                },
                qr/^(cat|more|less) (.+)/ => sub {
                    my ( $self, $pager, $file ) = @_;
                    return system( $pager, $file ) == 0;
                },
                qr/^(?:exit|quit|bye|\w+\s+off)$/i => sub {
                    my ($sqlsh) = @_;
                    $sqlsh->disconnect();
                    $quit = 1;
                }
            }
        );

        $sqlsh->load_history(HISTORY_FILE) if ( -f HISTORY_FILE );

        local $_;
        my $prompt = "SQL> ";
        while ( defined( $_ = $term->readline($prompt) ) ) {
            eval { $sqlsh->execute_cmd($_); };
            print("Error: $@") if ($@);
            last if ($quit);
        }

        $sqlsh->save_history(HISTORY_FILE);
    }
    else {
        my $script = slurp();
        $sqlsh->execute_cmd($_) foreach _parse_script($script);
    }
}

1;

__END__

=pod

=head1 NAME

Footprintless::Plugin::Database::SqlShellAdapter - An adaptor to SQL::Shell

=head1 VERSION

version 1.06

=head1 SYNOPSIS

    # Standard way of getting an overlay
    use Footprintless::Plugin::Database::SqlShellAdapter qw(sql_shell);
    sql_shell('DBI:CSV:f_dir=/tmp');

=head1 DESCRIPTION

Provides a vendor independent client implementation using L<SQL::Shell>. 

=head1 FUNCTIONS

=head2 sql_shell($connection_string, $username, $password, %options)

Executes the shell.

=head1 AUTHOR

Lucas Theisen <lucastheisen@pastdev.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Lucas Theisen.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=head1 SEE ALSO

Please see those modules/websites for more information related to this module.

=over 4

=item *

L<Footprintless::Plugin::Database|Footprintless::Plugin::Database>

=item *

L<Footprintless|Footprintless>

=item *

L<Footprintless::Plugin::Database|Footprintless::Plugin::Database>

=item *

L<SQL::Shell|SQL::Shell>

=back

=cut



( run in 2.090 seconds using v1.01-cache-2.11-cpan-524268b4103 )