Acrux-DBI

 view release on metacpan or  search on metacpan

lib/Acrux/DBI/Res.pm  view on Meta::CPAN

That value of C<AUTO_INCREMENT> column if executed query was C<INSERT> in a table with
C<AUTO_INCREMENT> column

=head2 more_results

    do {
      my $columns = $res->columns;
      my $arrays = $res->arrays;
    } while ($res->more_results);

Handle multiple results

=head2 rows

    my $num = $res->rows;

Number of rows

=head2 state

    my $state = $res->state;

Error state received

=head2 text

    my $text = $res->text;

Fetch all rows from L</"sth"> and turn them into a table with L<Mojo::Util/"tablify">.

=head1 HISTORY

See C<Changes> file

=head1 TO DO

See C<TODO> file

=head1 SEE ALSO

L<Mojo::mysql>, L<Mojo::Pg>, L<Mojo::DB::Connector>, L<CTK::DBI>, L<DBI>

=head1 AUTHOR

Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>

=head1 COPYRIGHT

Copyright (C) 1998-2026 D&D Corporation

=head1 LICENSE

This program is distributed under the terms of the Artistic License Version 2.0

See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details

=cut

use Carp qw/croak/;
use Mojo::Collection;
use Mojo::JSON qw(from_json);
use Mojo::Util qw(tablify);

sub new {
    my $class = shift;
    my $args = scalar(@_) ? scalar(@_) > 1 ? {@_} : {%{$_[0]}} : {};
    my $sth = $args->{sth};
       croak 'Invalid STH' unless ref($sth);
    my $self  = bless {
            sth     => $sth,
            dbi     => undef,
            driver  => '',
            affected_rows => $args->{affected_rows} || 0,
        }, $class;
    $self->dbi($args->{dbi});
    return $self;
}

sub sth {
    my $self = shift;
    if (scalar(@_) >= 1) {
        $self->{sth} = shift;
        return $self;
    }
    return $self->{sth};
}
sub dbi {
    my $self = shift;
    if (scalar(@_) >= 1) {
        my $dbi = $self->{dbi} = shift;
        $self->{driver} = $dbi ? ($dbi->dbh->{Driver}{Name} || '') : '';
        return $self;
    }
    return $self->{dbi};
}
sub state { shift->sth->state }
sub err { shift->sth->err }
sub errstr { shift->sth->errstr }
sub finish { shift->sth->finish }

# Main Accessors
sub array { return shift->sth->fetchrow_arrayref() } # See CTK::DBI::record
sub arrays { return shift->sth->fetchall_arrayref() } # See CTK::DBI::table
sub collection_list { return Mojo::Collection->new(shift->sth->fetchall_arrayref()) }
sub columns { return shift->sth->{NAME} }
sub hash { return shift->sth->fetchrow_hashref() } # See CTK::DBI::recordh
sub hashes { return shift->sth->fetchall_arrayref({}) }
sub collection { return Mojo::Collection->new(@{(shift->sth->fetchall_arrayref({}))}) }
sub rows { shift->sth->rows }
sub text { tablify shift->arrays }
sub affected_rows { shift->{affected_rows} }
sub more_results { shift->sth->more_results }
sub last_insert_id {
    my $self = shift;
    return $self->sth->last_insert_id() if $self->sth->can('last_insert_id');
    my $liid = sprintf('%s_insertid', $self->{driver});
    return $self->sth->{$liid};
}
sub hashed_by { # See CTK::DBI::tableh
    my $self = shift;
    my $key_field = shift; # See keys (http://search.cpan.org/~timb/DBI-1.607/DBI.pm#fetchall_hashref)



( run in 1.622 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )