PDO provides us with the (highly desirable) possibility of providing the contents for a blob file through a filehandle resource, so the data can be read directly from a file or another stream source. When retrieving blob data from the database, I already get such file handle back. However, when creating of updating a record with a blob field using a filehandle, this fails. It fails because of two issues:
- Doctrine_Validator::isValidType() rejects the resource handle, because blob fields are only checked using is_string().
- $sth->execute($params) is used for executing a query after preparing it. The $params are provided straight away to the statement handle, without differentiating between field types by means of explicit bindings. An explicit binding with Doctrine::PARAM_PDO would be needed to allow for field data upload using a filehandle.
I have already been going over the code and I could not find a very good spot for handling this. What functionally should happen is that:
- a blob field
- for which a stream resource is set
- should not be rejected as a valid blob type field and
- should be bound as a param to the prepared insert/update query
- using the data type Doctrine::PARAM_LOB
In the attached patch, I have updated the code in a way that makes this feature work. What I did feels like a hack, but I couldn't find a good way to implement this cleanly. The type of field that we are handling (blob or not?), the data that we are handling (resource or not?) and the spot where we can use bindParam() are not really tightly interconnected (or maybe they are and I overlooked it).