When trying to masquerade as a user when using a MSSQL or Azure SQL database for Drupal, the following error occurs:

PDOException: SQLSTATE[42S22]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'TRUE'.: SELECT TRUE FROM {masquerade_users} WHERE uid_from = :uid_from AND uid_to = :uid_to; Array ( [:uid_from] => 22 [:uid_to] => 19 ) in masquerade_menu_access() (line 243 of [...]\drupal\sites\all\modules\masquerade\masquerade.module).
The website encountered an unexpected error. Please try again later.

The fix is to change line 230 in masquerade.module from
return db_query("SELECT TRUE FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid))->fetchField();
to
return db_query("SELECT 1 FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid))->fetchField();
or
return db_query("SELECT 'TRUE' FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid))->fetchField();

and line 240 from
$switch_to_account = db_query("SELECT TRUE FROM {masquerade_users} WHERE uid_from = :uid_from AND uid_to = :uid_to", array(
to
$switch_to_account = db_query("SELECT 1 FROM {masquerade_users} WHERE uid_from = :uid_from AND uid_to = :uid_to", array(
or
$switch_to_account = db_query("SELECT 'TRUE' FROM {masquerade_users} WHERE uid_from = :uid_from AND uid_to = :uid_to", array(

Note: I have not tested whether this breaks MySQL or PostgreSQL compatibility!

Comments

andypost’s picture

Status:Active» Closed (duplicate)