Issue Details (XML | Word | Printable)

Key: MDL-8164
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Eloy Lafuente (stronk7)
Reporter: Tom McMurtry
Votes: 2
Watchers: 4
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

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

Created: 12/Jan/07 11:20 PM   Updated: 14/Sep/07 02:05 AM
Return to search
Component/s: Assignment
Affects Version/s: 1.7.1
Fix Version/s: 1.7.3, 1.8.3, 1.9

File Attachments: 1. File lib.php (96 kB)

Environment: Windows 2003, Php 5.12, Sql 2005
Issue Links:
Dependency
 

Database: Microsoft SQL
Participants: Eloy Lafuente (stronk7), Iñaki Arenaza, Petr Skoda and Tom McMurtry
Security Level: None
Resolved date: 14/Sep/07
Affected Branches: MOODLE_17_STABLE
Fixed Branches: MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
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 ';
 }


 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Iñaki Arenaza added a comment - 14/Jan/07 11:38 PM
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.


Eloy Lafuente (stronk7) added a comment - 15/Jan/07 02:15 AM
True!

That expression isn't cross-db at all!

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


Eloy Lafuente (stronk7) added a comment - 31/Jan/07 03:40 AM
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


Eloy Lafuente (stronk7) added a comment - 31/Jan/07 03:49 AM
Fixed some bugs. New version of the lib available. Tested against MySQL and working.

Eloy Lafuente (stronk7) added a comment - 02/Feb/07 07:51 AM
Sent to CVS 17_STABLE and HEAD. Closing this....ciao

Petr Skoda added a comment - 21/Aug/07 06:26 AM
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

Eloy Lafuente (stronk7) added a comment - 14/Sep/07 02:03 AM
Done, now it's using one cross-db clause to work properly.

Applied to 17_STABLE, 18_STABLE and HEAD.

Thanks and ciao