Advertisement module error

23 Jul 2010

If you updated the ad module (Drupal) to the latest dev version, you may come across the above error message:

user warning: Unknown column 'sitekey' in 'where clause' query: UPDATE ad_statistics SET count = count + 1 WHERE date = 2010060800 AND aid = 6149 AND action = 'create' AND adgroup = '' AND hostid = '' AND sitekey = '' in .../sites/all/modules/ad/ad.module on line 333.

or something similar to it.

 

There are two quick solutions:

  1. Manualy create the “sitekey” field using phpMyAdmin
    Go to ad_statistics table and create 1 field after hosted (Go)
    Type: varchar(255) and collation: utf8_general_ci
  2. delete the "sitekey" from "Increment action counter" (line 333) - ad.module resulting to:
    /**
    * Increment action counter.
    */
    function ad_statistics_increment($aid, $action, $group = NULL, $hostid = NULL) {
      // Update action statistics.
      db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE date = %d AND aid = %d AND action = '%s' AND adgroup = '%s' AND hostid = '%s'", date('YmdH'), $aid, $action, $group, $hostid);
      // If column doesn't already exist, we need to add it.
      if (!db_affected_rows()) {
        db_query("INSERT INTO {ad_statistics} (aid, adgroup, hostid, date, action, count) VALUES(%d, '%s', '%s', %d, '%s', 1)", $aid, $group, $hostid, date('YmdH'), $action);
        // If another process already added this row our INSERT will fail, if so we
        // still need to increment it so we don't loose an action.
        if (!db_affected_rows()) {
          db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE date = %d AND aid = %d AND action = '%s' AND adgroup = '%s' AND hostid = '%s'", date('YmdH'), $aid, $action, $group, $hostid);
        }
      }
    
      $event = array('aid' => $aid, 'action' => $action, 'hostid' => $hostid, 'sitekey' => $sitekey);
      module_invoke_all('adapi', 'statistics_increment', $event);
    }

If you follow the 2. solution, keep in mind that you have patched a module file and you have to remember that in future updates. I think the best solution is the 1. or to stick with the stable version.

Info