Re: [fw-general] Executing manually built SQL queries - Is there an easier way?

2012-11-09 Thread Stephen Rees-Carter
> 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.
>
> 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());

Something like that would be perfect. It's nice and simple to understand
and means that if you just want to get the database result you can bypass
the extra steps.

Thanks,
~Stephen


On 10 November 2012 01:48, Ralph Schindler  wrote:

>
>  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-unsubscribe@lists.**zend.com
>
>
>


-- 
Stephen Rees-Carter ~ Valorin
http://stephen.rees-carter.net/


Re: [fw-general] Executing manually built SQL queries - Is there an easier way?

2012-11-09 Thread Ralph Schindler



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




[fw-general] Executing manually built SQL queries - Is there an easier way?

2012-11-07 Thread Stephen Rees-Carter
Hi all,

Someone please correct me if I've missed the easy way to do this!

Currently to build a manual SQL statement and execute it, it takes a couple
of extra steps which I don't understand or see the need for. For example,
let's run this query: SELECT count(id) AS `count` FROM `affected_version`

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

$statement = $sql->prepareStatementForSqlObject($select);
$results   = $statement->execute();

foreach ($results as $value) {
\Zend\Debug\Debug::dump($value);
}

The first two lines make sense.

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?

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'm sure there is a very good reason for this... But I don't have a clue
what it is.

Can anyone help me out here?

Thanks,
~Stephen

-- 
Stephen Rees-Carter ~ Valorin
http://stephen.rees-carter.net/