Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-82043

Improve working with the reserved words in Moodle DML

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.3.5, 4.4
    • Database SQL/XMLDB
    • None
    • MOODLE_403_STABLE, MOODLE_404_STABLE

      Discovered while testing MDL-81751

      I was looking at how reserved words are used in Moodle. The reserved lists are checked:

      • in the XMLDB editor, only to display that a word is reserved (from all supported db type)
      • in the command sql_generator::getEncQuoted() that will add db-specific quotes if the parameter is a reserved keyword (from the current db type)

      The later is mostly used when creating/updating/dropping tables, columns and indexes. There are couple of other cases where it is used, for example, in tool_httpsreplace :

      $columnnamequoted = $DB->get_manager()->generator->getEncQuoted($columnname);
      list($select, $params) = $this->get_select_search_in_column($columnnamequoted);
      $rs = $DB->get_recordset_select($table, $select, $params, '', $columnnamequoted);
      

      Surprisingly, the getEncQuoted() function is not used where I would expect it to be used:

      • in $DB->insert_record() function to quote column names
      • in $DB->get_records() and similar to quote column names from the second argument
      • any other method in $DB where you pass a column name
      • in backup/restore when you specify list of columns in `new backup_nested_element()`

      Moodle also does not display any warnings anywhere that a plugin uses reserved keywords as table/column names.

      A good test would be to create an activity module where the main table has a column named "where", add the column to the backup, add some $DB calls to insert/update this column . And then see how many places will break.

      However even if we do this, there are some places where people need to make sure to manually quote column names using `getEncQuoted()`:

      • $DB methods where column names are used in a SQL statement (get_records_sql, get_records_where, etc)
      • Any other place where we pass SQL fragments (report builder, for example)

            Unassigned Unassigned
            marina Marina Glancy
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.