Skip to content

Commit

Permalink
time range
Browse files Browse the repository at this point in the history
  • Loading branch information
mschilli committed Jan 12, 2008
1 parent 4492bd1 commit bd672ca
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -2,4 +2,4 @@
Revision history for Perl extension Cache::Historical

0.01 2008/01/12
* Where it all began.
(ms) Where it all began.
28 changes: 27 additions & 1 deletion Historical.pm
Expand Up @@ -52,12 +52,24 @@ sub new {
return $self;
}

###########################################
sub dbh {
###########################################
my($self) = @_;

if(! $self->{dbh} ) {
$self->{dbh} = DBI->connect($self->{dsn}, "", "");
}

return $self->{dbh};
}

###########################################
sub db_init {
###########################################
my($self) = @_;

my $dbh = DBI->connect($self->{dsn}, "", "");
my $dbh = $self->dbh();

DEBUG "Creating new SQLite db $self->{sqlite_file}";

Expand Down Expand Up @@ -114,6 +126,20 @@ sub get {
return undef;
}

###########################################
sub time_range {
###########################################
my($self, $key) = @_;

my $dbh = $self->dbh();

my($from, $to) = $dbh->selectrow_array(
"SELECT MIN(date), MAX(date) FROM vals WHERE key = " .
$dbh->quote( $key ));

return($from, $to);
}

1;

__END__
Expand Down
8 changes: 7 additions & 1 deletion Makefile.PL
Expand Up @@ -6,7 +6,13 @@ use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'Cache::Historical',
'VERSION_FROM' => 'Historical.pm', # finds $VERSION
'PREREQ_PM' => {}, # e.g., Module::Name => 1.1
'PREREQ_PM' => {
DBD::SQLite => 1.13,
DBI => 0,
Rose::DB => 0.735,
Rose::DB::Object::Loader => 0.764,
Log::Log4perl => 1,
}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'Historical.pm',
AUTHOR => 'Mike Schilli <cpan@perlmeister.com>') : ()),
Expand Down
4 changes: 4 additions & 0 deletions t/001Basic.t
Expand Up @@ -27,3 +27,7 @@ is( $c->get( $fmt->parse_datetime("2008-01-03"), "msft"), 35.37,
"get value" );
is( $c->get( $fmt->parse_datetime("2008-01-05"), "msft"), undef,
"get undef value" );

my($from, $to) = $c->time_range( "msft" );
is($from, "2008-01-02 00:00:00", "time range from");
is($to, "2008-01-07 00:00:00", "time range to");

0 comments on commit bd672ca

Please sign in to comment.