chiark / gitweb /
fix spurious comma causing syntax error in query
[ypp-sc-tools.web-live.git] / yarrg / db-idempotent-populate
index 96df020f842de9ab78e0e59035f7ab5122313db3..9d7bab06a426193a15ed073473d6fb85a0bee203 100755 (executable)
@@ -103,12 +103,28 @@ $dbh->commit;
 #---------- commodity list ----------
 
 {
-    my $sth= $dbh->prepare(<<'END')
- INSERT OR IGNORE INTO commods (commodname) VALUES (?);
+    my $insert= $dbh->prepare(<<'END')
+ INSERT OR IGNORE INTO commods
+     (unitmass,
+      unitvolume,
+      commodname)
+     VALUES (?,?,?);
+END
+    ;
+    my $update= $dbh->prepare(<<'END')
+ UPDATE commods
+     SET unitmass = ?,
+         unitvolume = ?
+     WHERE commodname = ?
 END
     ;
     foreach my $commod (sort keys %commods) {
-       $sth->execute($commod);
+       my $c= $commods{$commod};
+        die "no mass for $commod" unless defined $c->{Mass};
+        die "no colume for $commod" unless defined $c->{Volume};
+       my @qa= ($c->{Mass}, $c->{Volume}, $commod);
+       $insert->execute(@qa);
+       $update->execute(@qa);
     }
     $dbh->commit;
 }