Problem/Motivation
The method Connection::escapeFields() will strip all spaces from column names. This appears to apply to all of the "dynamic" queries. It does not occur/get called by a static query call. I have a MySQL database which has certain tables that have spaces in the column names. While this may not be the "preferred" standard - it's not "illegal" and I need to keep the column names as they are.
Steps to reproduce
Given a table 'csvtable' with columns 'Column One', 'Column Two', 'Column3'...
Running this query code:
$this->db->delete('csvtable')
->condition('Column One', $value1)
->condition('Column Two', $value2)
->execute();
will produce something similar to the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ColumnOne' in 'where clause': DELETE FROM @csvtable
WHERE ("ColumnOne" = :db_condition_placeholder_0) AND ("ColumnTwo" = :db_condition_placeholder_1); Array
(
[:db_condition_placeholder_0] => 1234
[:db_condition_placeholder_1] => TextValue
)
Proposed resolution
Modify the escapeField() function to allow space characters in the column name.
line (1270):
$escaped = preg_replace('/[^A-Za-z0-9_.]+/', '', $field);
becomes:
$escaped = preg_replace('/[^A-Za-z0-9_. ]+/', '', $field); // adding 'space' to the allowed characters
Optionally - make the use of spaces in column names a "configurable" value with a default of False.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet