jonof / moodle-block_completion_progress

A time management tool for students using activity completion
https://moodle.org/plugins/block_completion_progress
GNU General Public License v3.0
17 stars 65 forks source link

Database warnings - 'duplicate id' #98

Open thepurpleblob opened 1 year ago

thepurpleblob commented 1 year ago

Getting lots of these...

Did you remember to make the first column something unique in your call to get_records? Duplicate value '77126' found in column 'id'.
line 1287 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
line 196 of /blocks/completion_progress/block_completion_progress.php: call to mysqli_native_moodle_database->get_records_sql()
line 127 of /blocks/completion_progress/block_completion_progress.php: call to block_completion_progress->prepare_dashboard_content()

The SQL and parameters that are causing this is...

string(615) "SELECT bi.id,
                       COALESCE(bp.visible, 1) AS visible,
                       bi.configdata
                  FROM {block_instances} bi
             LEFT JOIN {block_positions} bp ON bp.blockinstanceid = bi.id
                                           AND LOWER(bp.pagetype) LIKE LOWER(:pagetype) COLLATE utf8mb4_bin ESCAPE '\\'
                 WHERE bi.blockname = 'completion_progress'
                   AND bi.parentcontextid = :contextid
              ORDER BY COALESCE(bp.region, bi.defaultregion),
                       COALESCE(bp.weight, bi.defaultweight),
                       bi.id"
array(2) {
  ["contextid"]=>
  int(136075)
  ["pagetype"]=>
  string(13) "course-view-%"
}

Unfortunately, I'm really struggling to see what this SQL is trying to do. The LEFT JOIN followed by an AND looks wrong to me. I thought that needed parenthesis? However, I must admit to being unsure.