. Enclose component updates in a transaction
authorJoey Schulze <joey@infodrom.org>
Fri, 1 Oct 2004 07:43:31 +0000 (07:43 +0000)
committerJoey Schulze <joey@infodrom.org>
Fri, 1 Oct 2004 07:43:31 +0000 (07:43 +0000)
 . Actually query the database for the last oid *sigh*
 . Fixed a typo -> parse error

src/InfoCon/hwdb/update.wml

index e78f849..e4c9b8d 100644 (file)
@@ -52,6 +52,7 @@
       }
       $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
   } elseif ($formtype == "component") {
+      pg_exec($dbh, "BEGIN TRANSACTION") or die ("Could not start transaction.");
       if ($endtime == '') {
          $endtime = 'NULL';
       } else {
@@ -90,6 +91,7 @@
         $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
        if ($compound != 0) {
          $query = sprintf ("SELECT id FROM component WHERE oid = %d", pg_getlastoid ($sth));
+         $sth = pg_exec ($dbh, $query) or die_query("Cannot determine last oid!", $query);
          if (pg_NumRows ($sth) > 0) {
            $row = pg_fetch_array ($sth, 0);
            $id = $row['id'];
        } else {
          $query = sprintf ("INSERT INTO screw (component,compound,starttime) "
                           ."VALUES (%d,%d,%s)", $id, $compound,
-                          $starttime? "'".$starttime."'" ? "now()");
+                          $starttime? "'".$starttime."'" : "now()");
          $sth = pg_exec ($dbh, $query) or die_query("Cannot update component history!", $query);
        }
 
       }
+      pg_exec($dbh, "COMMIT") or die ("Could not finish transaction.");
   } elseif ($formtype == "type") {
       if ($id) {
        $query = sprintf ("UPDATE types SET name='%s' WHERE id = %d",