The third and forth lines (prepare*() & execute()) seem needlessly verbose.
Can't it be simplified down into a single "execute() function on the Select
object?

On the select object, probably not. The Select object by itself does not do SQL abstraction, only when prepared with a Sql object will you get SQL abstraction. The Select by itself will produce ANSI-compatible-ish queries, specific to the adapter and the platform.

I think there is a feature request in there though. Perhaps the Sql object could have an execute() which would be similar in nature to Zend\Db\Adapter\Adapter::query(). The downside is that you are throwing away the statement produced in favor of just the result. While that may seem like what you're really after in most cases, this also means you cannot change a parameter in the ParameterContainer and then execute (again) and already prepared statement.


Finally, I get back some weird Result object which I need to do yet another
operation on before I can even access the query data in a useful way.
Again, it seems needlessly verbose and not very useful. ZF1 made this
pretty easy from memory.

I personally would love to write code like this:

         $sql    = $table->getSql();
         $select = $sql->select()->columns(Array('count' => new
Expr('count(id)')));
         $results = $select->execute();

         \Zend\Debug\Debug::dump($results);

I will see about this. It would look more like this though (just stabbing in the dark):

$select = $table->getSql()->select();
$select->columns(['count' => new Expr('count(id)')]);
$results = $table->getSql()->execute($select);

var_dump($results->toArray());

-ralph

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to