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
Change History
comment:2 Changed 2 years ago by hans
- Status changed from new to closed
- Resolution set to invalid
This is not a bug; this is how the system is designed. You should get back the resource so that you don't have to read the entire contents into memory (e.g. if you only want to passthru to stdout). Returning the resource provides the most flexibility.