chiark / gitweb /
Merge branch 'ijackson'
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Thu, 20 Aug 2009 18:26:27 +0000 (19:26 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Thu, 20 Aug 2009 18:26:27 +0000 (19:26 +0100)
yarrg/commod-email-processor
yarrg/devel-notes [new file with mode: 0644]

index b395aa8d851fc1ede7bc385968b20b65d8758eca..1cff462cda1c67d451ee8064b9ac952e8e096cae 100755 (executable)
@@ -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 (file)
index 0000000..27335dd
--- /dev/null
@@ -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>