App-RPi-EnvUI

 view release on metacpan or  search on metacpan

lib/App/RPi/EnvUI/DB.pm  view on Meta::CPAN

    $self->{insert_env_sth}->execute(undef, $temp, $hum);
}
sub last_id {
    my $self = shift;
    my $id_list = $self->db->selectrow_arrayref(
        "select seq from sqlite_sequence where name='stats';"
    );

    return defined $id_list ? $id_list->[0] : 0;
}
sub update {
    my ($self, $table, $col, $value, $where_col, $where_val) = @_;

    if (! defined $where_col) {
        my $sth = $self->db->prepare("UPDATE $table SET $col=?");
        $sth->execute($value);
    }
    else {
        my $sth = $self->db->prepare(
            "UPDATE $table SET $col=? WHERE $where_col=?"
        );
        $sth->execute($value, $where_val);
    }
}
sub update_bulk {
    my ($self, $table, $col, $where_col, $data) = @_;

    my $sth = $self->db->prepare(
        "UPDATE $table SET $col=? WHERE $where_col=?"
    );

    for (@$data){
        $sth->execute(@$_);
    }
}
sub update_bulk_all {
    my ($self, $table, $col, $data) = @_;

    my $sth = $self->db->prepare(
        "UPDATE $table SET $col=?;"
    );
    $sth->execute(@$data);
}
sub begin {
    $_[0]->{db}->begin_work;
}



( run in 0.304 second using v1.01-cache-2.11-cpan-95122f20152 )