Moodle

Moodle 1.7: cannot display list of courses in a category

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.7
  • Component/s: Administration
  • Labels:
    None
  • Environment:
    Moodle 1.7
  • Database:
    Any
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE

Description

Error message in Moodle 1.7 when trying to view courses in the "Miscellaneous" category

--------------------------------------------------------
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SELECT c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.teacher,c.guest,c.password FROM mdl_course c WHERE c.category = '1' ORDER BY c.sortorder ASC LIMIT 0,
--------------------------------------------------------

To reproduce the error

1. Display categories
moodle/course/index.php?categoryedit=on

2. Display "Miscellaneous" category
moodle/course/category.php?id=1&categoryedit=on&sesskey=IVvZvGM6SX

Error is caused because "lib/dmllib.php::sql_paging_limit" returns invalid SQL if $recordsperpage is '' (empty string)

Two suggested fixes:

1. make "lib/dmllib.php::sql_paging_limit" more robust

----------------------------------------------------
function sql_paging_limit($page, $recordsperpage) {
global $CFG;

if ($page==='' || $recordsperpage==='') { return ''; } else {
switch ($CFG->dbtype) { case 'postgres7': return 'LIMIT '. $recordsperpage .' OFFSET '. $page; default: return 'LIMIT '. $page .','. $recordsperpage; }
}
}
----------------------------------------------------

2. make "lib/moodlelib::get_courses_page" more robust

----------------------------------------------------
function get_courses_page() {
/* snip */
if ($limitfrom==='' || $limitnum==='') { $limit = ""; } else { $limit = sql_paging_limit($limitfrom, $limitnum); }
/* end snip */
}
----------------------------------------------------

Activity

Hide
Gordon Bateson added a comment -

This is no longer a problem since the courseperpage field got defined in the mdl_config table.

The bug stops here.

Show
Gordon Bateson added a comment - This is no longer a problem since the courseperpage field got defined in the mdl_config table. The bug stops here.
Hide
Nicolas Martignoni added a comment -

Verified on 1.7dev fresh from CVS, closing.

Show
Nicolas Martignoni added a comment - Verified on 1.7dev fresh from CVS, closing.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: