Order/Group/Having Clauses

There are a few last minute clauses to an SQL statement that I need to address. The HAVING clause is fairly straight forward. I requires a WHERE condition, so that is what I will use. Any statement class that can take a HAVING clause will accept an sqlConditionGroup as an argument as long as it is of the WHERE type. The ORDER BY and GROUP BY clauses will have their own classes.

An abstract sqlSorter class will be extended to create both the sqlOrder and sqlGroup classes. The sqlSorter will, in turn, be extended from the sqlRelationship class. Utilizing the same name/value pairs to hold things like column definitions or functions and the value being the direction, ASC or DESC. I am imagining functionality that will allow a user to add an sqlSelectExpression to the sqlStatement class, then designate it as a column to ORDER or GROUP by. The method to add the expression will return a reference to the added expression, this expression will have a reference to the statement class that holds it. When the expression is designated as a sorter, it will call its “parent” statement class to add the appropriate column definition to an internal array of sorters.

$objSelect->addSelect($objTable)->setAS('col1')->orderBy(2);

The value passed to “orderBy” will be used to sort the array. This will allow users to set order by rules out of order while creating select or where expressions. Either of the sqlSorter children can contain any number of sqlComponent classes to create the finalized string.

sqlNewQuery-uml-20110111

Leave a Reply