SELECT",$line); $l = str_replace("FROM","
FROM",$l); $l = str_replace("LEFT JOIN","
LEFT JOIN",$l); $l = str_replace("INNER JOIN","
INNER JOIN",$l); $l = str_replace("WHERE","
WHERE",$l); $l = str_replace("AS","AS",$l); $l = str_replace("ON","ON",$l); $l = str_replace("ORDER BY","ORDER BY",$l); $l = str_replace("LIMIT","LIMIT",$l); $l = str_replace("OFFSET","OFFSET",$l); $l = str_replace("DISTINCT","DISTINCT",$l); $l = str_replace(" ","
",$l); print $l."
"; if(substr($l,0,3) == "SQL") print "
"; } } renderQueries($str); ?> Propably the most complex feature DQL parser has to offer is its LIMIT clause parser. In pure sql the limit clause limits the number of rows returned. So for example when fetching users and their phonenumbers using limit 20 you might get anything between 1-20 users, since the first user might have 20 phonenumbers and hence the record set would consist of 20 rows.

DQL overcomes this problem with subqueries and with complex but efficient subquery analysis. In the next example we are going to fetch first 20 users and all their phonenumbers with single efficient query. Notice how the DQL parser is smart enough to use column aggregation inheritance even in the subquery.

In the next example we are going to fetch first 20 users and all their phonenumbers and only those users that actually have phonenumbers (hence the usage of colon operator = INNER JOIN) with single efficient query. Notice how the DQL parser is smart enough to use the INNER JOIN in the subquery.