There's a bug in query builder

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'avsr.aid' in 'on clause': SELECT COUNT(*) AS expression FROM (SELECT DISTINCT 1 AS expression FROM {avatar_selection} avs INNER JOIN {avatar_selection_roles} avs_2 ON avs.aid = avsr.aid WHERE ( (avs_2.rid IS NULL ) OR (avs_2.rid IN (:db_condition_placeholder_0, :db_condition_placeholder_1)) )) subquery; Array ( [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => 3 ) в функции _avatar_selection_image_list() (строка 499 в файле /home/u4522/domains/yurist.by/sites/yurist.by/modules/avatar_selection/avatar_selection.module).

CommentFileSizeAuthor
#1 1278802-query.patch997 bytesandypost

Comments

andypost’s picture

StatusFileSize
new997 bytes

This been caused by wrong JOIN name

sw3b’s picture

same here and patch does not solve the problem !

andypost’s picture

@sw3b can you show add a message with quiery that broken?

sw3b’s picture

Status: Needs review » Reviewed & tested by the community

ok i re-check and there was another line who i forget to change.... same to be ok ! now i have another error, i will open a new issue to track this one.

sw3b’s picture

Status: Reviewed & tested by the community » Needs work

OK ! I did both of modification and when I go to edit a user now i got this error.

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'avsr.aid' in 'on clause': SELECT DISTINCT avs.avatar AS avatar, avs.name AS name, avs.weight AS weight FROM {avatar_selection} avs INNER JOIN {avatar_selection_roles} avs_2 ON avs.aid = avsr.aid WHERE ( (avs_2.rid IS NULL ) OR (avs_2.rid IN (:db_condition_placeholder_0)) ) ORDER BY weight ASC, name ASC, avatar ASC LIMIT 30 OFFSET 0; Array ( [:db_condition_placeholder_0] => 2 ) in _avatar_selection_image_list() (line 501 of /home/sw3b/www/www/sites/all/modules/avatar_selection/avatar_selection.module).

I think there is something missing in DB ?!? Could be wrong....

sw3b’s picture

Status: Needs work » Needs review

Ok i did some research and this is what if found... there is two more lines two change.

      $user_alias = $query->join('users', 'u', 'u.picture = concat(:dir, "/", avs.avatar)', array(':dir', $dir));
      $query->isNull('u.picture');
-      $avsr_alias = $query->join('avatar_selection_roles', 'avs', 'avs.aid = avsr.aid');
+      $avsr_alias = $query->join('avatar_selection_roles', 'avsr', 'avs.aid = avsr.aid');
      $query->condition(db_or()->isNULL("{$avsr_alias}.rid")->condition("{$avsr_alias}.rid", $user_roles, 'IN'));
    }

    // Not root user - join avatar_selection_roles table.
    elseif ($user->uid != 1) {
      $count_avsr_alias = $count_query->join('avatar_selection_roles', 'avsr', 'avs.aid = avsr.aid');
      $count_query->condition(db_or()->isNULL("{$count_avsr_alias}.rid")->condition("{$count_avsr_alias}.rid", $user_roles, 'IN'));

-      $avsr_alias = $query->join('avatar_selection_roles', 'avs', 'avs.aid = avsr.aid');
+      $avsr_alias = $query->join('avatar_selection_roles', 'avsr', 'avs.aid = avsr.aid');
      $query->condition(db_or()->isNULL("{$avsr_alias}.rid")->condition("{$avsr_alias}.rid", $user_roles, 'IN'));

After that the error is gone !!!

andypost’s picture

@w3b can you roll a new patch? When I faced with this this two lines was enough probably I've checked not all cases

sw3b’s picture

Its in avatar_selection.module at approximatly line 484 and 493. I applied your patch and after the modification of the two lines in my previous post its solve my problem.

Sorry for patch creation, i'm not sure how to to the patch file like you did...

andypost’s picture

Thanx, you could try http://drupal.org/patch/create

stella’s picture

Status: Needs review » Closed (duplicate)

The patch at #1326854: D7 does not display anything (now committed) should fix this and other issues.