Bug #1456

Empty array causes PDO exception if not documented as @reference

Added by Robert Lemke about 11 years ago. Updated about 9 years ago.

Status:
Resolved
Priority:
Should have
Category:
Persistence
Target version:
-
Start date:
2008-09-02
Due date:
% Done:

100%

PHP Version:
Has patch:
Complexity:

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 (diff)
Added by Karsten Dambekalns about 11 years ago

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

History

#1 Updated by Robert Lemke about 11 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 about 11 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 about 11 years ago

  • Project changed from TYPO3.TYPO3CR to TYPO3.Flow

#4 Updated by Karsten Dambekalns about 11 years ago

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

#5 Updated by Karsten Dambekalns about 11 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 about 11 years ago

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

Applied in changeset r1176.

Also available in: Atom PDF