Moodle

Assign Roles fails to display roles when installed with Microsoft SQL. Cannot use the ntext datatype when DISTINCT r.* is used in a query. Suggest using nvarchar(MAX) instead.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 1.9.3
  • Component/s: Administration
  • Labels:
    None
  • Environment:
    Windows 2003 Standard sp2, php 5.2.6, MySQL 5.0.67 (web server)
    Windows 2003 Standard sp2, Microsoft SQL 2005 (database server)
  • Database:
    Microsoft SQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

Assign Roles fails to display created roles when running with Microsoft SQL 2005.

Problem:

Query in class "accesslib::get_assignable_roles()"

SELECT DISTINCT r.*
FROM {$CFG->prefix}role r,
{$CFG->prefix}role_assignments ra,
{$CFG->prefix}role_allow_assign raa
WHERE ra.userid = $USER->id AND ra.contextid IN ($contexts)
AND raa.roleid = ra.roleid AND r.id = raa.allowassign
ORDER BY r.sortorder ASC

Cannot use keyword DISTINCT on Column Description with datatype as ntext. Returns the error as follows:

"Msg 421, Level 16, State 1, Line 1
The ntext data type cannot be selected as DISTINCT because it is not comparable."

FIX:

Use the datatype nvarchar(MAX). ntext is now considered a depricated datatype in MSSQL

Activity

Hide
Ben Steeples added a comment -

Same thing applied to us on our install. Altering the field to nvarchar(MAX) resolved the issue.

Show
Ben Steeples added a comment - Same thing applied to us on our install. Altering the field to nvarchar(MAX) resolved the issue.
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Ben,

fix committed to 19_STABLE and HEAD.

While the change to nvarchar(MAX) solves the issue under MSSQL, it doesn't under Oracle (obviosuly), so we'll continue needing to "fix" those queries to get cross-db.

Anyway, I agree we should consider migrating to nvarchar(MAX), just have to learn more about it (and potential issues). I wouldn't change DB manually for now. Let's see how it evolves.

Closing this as resolved. Thanks and ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Ben, fix committed to 19_STABLE and HEAD. While the change to nvarchar(MAX) solves the issue under MSSQL, it doesn't under Oracle (obviosuly), so we'll continue needing to "fix" those queries to get cross-db. Anyway, I agree we should consider migrating to nvarchar(MAX), just have to learn more about it (and potential issues). I wouldn't change DB manually for now. Let's see how it evolves. Closing this as resolved. Thanks and ciao
Hide
Tim Hunt added a comment -

I reviewed the change, and it looks logical, and I also tested on my Postgres install to ensure that it had not caused any regressions. I can't test on MSSQL, but I assume Eloy did. I think that is good enough to close this issue.

Show
Tim Hunt added a comment - I reviewed the change, and it looks logical, and I also tested on my Postgres install to ensure that it had not caused any regressions. I can't test on MSSQL, but I assume Eloy did. I think that is good enough to close this issue.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: