Ticket #128 (new enhancement)
QQuery - SubQueries SubSQL - natural support for literals
| Reported by: | alex94040 | Owned by: | somebody |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.2 |
| Component: | QQuery | Version: | |
| Keywords: | qquery, subsql, QQN | Cc: |
Description
Ported from http://www.qcodo.com/forums/topic.php/2770/1//?strSearch=SubSQL:
I've just been banging my head against the wall with subqueries - I think they're really cool, but without documentation, it's a bit tough to get them right the first time. Or the 10-th time, in my case :-)
One particular issue has been messing me up badly: the fact that {1}-style substitutions only work with QQ Nodes, not literals.
So a supposedly innocent query
QQ::Virtual('invitationCount',
QQ::SubSql('SELECT count(*)
FROM invitation
WHERE invitation.JobID = {1} AND
invitation.WorkerID = {2}',
QQN::Job()->Id,
$myIntegerWorkerId
)
)
falls flat on its face with a cryptic error message about GetColumnAlias?. The root cause, of course, is that {2} is not the right way to refer to the integer literal here. And that's totally not intuitive - I had to go with the following 'messy' code instead:
QQ::Virtual('invitationCount',
QQ::SubSql('SELECT count(*)
FROM invitation
WHERE invitation.JobID={1} AND
invitation.WorkerID=' . intval($myIntegerWorkerId),
QQN::Job()->Id
)
)
Please, add support for literals, not just QQN nodes, into SubSql?.
