Every time I save an Ad node I get the following error:

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.

CommentFileSizeAuthor
#6 821160_ad_sitekey.patch1.32 KBzoo33
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Fspy’s picture

I am getting that same error.

Dubs’s picture

Me too...

Demian’s picture

A. create the "sitekey" field manualy using phpMyAdmin

B. 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);
}

B2. If you follow the B. 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 A. or to stick with the stable version.

hedac’s picture

I created the sitekey field and now it works... What's the sitekey field for?
and which type of field do we have to create? I did a varchar.. but not sure...
it should be created by update.php

jmellon’s picture

figured it out; Thanks for your entry, probably saved me an hour or two

zoo33’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Active » Needs review
FileSize
1.32 KB

The whole sitekey business was introduced in this commit (issue: #743848: ad_owners does not uninstall properly). It seems to have been unintentional, considering the commit message and the issue title.
Anyway, if sitekey is part of some actual feature in this module, then there needs to be an update to the database schema.

The supplied patch updates the hook_schema() implementation and adds an update function for existing users.

zoo33’s picture

BTW, I tested the update function on a site of my own, and that at least seems to work without a problem.

tacoparty’s picture

Would there be any problem with just ignoring the error? The ads I've created still seem to function the way they're supposed to. Interested to know if it's really worth worrying about.

Thanks

vishun’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #6 works. After applying the patch all I had to do was run a site update and it added the column. Thanks zoo33.

anonymous07’s picture

+1 for seeing this issue (when removing an Ad from a Channel, since the Channel display algorithm doesn't appear to be working)

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

and +1 for the patch working.

Thanks zoo33 for the patch.

Majdi’s picture

#6 works for me

eric.chenchao’s picture

subscribe

John Franklin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.