commit a2e031a793be5bf61859c4fd2aeaba72e1f0bab6
parent 1e3967f70ce776275799e9f8e77bce407d5c3802
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Sat, 1 Nov 2014 22:29:08 -0600
price_scraper: convert to prepare, execute style queries
Diffstat:
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/price_scraper.pl b/price_scraper.pl
@@ -38,6 +38,13 @@ printf $log "%-15s [", $part_num;
vprint("$part_num\n");
+my $qry = "insert into prices(date, part_num, vendor, price, duration) " .
+ "values (?, ?, ?, ?, ?)";
+my $prices_sth = $dbh->prepare($qry);
+
+$qry = "update products set last_seen = ? where part_num = ?";
+my $products_sth = $dbh->prepare($qry);
+
my $date = time;
for (sort keys $cfg->{vendors}) {
my $start = time;
@@ -78,11 +85,8 @@ for (sort keys $cfg->{vendors}) {
next if ($args{n});
- $dbh->do("insert into prices(date, part_num, vendor, price, duration)" .
- "values (?, ?, ?, ?, ?)",
- undef, $date, $part_num, $_, $price, time - $start);
- $dbh->do("update products set last_seen = ? where part_num = ?",
- undef, $date, $part_num);
+ $prices_sth->execute($date, $part_num, $_, $price, time - $start);
+ $products_sth->execute($date, $part_num);
vprint("\tdb updated\n");
}