Bug #1456
Empty array causes PDO exception if not documented as @reference
100%
Description
Consider this model:
/** *@entity */ class { /** * @var array */ protected $subObjects = array(); }
This will result in a PDO exception because the type of the array items cannot be determined and no @reference annotation is given.
Even if multi-value properties of different types are not allowed (yet), there should be some proper handling for these cases.
Updated by Robert Lemke over 13 years ago
SQLSTATE[HY000]: General error: 1 no such table: undefinedmultivalueproperties
PDOException thrown in file
TYPO3CR/Classes/Storage/Backend/F3_TYPO3CR_Storage_Backend_PDO.php in line 250.
19 PDO::prepare("SELECT "index", "value" FROM "undefinedm…" = ? AND "name" = ? AND "namespace" = ?")
/Users/Shared/Sites/dev/t3v5/dist/Packages/TYPO3CR/Classes/Storage/Backend/F3_TYPO3CR_Storage_Backend_PDO.php:
00248: $typeName = strtolower(F3_PHPCR_PropertyType::nameFromValue($property['type']));
00249:
00250: $statementHandle = $this->databaseHandle->prepare('SELECT "index", "value"' . ($property['type'] == F3_PHPCR_PropertyType::NAME ? ',"valuenamespace"' : '') . ' FROM "' . $typeName . 'multivalueproperties" WHERE "parent" = ? AND "name" = ? AND "namespace" = ?');
00251: $statementHandle->execute(array($property['parent'], $property['name'], $property['namespace']));
00252: $multivalues = $statementHandle->fetchAll(PDO::FETCH_ASSOC);
Updated by Robert Lemke over 13 years ago
This will result in a PDO exception because the type of the array items cannot be determined and no @reference annotation is given.
Update: This even happens if a @reference annotation is given. The error does not occur however if the property is marked as @transient
Updated by Karsten Dambekalns over 13 years ago
- Category set to Persistence
- Status changed from New to Accepted
Updated by Karsten Dambekalns over 13 years ago
Robert Lemke wrote:
Consider this model:
[...]
This will result in a PDO exception because the type of the array items cannot be determined and no @reference annotation is given.
The actual offending code that first showed this error used an annotation like "@var array of pages", which lead to the variable type "array of pages" being seen by the reflection. That in turn ended up in the class schema and the property ended up in the database with an "undefined" type.
The fix is to a) use @var annotations as shown in the CGL and b) make sure the class schema only accepts allowed types. For convenience add c) try to extract a meaningful type from the annotation in cases like the one above.
Updated by Karsten Dambekalns over 13 years ago
- Status changed from Accepted to Resolved
- % Done changed from 0 to 100
Applied in changeset r1176.