-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
4.3.5, 4.4
-
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)
- Discovered while testing
-
MDL-81751 New reserved keywords in Aurora MySQL database engine
-
- Closed
-