How do I check whether a node is flagged when it is being deleted?
That code works, but if the module that implements hook_nodeapi() is executed before Flag; differently, it will be executed after flag_nodeapi(), which removes any reference to the deleted node from the database tables used by Flag.

case 'delete':
  foreach (flag_get_flags('node') as $flag) {
    // If the flag is being tracked by translation set and the node is part
    // of a translation set, don't delete the flagging record.
    // Instead, data will be updated in the 'translation_change' op, below.
    if (!$flag-&gt;i18n || empty($node-&gt;tnid)) {
      db_query("DELETE FROM {flag_content} WHERE fid = %d AND content_id = %d", $flag-&gt;fid, $node-&gt;nid);
      db_query("DELETE FROM {flag_counts} WHERE fid = %d AND content_id = %d", $flag-&gt;fid, $node-&gt;nid);
    }
  }
  break;


If the short name of the module starts with any letter after the f, then that module needs to change its weight to a number lower than 0; it is usually done in the implementation of hook_install(), or hook_update_N().

db_query("UPDATE {system} SET weight = %d WHERE name = 'mymodule' AND type = 'module', -1);