Skip to content

Database warnings - 'duplicate id' #98

@thepurpleblob

Description

@thepurpleblob

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions