Decoding a Moodle error

Decoding a Moodle error

by Pedro Martins De Torre -
Number of replies: 1

I'm running a Moodle 2.0.4+ site on a Windowse Server 2003 machine with SQL Server 2008 R2 as the database engine and SQLSRV as the database driver. PHP 5.3.3 NTS.

During a routine check I found the following error in my PHP Errors log file:

[01-Apr-2015 21:51:01] sqlsrv_query: SQLSTATE = 42000
[01-Apr-2015 21:51:01] sqlsrv_query: error code = 8114
[01-Apr-2015 21:51:01] sqlsrv_query: message = [Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type nvarchar to bigint.
[01-Apr-2015 21:51:01] Default exception handler: Error reading from database Debug: SQLState: 42000<br>
Error Code: 8114<br>
Message: [Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type nvarchar to bigint.<br>

SELECT u.id,u.picture,u.firstname,u.lastname,u.imagealt,u.email
              FROM mdl_user u
              JOIN (SELECT DISTINCT eu1_u.id
               FROM mdl_user eu1_u
             JOIN mdl_groups_members eu1_gm ON (eu1_gm.userid = eu1_u.id AND eu1_gm.groupid = N'Array')
JOIN mdl_user_enrolments eu1_ue ON eu1_ue.userid = eu1_u.id
JOIN mdl_enrol eu1_e ON (eu1_e.id = eu1_ue.enrolid AND eu1_e.courseid = '563')
            WHERE eu1_u.deleted = 0 AND eu1_u.id <> '1') je ON je.id = u.id
             WHERE u.deleted = 0 ORDER BY u.lastname ASC, u.firstname ASC
[array (
  0 =>
  array (
    0 => 4808,
  ),
  1 => '563',
  2 => '1',
)]
* line 391 of \lib\dml\moodle_database.php: dml_read_exception thrown
* line 252 of \lib\dml\sqlsrv_native_moodle_database.php: call to moodle_database->query_end()
* line 368 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->query_end()
* line 773 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->do_query()
* line 807 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->get_recordset_sql()
* line 3259 of \lib\accesslib.php: call to sqlsrv_native_moodle_database->get_records_sql()
* line 63 of \course\recent_form.php: call to get_enrolled_users()
* line 153 of \lib\formslib.php: call to recent_form->definition()
* line 59 of \course\recent.php: call to moodleform->moodleform()

The problem in that SQL query is probably the invalid

eu1_gm.groupid = N'Array'

part of th query. It should contain the actual array items, not the string "Array". But the error message doesn't tell me where that error was triggered. There are those nine "line xxx of xxx" references, but where is Moodle generating the above SQL query and how do I determine where the problem is?

Yes, I know it's an old version of Moodle and it should be upgraded...

Average of ratings: -
In reply to Pedro Martins De Torre

Re: Decoding a Moodle error

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Pedro -

Read the calling tree of the error messages from the bottom to the top. The SQL is most likely getting created in whatever function is at line 3259 of "\lib\accesslib.php". That's where the call to the database functions starts.

mike

Average of ratings: Useful (1)