App-RPi-EnvUI
view release on metacpan or search on metacpan
lib/App/RPi/EnvUI/DB.pm view on Meta::CPAN
package App::RPi::EnvUI::DB;
BEGIN {
if (! exists $INC{'DateTime.pm'}){
require DateTime;
DateTime->import;
}
if (! exists $INC{'DBI.pm'}){
require DBI;
DBI->import;
}
if (! exists $INC{'RPi/Const.pm'}){
require RPi::Const;
RPi::Const->import(qw(:all));
}
}
our $VERSION = '0.30';
sub new {
my ($class, %args) = @_;
my $self = bless {%args}, $class;
my $db_file = defined $self->{testing}
? 't/envui.db'
: 'db/envui.db';
$db_file = $self->{db_file} if defined $self->{db_file};
warn "DB in test mode\n" if $self->{testing};
$self->{db} = DBI->connect(
"dbi:SQLite:dbname=$db_file",
"",
"",
{
#sqlite_use_immediate_transaction => 1,
RaiseError => $self->{db_err},
AutoCommit => 1
}
) or die $DBI::errstr;
# commonly used statement handles
$self->{graph_sth} = $self->db->prepare(
"select * from (
select * from stats order by id DESC limit 5760
) sub
order by id asc;"
);
return $self;
}
sub user {
my ($self, $user) = @_;
my $sth = $self->db->prepare(
"SELECT * FROM auth WHERE user=?;"
);
$sth->execute($user);
my $res = $sth->fetchrow_hashref;
return ref $res ne 'HASH'
( run in 1.153 second using v1.01-cache-2.11-cpan-5837b0d9d2c )