Bug #1456

Empty array causes PDO exception if not documented as @reference

Added by Robert Lemke almost 7 years ago. Updated almost 5 years ago.

Status:Resolved Start date:2008-09-02
Priority:Should have Due date:
Assigned To:Karsten Dambekalns % Done:

100%

Category:Persistence
Target version:-
PHP Version: Complexity:
Has patch: Affected Flow version:

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.

Associated revisions

Revision 908105e7
Added by Karsten Dambekalns almost 7 years ago

FLOW3: make sure only allowed property types are accepted and used in class schemata, fixes #1456.

History

#1 Updated by Robert Lemke almost 7 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);

#2 Updated by Robert Lemke almost 7 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

#3 Updated by Karsten Dambekalns almost 7 years ago

  • Project changed from TYPO3.TYPO3CR to TYPO3.Flow

#4 Updated by Karsten Dambekalns almost 7 years ago

  • Category set to Persistence
  • Status changed from New to Accepted

#5 Updated by Karsten Dambekalns almost 7 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.

#6 Updated by Karsten Dambekalns almost 7 years ago

  • Status changed from Accepted to Resolved
  • % Done changed from 0 to 100

Applied in changeset r1176.

Also available in: Atom PDF