In #337926: Force connection with PDO::CASE_LOWER, a default PDO database connection attribute was added that converts all fetched field/column names into lowercase. That is, for no particular reason.
This turns integration with third-party web services into a pain.
Schema functions, however, still create fields with their natural letter casing.
Example:
db_create_table('foo');
db_add_field('foo', 'contentId', array(
'type' => 'int',
'not null' => FALSE,
));
db_insert('foo')
->fields(array('contentId' => 3)
->execute();
debug(db_query('SELECT * FROM {foo} WHERE contentId = :id', array(':id' => 3))->fetchObject());
stdClass::__set_state(array(
'contentid' => '3',
))
Note that the fetched column name is lowercase, contentid instead of contentId.
The only ugly workaround for the moment:
function foo_db_query($query, array $args = array(), array $options = array()) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
$connection = Database::getConnection($options['target']);
// Backup and restore PDO::ATTR_CASE afterwards, 'cause it sticks.
$backup = $connection->getAttribute(PDO::ATTR_CASE);
$connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
// Execute the query statement.
$result = $connection->queryRange($query, $from, $count, $args, $options);
// Restore the attribute.
$connection->setAttribute(PDO::ATTR_CASE, $backup);
return $result;
}
It might be possible to set PDO::ATTR_CASE on a statement only (instead of the connection). At least there's http://php.net/manual/en/pdostatement.setattribute.php, living right next to http://www.php.net/manual/en/pdostatement.setfetchmode.php, which we already support through $options = array('fetch' => PDO::FETCH_...)