+ db_setocean($md{'ocean'});
+ my $dbfn= db_filename();
+ (stat $dbfn) or die "stat database $dbfn failed $!\n";
+ db_connect();
+
+ my ($islandid) = $dbh->selectrow_array(
+ "SELECT islands.islandid
+ FROM islands
+ WHERE islandname == ?;
+ ", {}, $md{'island'});
+
+ die "unknown island\n" unless defined $islandid;
+
+ db_doall("DELETE FROM uploads WHERE islandid == $islandid;
+ DELETE FROM buy WHERE islandid == $islandid;
+ DELETE FROM sell WHERE islandid == $islandid;
+ ");
+
+ $dbh->do("INSERT INTO uploads
+ (islandid, message,
+ timestamp, clientspec, serverspec)
+ VALUES (?,?,?,?,?);
+ ", {},
+ $islandid, $mid,
+ map { $md{$_} } (qw(timestamp clientspec serverspec)));
+
+ my %sth_cs;
+ foreach my $cs (qw(commod stall)) {
+ $sth_cs{$cs}= $dbh->prepare(
+ "INSERT OR IGNORE
+ INTO ${cs}s
+ (${cs}id) VALUES (?)
+ ");
+ }
+
+ my %sth_bs;
+ foreach my $bs (qw(buy sell)) {
+ $sth_bs{$bs}= $dbh->prepare(
+ "INSERT INTO $bs
+ (commodid, islandid, stallid, price, qty)
+ VALUES (
+ (SELECT commodid FROM commods WHERE commodname = ?),
+ $islandid,
+ (SELECT stallid FROM stalls WHERE stallname = ?),
+ ?, ?
+ )
+ ");
+ }
+