Task #9710

Refactor QueryResultProxy behaviour

Added by Karsten Dambekalns about 11 years ago. Updated about 11 years ago.

Status:
Resolved
Priority:
Must have
Category:
Persistence
Start date:
Due date:
% Done:

100%

Estimated time:
Sprint:
PHP Version:
Has patch:
Complexity:

Description

The following seems reasonable:
  • rename QueryResultProxy to QueryResult
  • get rid of FETCH_* and have execut()@e always return @QueryResult
  • add QueryResult->getFirst() (or similar) to replicate FETCH_OBJECT
  • add toArray() (or similar) to QueryResult to ease iterator_to_array() hassle

Hint: inject DataMapper and PersistenceManager to QueryResult to get actual data there instead of through no-loger-existing-FETCH_ARRAY...


Related issues

Related to TYPO3.Flow - Feature #8774: Query::execute() should return a Proxy instead of arrayResolvedBastian Waidelich

Actions
#1

Updated by Karsten Dambekalns about 11 years ago

  • Category set to Persistence
  • Start date deleted (2010-09-13)
#2

Updated by Bastian Waidelich about 11 years ago

Note: As discussed QueryResult::getFirst() should return NULL instead of FALSE if the result set is empty

#3

Updated by Karsten Dambekalns about 11 years ago

  • Status changed from New to Accepted
  • Assignee set to Karsten Dambekalns
#4

Updated by Karsten Dambekalns about 11 years ago

  • Status changed from Accepted to Needs Feedback

getFirst() would be pure syntactic sugar, as it's the same as $result->current() - I'd say we sip that.

More interesting is the name of the array-returning method. Should it be
  • toArray() - misleading, as it's not the equivalent of a typecast
  • asArray() - well it's not the QueryResult that's being returned, but the objects inside
  • getObjectsInAnArray() - seems quite long
  • getResultAsArray() - similar to asArray(), same problem

Any more?

#5

Updated by Sebastian Kurfuerst about 11 years ago

Karsten Dambekalns wrote:

getFirst() would be pure syntactic sugar, as it's the same as $result->current() - I'd say we sip that.

I'd still prefer to have a "getFirst()" method, as it is a lot more intuitive to read "getFirst()" instead of "current()".

More interesting is the name of the array-returning method. Should it be
  • toArray() - misleading, as it's not the equivalent of a typecast

I'd suggest that, as for the user, it looks like as the query result is converted to an array.
So "toArray" reads most natural for me.

Greets,
Sebastian

#6

Updated by Bastian Waidelich about 11 years ago

Karsten Dambekalns wrote:

getFirst() would be pure syntactic sugar, as it's the same as $result->current() - I'd say we sip that.

I'd prefer to keep the getFirst(). It could internally clone the query and call setLimit(1) for greater performance

More interesting is the name of the array-returning method. Should it be
  • toArray() - misleading, as it's not the equivalent of a typecast
  • asArray() - well it's not the QueryResult that's being returned, but the objects inside
  • getObjectsInAnArray() - seems quite long
  • getResultAsArray() - similar to asArray(), same problem

I like toArray() best. And in fact it should behave the same as iterator_to_array($result) doesn't it?

#7

Updated by Karsten Dambekalns about 11 years ago

Bastian Waidelich wrote:

I like toArray() best. And in fact it should behave the same as iterator_to_array($result) doesn't it?

Yes, but not the same as (array)$result... which is the difference to __toString()

#8

Updated by Bastian Waidelich about 11 years ago

Karsten Dambekalns wrote:

Bastian Waidelich wrote:

I like toArray() best. And in fact it should behave the same as iterator_to_array($result) doesn't it?

Yes, but not the same as (array)$result... which is the difference to __toString()

I still think to the user it's the same.
$result->__toArray() would be a different issue IMO

#9

Updated by Karsten Dambekalns about 11 years ago

  • Status changed from Needs Feedback to Under Review
#10

Updated by Karsten Dambekalns about 11 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF