/**
  * update a record in the database
  *
  * @param string $gedrec
  * @param int $ged_id
  * @param bool $delete
  */
 public static function updateRecord($gedrec, $ged_id, $delete)
 {
     if (preg_match('/^0 @(' . WT_REGEX_XREF . ')@ (' . WT_REGEX_TAG . ')/', $gedrec, $match)) {
         list(, $gid, $type) = $match;
     } else {
         echo "ERROR: Invalid gedcom record.";
         return;
     }
     // TODO deleting unlinked places can be done more efficiently in a single query
     $placeids = Database::prepare("SELECT pl_p_id FROM `##placelinks` WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id))->fetchOneColumn();
     Database::prepare("DELETE FROM `##placelinks` WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id));
     Database::prepare("DELETE FROM `##dates`      WHERE d_gid =? AND d_file =?")->execute(array($gid, $ged_id));
     //-- delete any unlinked places
     foreach ($placeids as $p_id) {
         $num = Database::prepare("SELECT count(pl_p_id) FROM `##placelinks` WHERE pl_p_id=? AND pl_file=?")->execute(array($p_id, $ged_id))->fetchOne();
         if ($num == 0) {
             Database::prepare("DELETE FROM `##places` WHERE p_id=? AND p_file=?")->execute(array($p_id, $ged_id));
         }
     }
     Database::prepare("DELETE FROM `##name` WHERE n_id=? AND n_file=?")->execute(array($gid, $ged_id));
     Database::prepare("DELETE FROM `##link` WHERE l_from=? AND l_file=?")->execute(array($gid, $ged_id));
     switch ($type) {
         case 'INDI':
             Database::prepare("DELETE FROM `##individuals` WHERE i_id=? AND i_file=?")->execute(array($gid, $ged_id));
             break;
         case 'FAM':
             Database::prepare("DELETE FROM `##families` WHERE f_id=? AND f_file=?")->execute(array($gid, $ged_id));
             break;
         case 'SOUR':
             Database::prepare("DELETE FROM `##sources` WHERE s_id=? AND s_file=?")->execute(array($gid, $ged_id));
             break;
         case 'OBJE':
             Database::prepare("DELETE FROM `##media` WHERE m_id=? AND m_file=?")->execute(array($gid, $ged_id));
             break;
         default:
             Database::prepare("DELETE FROM `##other` WHERE o_id=? AND o_file=?")->execute(array($gid, $ged_id));
             break;
     }
     if (!$delete) {
         self::importRecord($gedrec, Tree::FindById($ged_id), true);
     }
 }