Sélectionner une révision Git
-
Alexandre Morignot a rédigé
If the external id is precised, it will be used to dynamically retrieves the URL when printing this content. This is useful for some source that change the content's URL (like soundcloud). Fuck soundcloud.
Alexandre Morignot a rédigéIf the external id is precised, it will be used to dynamically retrieves the URL when printing this content. This is useful for some source that change the content's URL (like soundcloud). Fuck soundcloud.
get.pm 5,15 Kio
package PlayBot::utils::db::get;
use strict;
use warnings;
use feature 'state';
use Moose;
use PlayBot::utils::db;
has '_dbh' => (
is => 'rw',
isa => 'HashRef',
init_arg => undef,
default => sub { state %h; return \%h; }
);
has '_sth' => (
is => 'rw',
isa => 'HashRef',
init_arg => undef,
default => sub { state %h; return \%h; }
);
has '_queries' => (
is => 'rw',
isa => 'HashRef',
init_arg => undef,
default => sub { state %h; return \%h; }
);
sub get {
my ($self, $query) = @_;
my $chan = $query->chan;
my $result;
if (defined $self->_queries->{$chan} and $self->_queries->{$chan} ~~ $query) {
if ($self->_queries->{$chan}->date < time - 3600*6) {
$self->_clean($chan);
$self->_init($query);
$self->_queries->{$chan} = $query;
}
$query = $self->_queries->{$chan};
}
else {
$self->_init($query);
$self->_queries->{$chan} = $query;
}
$result = $self->_get_next($query);
# if id was precised, we (and so the user) know there is no more results
$self->_clean($chan) if ($query->id >= 0);
return $result;
}
sub get_rows {
my ($self, $query) = @_;
my $dbh = PlayBot::utils::db::get_new_session();
my ($request, @args) = $self->_prepare_request($query);
my $sth = $dbh->prepare('select count(*) from ('.$request.') as TGTGTG');
$sth->execute(@args);
my $rows = $sth->fetch->[0];
$sth->finish;