Moodle

MS SQL cannot return Boolean data type in query results, any code using this returns no results when using Sql 2005

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.7.1
  • Fix Version/s: 1.7.3, 1.8.3, 1.9
  • Component/s: Assignment
  • Labels:
    None
  • Environment:
    Windows 2003, Php 5.12, Sql 2005
  • Database:
    Microsoft SQL
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

Description

line 1095 in lib.php in assignments is a good example:
$select = 'SELECT u.id, u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) AS status ';

returns no records for sql 2005
if changed to the following it works:

$select = 'SELECT u.id, u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, ';
if ($CFG->dbtype == 'mssql' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'mssql_n'){ $select .= ' Case When ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) THEN \'True\' Else \'False\' End AS status '; } else { $select .=' ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) AS status '; }

Issue Links

Activity

Hide
Iñaki Arenaza added a comment -

The same problem exists when using Oracle, according to our local Oracle guru. He tells me that you cannot use a boolean expression as a return field.

Saludos. Iñaki.

Show
Iñaki Arenaza added a comment - The same problem exists when using Oracle, according to our local Oracle guru. He tells me that you cannot use a boolean expression as a return field. Saludos. Iñaki.
Hide
Eloy Lafuente (stronk7) added a comment -

True!

That expression isn't cross-db at all!

I'll try to modify the logic a bit to work against all DBs

Show
Eloy Lafuente (stronk7) added a comment - True! That expression isn't cross-db at all! I'll try to modify the logic a bit to work against all DBs
Hide
Eloy Lafuente (stronk7) added a comment -

Hi

I've made a minor change to that code to make it cross-db (I hope). Basically I've moved the calculation of status out from the SQL, performing it at PHP code.

Attached is the hack to use against Moodle 1.7.1+ Can you confirm if it's working properly under your DBs?

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi I've made a minor change to that code to make it cross-db (I hope). Basically I've moved the calculation of status out from the SQL, performing it at PHP code. Attached is the hack to use against Moodle 1.7.1+ Can you confirm if it's working properly under your DBs? Ciao
Hide
Eloy Lafuente (stronk7) added a comment -

Fixed some bugs. New version of the lib available. Tested against MySQL and working.

Show
Eloy Lafuente (stronk7) added a comment - Fixed some bugs. New version of the lib available. Tested against MySQL and working.
Hide
Eloy Lafuente (stronk7) added a comment -

Sent to CVS 17_STABLE and HEAD. Closing this....ciao

Show
Eloy Lafuente (stronk7) added a comment - Sent to CVS 17_STABLE and HEAD. Closing this....ciao
Hide
Petr Škoda (skodak) added a comment -

the patch breaks badly the sorting when using status column - user has to log out/in to get rid of the db errors caused by missing status filed in sql query see linked bug for explanation

Show
Petr Škoda (skodak) added a comment - the patch breaks badly the sorting when using status column - user has to log out/in to get rid of the db errors caused by missing status filed in sql query see linked bug for explanation
Hide
Eloy Lafuente (stronk7) added a comment -

Done, now it's using one cross-db clause to work properly.

Applied to 17_STABLE, 18_STABLE and HEAD.

Thanks and ciao

Show
Eloy Lafuente (stronk7) added a comment - Done, now it's using one cross-db clause to work properly. Applied to 17_STABLE, 18_STABLE and HEAD. Thanks and ciao
Hide
Dilkhush added a comment -

Thank bro its working.

Show
Dilkhush added a comment - Thank bro its working.

People

Dates

  • Created:
    Updated:
    Resolved: