pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit 0909e90534184b241968548e0bdff443b7743d62
parent 30241b0e3584b5b0c65c77c183f30a7cc1ae426f
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Wed,  5 Nov 2014 22:21:19 -0700

gen_svg: use selectrow_array for single row selects

Diffstat:
Mgen_svg.pl | 16++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/gen_svg.pl b/gen_svg.pl @@ -31,19 +31,15 @@ my $point_sth = $dbh->prepare($sql); $sql = "select distinct vendor from prices where part_num = ?"; my $vendor_sth = $dbh->prepare($sql); -$sql = "select min(date), max(date), min(price), max(price) " . - "from prices where part_num = ?"; -my $limits_sth = $dbh->prepare($sql); - my $parts_sth = $dbh->prepare("select part_num, description from products"); $parts_sth->execute(); while (my ($part_num, $description) = $parts_sth->fetchrow_array()) { - $limits_sth->execute($part_num); - my ($x_min, $x_max, $y_min, $y_max) = $limits_sth->fetchrow_array(); - if (!defined $x_min) { - $limits_sth->finish(); - next; - } + + $sql = "select min(date), max(date), min(price), max(price) " . + "from prices where part_num = ?"; + my ($x_min, $x_max, $y_min, $y_max) = + $dbh->selectrow_array($sql, undef, $part_num); + next unless (defined $x_min); my $domain = $x_max - $x_min; my $range = $y_max - $y_min;