You are here

function _radioactivity_add_energy_std in Radioactivity 5

Same name and namespace in other branches
  1. 6 radioactivity.inc \_radioactivity_add_energy_std()
1 call to _radioactivity_add_energy_std()
_radioactivity_add_energy_internal in ./radioactivity.inc

File

./radioactivity.inc, line 135

Code

function _radioactivity_add_energy_std($oid, $oclass, $dpid, $amount, $timestamp) {
  db_query("UPDATE {radioactivity} SET energy=energy+%f " . "WHERE id=%d AND class='%s' AND decay_profile=%d", $amount, $oid, $oclass, $dpid);
  if (db_affected_rows() == 0) {

    // No new rows, try update again and insert one if necessary.
    // Note that we do the second update inside lock table to be certain that there wasn't insert
    // after the last update.
    db_lock_table("radioactivity");
    $result = db_query("UPDATE {radioactivity} SET energy=energy+%f " . "WHERE id=%d AND class='%s' AND decay_profile=%d", $amount, $oid, $oclass, $dpid);
    if (db_affected_rows() == 0) {
      db_query("INSERT INTO {radioactivity} (id, class, decay_profile, energy, last_emission_timestamp) " . "VALUES (%d, '%s', %d, %f, %d)", $oid, $oclass, $dpid, $amount, $timestamp);
    }
    db_unlock_tables();
  }
}