$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;
--- /dev/null
+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>