Moodle

SUBSTR function in accesslib.php fails on MS SQL

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.9.1, 1.9.2
  • Fix Version/s: 1.9.3
  • Component/s: Course
  • Labels:
    None
  • Environment:
    Microsoft SQL
  • Database:
    Microsoft SQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

lib/accesslib.php makes a call to SQL function SUBSTR in the statement:
$sql = "UPDATE {$CFG->prefix}context
SET path = ".sql_concat("'$newpath'", 'SUBSTR(path, '.$len.' +1)')."
$setdepth
WHERE path LIKE '{$frompath}/%'";
execute_sql($sql,false);

but SUBSTR is not legitimate in MSSQL, SUBSTRING must be used, which is fine with MySQL except there may be a difference in the length parameter.

Problem discussed at:
http://moodle.org/mod/forum/discuss.php?d=106337

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

Fixed under 19_STABLE and HEAD.

Here it's the 19_STABLE change: http://cvs.moodle.org/moodle/lib/accesslib.php?r1=1.421.2.77&r2=1.421.2.78

Now it's using the cross-db sql_substr() function and the 3rd parameter is added to MSSQL DBs.

Show
Eloy Lafuente (stronk7) added a comment - Fixed under 19_STABLE and HEAD. Here it's the 19_STABLE change: http://cvs.moodle.org/moodle/lib/accesslib.php?r1=1.421.2.77&r2=1.421.2.78 Now it's using the cross-db sql_substr() function and the 3rd parameter is added to MSSQL DBs.
Hide
Eloy Lafuente (stronk7) added a comment -

Resolving as fixed. Thanks for report!

Show
Eloy Lafuente (stronk7) added a comment - Resolving as fixed. Thanks for report!
Hide
John White added a comment -

Thanks Eloy.

I'm amazed that at least some versions of MSSQL require a 3rd parameter, even though the documentation suggests its optional!
I suspect that Ross Stanbridge setting this to 0 was equivalent to saying 'ignore this parameter' - however bonkers!

Cheers,

John

Show
John White added a comment - Thanks Eloy. I'm amazed that at least some versions of MSSQL require a 3rd parameter, even though the documentation suggests its optional! I suspect that Ross Stanbridge setting this to 0 was equivalent to saying 'ignore this parameter' - however bonkers! Cheers, John

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: