In issue #2506005: PostgreSQL incompatible with Storage API, we've run into a problem where binary data is being passed as a value to the ->condition method, and on PostgreSQL, this typically results in a 'invalid byte sequence for encoding "UTF8"' error.
The code involved is
$file_id = db_select('storage_file')
->fields('storage_file', array('file_id'))
->condition('whirlpool', $whirlpool)
->condition('filename', $filename)
->execute()
->fetchField();
The whirlpool field is defined as:
'whirlpool' => array(
'type' => 'blob', 'length' => 64, 'not null' => TRUE,
'mysql_type' => 'BINARY(64)',
),
And the contents of $whirlpool is definitely binary, being returned from hash_file:
$whirlpool = hash_file('whirlpool', $uri, TRUE);
Is there some way of indicating that the value passed to ->condition is binary, and therefore should be properly escaped or formatted as such if the underlying database requires it? Is there a different way of handling it?
Comments
Comment #2
roderikThis is still not solved in D9. #2238253: Add bindValue to a PDO::PARAM_* type in database query arguments is trying to solve it by adding an extra optional argument
$bindValueto (what in D7 is)DatabaseConnection::query().So this issue could be the D7 followup once it gets fixed there.
(There's no problem description on #2238253, but it refers to #710940-10: Support for BINARY and VARBINARY in Database Schema which shows the same error.)