From: Ian Jackson Date: Thu, 20 Aug 2009 00:54:29 +0000 (+0100) Subject: Merge branch 'stable-3.x' X-Git-Tag: 3.4~161 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=commitdiff_plain;h=fd6bf359d9051fe0c6d269a44bcc08cc53aa2fea;hp=2b6a88303ee81419e9583c4fc34e71f4e692a2e0;p=ypp-sc-tools.db-live.git Merge branch 'stable-3.x' --- diff --git a/yarrg/commod-email-processor b/yarrg/commod-email-processor index b395aa8..1cff462 100755 --- a/yarrg/commod-email-processor +++ b/yarrg/commod-email-processor @@ -123,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; diff --git a/yarrg/devel-notes b/yarrg/devel-notes new file mode 100644 index 0000000..27335dd --- /dev/null +++ b/yarrg/devel-notes @@ -0,0 +1,15 @@ +To remedy bug fixed in 01c14767c024ac56686dbbfcd88d9f3a0b4b1574, +did this: + +sqlite> begin; +sqlite> insert or ignore into stalls select null, buy.islandid, stalls.stallname from buy, stalls using (stallid); +sqlite> insert or ignore into stalls select null, sell.islandid, stalls.stallname from sell, stalls using (stallid); +sqlite> update buy set stallid = (select stallid from stalls where stalls.islandid == buy.islandid and stalls.stallname == (select stallname from stalls as bad where buy.stallid == bad.stallid)); +sqlite> update sell set stallid = (select stallid from stalls where stalls.islandid == sell.islandid and stalls.stallname == (select stallname from stalls as bad where sell.stallid == bad.stallid)); +sqlite> commit; + +And to check that it worked: + +sqlite> select * from buy offers, stalls using (stallid) where offers.islandid != stalls.islandid group by offers.islandid; +sqlite> select * from sell offers, stalls using (stallid) where offers.islandid != stalls.islandid group by offers.islandid; +sqlite>