+ 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();
+ if (!defined $r) {
+ $sth_insert{$cs}->execute($name);
+ $sth_lookup->execute($name) or die;
+ ($r)= $sth_lookup->fetchrow_array();
+ die unless defined $r;
+ }
+ $cache_cs{$cs}{$name}= $r;
+ return $r;
+ };
+ }