I had a similar problem to http://drupal.org/node/113498 with Drupal 5.1 and Akismet 5.x-1.2. When you click on the Akismet moderation queue menu I received the following error:

Unknown table 'n' in on clause query: SELECT COUNT(*) AS cnt FROM comments c LEFT JOIN akismet_spam_marks s ON s.content_id = c.cid AND s.content_type = 'comment' INNER JOIN node_access na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm 'tac_lite') OR (na.gid = 28 AND na.realm = 'tac_lite') OR (na.gid = 0 AND na.realm = 'tac_lite') OR (na.gid = 9 AND na.realm = 'everest_editor'))) AND ( (c.status = 0))

I only noticed the error when I logged in as a non admin user, but one that I want to have limited Akismet moderation rights. There must be some reason why the error only showed up in my case in this scenario, but I haven't had time to work it out.

I believe the problem is caused by a db_rewrite_sql statement in the akismet_callback_queue function which is in the akismet_admin.inc module. The default parameters for primary_field and primary_table in the db_rewrite_sql function are for nodes but this query is looking at the comments table, so we can't use the defaults.

I removed the error by changing line 459 (it's the last line below)

if ($allowed_comments) {
$subitems = array();
foreach ($valid_submodes as $key => $title) {
$sql_cnt = str_replace('%cond', $sql_comments_cond[$key], $sql_comments_cnt);
$count = db_result(db_query(db_rewrite_sql($sql_cnt)));

to

$count = db_result(db_query(db_rewrite_sql($sql_cnt, 'c', 'cid')));

Hope this helps.

Comments

Greg Go’s picture

Thanks!

This worked for me using the 4.7.x-1.1-2 version of akismet. The change is on line 457.

drewish’s picture

marked http://drupal.org/node/113498 as a duplicate of this issue.

drewish’s picture

Status: Needs review » Fixed

I've committed this to HEAD and DRUPAL-5

Anonymous’s picture

Status: Fixed » Closed (fixed)