X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fcommod-email-processor;h=1cff462cda1c67d451ee8064b9ac952e8e096cae;hp=de68fbad98250c24cb43199cb1316e7dc4f79a0f;hb=9d30f9dd7130db1f4303240030b941a42f7d4466;hpb=49280bf6611e4a3ec8df5b2430677e253cbbc784 diff --git a/yarrg/commod-email-processor b/yarrg/commod-email-processor index de68fba..1cff462 100755 --- a/yarrg/commod-email-processor +++ b/yarrg/commod-email-processor @@ -25,25 +25,6 @@ # are used without permission. This program is not endorsed or # sponsored by Three Rings. -# Emails are: -# multipart/mixed, containing -# text/plain; name="metadata"; charset="utf-8" -# Content-Disposition: inline; filename="metadata" -# ocean\t canonical mixed case -# island\t canonical mixed case -# timestamp\t time_t (non-leap secs since start of 1970 UTC) -# clientname\t may contain spaces -# clientversion\t may contain spaces -# clientfixes\t space-delimited list -# clientspec\t \t\t -# servername\t may contain spaces -# serverversion\t may contain spaces -# serverfixes\t space-delimited list -# serverspec\t \t\t -# application/octet-stream; name="deduped.tsv.gz" -# Content-Disposition: attachment; filename="deduped.tsv.gz" -# - use strict (qw(vars)); use POSIX; @@ -58,7 +39,7 @@ BEGIN { use Commods; use CommodsDatabase; -setlocale(LC_CTYPE, "en_GB.UTF-8"); +set_ctype_utf8(); my $parser= new MIME::Parser; our $entity; @@ -142,33 +123,38 @@ sub main () { $islandid, $mid, map { $md{$_} } (qw(timestamp clientspec serverspec))); - my (%sth, %sub_cs, %cache_cs, %sth_insert); + my (%sth, %sub_cs, %cache_cs, %sth_insert, %sth_lookup); $sth_insert{'stall'}= $dbh->prepare( "INSERT OR IGNORE INTO stalls (islandid, stallname) VALUES ($islandid, ?) "); - $sth_insert{'commods'}= $dbh->prepare( + $sth_lookup{'stall'}= $dbh->prepare( + "SELECT stallid FROM stalls + WHERE islandid == $islandid AND stallname == ? + "); + $sth_insert{'commod'}= $dbh->prepare( "INSERT OR IGNORE INTO commods (commodname) VALUES (?) "); + $sth_lookup{'commod'}= $dbh->prepare( + "SELECT commodid FROM commods + WHERE commodname == ? + "); foreach my $cs (qw(stall commod)) { - my $sth_lookup= $dbh->prepare( - "SELECT ${cs}id FROM ${cs}s WHERE ${cs}name == ?; - "); $sub_cs{$cs}= sub { my ($name)= @_; my $r= $cache_cs{$cs}{$name}; return $r if defined $r; - $sth_lookup->execute($name) or die; - ($r)= $sth_lookup->fetchrow_array(); + $sth_lookup{$cs}->execute($name) or die; + ($r)= $sth_lookup{$cs}->fetchrow_array(); if (!defined $r) { $sth_insert{$cs}->execute($name); - $sth_lookup->execute($name) or die; - ($r)= $sth_lookup->fetchrow_array(); + $sth_lookup{$cs}->execute($name) or die; + ($r)= $sth_lookup{$cs}->fetchrow_array(); die unless defined $r; } $cache_cs{$cs}{$name}= $r;