Commit d9aee9d9 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 301141: [PostgreSQL] New charts throw an error about FROM_UNIXTIME - Patch…

Bug 301141: [PostgreSQL] New charts throw an error about FROM_UNIXTIME - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=justdave
parent 9410caae
...@@ -33,6 +33,8 @@ package Bugzilla::Chart; ...@@ -33,6 +33,8 @@ package Bugzilla::Chart;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Series; use Bugzilla::Series;
use Date::Format;
sub new { sub new {
my $invocant = shift; my $invocant = shift;
my $class = ref($invocant) || $invocant; my $class = ref($invocant) || $invocant;
...@@ -233,14 +235,18 @@ sub readData { ...@@ -233,14 +235,18 @@ sub readData {
$dateto = $self->{'dateto'}; $dateto = $self->{'dateto'};
} }
# Convert UNIX times back to a date format usable for SQL queries.
my $sql_from = time2str('%Y-%m-%d', $datefrom);
my $sql_to = time2str('%Y-%m-%d', $dateto);
# Prepare the query which retrieves the data for each series # Prepare the query which retrieves the data for each series
my $query = "SELECT " . $dbh->sql_to_days('series_date') . " - " . my $query = "SELECT " . $dbh->sql_to_days('series_date') . " - " .
$dbh->sql_to_days("FROM_UNIXTIME($datefrom)") . $dbh->sql_to_days('?') . ", series_value " .
", series_value FROM series_data " . "FROM series_data " .
"WHERE series_id = ? " . "WHERE series_id = ? " .
"AND series_date >= FROM_UNIXTIME($datefrom)"; "AND series_date >= ?";
if ($dateto) { if ($dateto) {
$query .= " AND series_date <= FROM_UNIXTIME($dateto)"; $query .= " AND series_date <= ?";
} }
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
...@@ -256,7 +262,12 @@ sub readData { ...@@ -256,7 +262,12 @@ sub readData {
foreach my $series (@$line) { foreach my $series (@$line) {
# Get the data for this series and add it on # Get the data for this series and add it on
$sth->execute($series->{'series_id'}); if ($dateto) {
$sth->execute($sql_from, $series->{'series_id'}, $sql_from, $sql_to);
}
else {
$sth->execute($sql_from, $series->{'series_id'}, $sql_from);
}
my $points = $sth->fetchall_arrayref(); my $points = $sth->fetchall_arrayref();
foreach my $point (@$points) { foreach my $point (@$points) {
......
...@@ -114,7 +114,7 @@ sub sql_limit { ...@@ -114,7 +114,7 @@ sub sql_limit {
sub sql_to_days { sub sql_to_days {
my ($self, $date) = @_; my ($self, $date) = @_;
return "TO_CHAR($date, 'J')::int"; return "TO_CHAR(${date}::date, 'J')::int";
} }
sub sql_date_format { sub sql_date_format {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment