Ticket #672 (closed defect: invalid)
Getter method Blob return resource
| Reported by: | cyrillus | Owned by: | hans |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.3.1 |
| Component: | Generator | Version: | 1.3.0RC1 |
| Severity: | normal | Keywords: | Generator Blob get |
| Cc: |
Description
Hi,
I have found an issue with getter method for field like BLOB.
In setter method of base object for fields these kind of filed there is a creation of resource in order to have PDOStatement::bindValue method working with PDO::PARAM_LOB.
Then for those type of field we have currently the following generated code
/**
* Set the value of [data] column.
*
* @param int $v new value
* @return MyTable The current object (for fluent API support)
*/
public function setData($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->data !== $v) {
$this->data = $v;
$this->modifiedColumns[] = MyTablePeer::DATA;
}
return $this;
} // setData()
But for getter method we have :
/**
* Get the [data] column value.
*
* @return string
*/
public function getData()
{
return $this->data;
}
When you call this method , you receive a resource not the data itself, so you have to read it to be able to have the content.
I think the read part should be inside the getter to be manage resource part in Propel.
The following code is working for me , so there is a need of addLobAccessor method in PHP5ObjectBuilderObject :
/**
* Get the [data] column value.
*
* @return string
*/
public function getData()
{
if (is_resource($this->data)) {
while(!feof($this->data)){
$content.= fread($this->data, 1024);
}
rewind($this->data);
return $content;
} else {
return $this->data;
}
}
Regards ,
Cyrille Heulland
