I have an issue connecting to the repository (either because of our proxy or Windows) so instead am posting a couple of bug fixes here.
The first bug is with the DBMSSQL::applyLimit function. It’s doesn’t check for SELECT modifiers and as such will generate invalid SQL when a SELECT modifier is present. I have provided a quick and dirty fix for this, I suggest someone should rewrite it but the code I have provided works.
The second bug I found with the same DBMSSQL::applyLimit function but it may appear elsewhere. The DBMSSQL::applyLimit function converts the SQL query into a sub-query to get around Microsoft SQL Server’s lack of an OFFSET function. The resulting SQL will fail (ambiguous column name) if two or more tables are joined, have columns with the same name and one or more of those columns is in the ORDER BY statement. To get around this bug, I updated the Criteria class to automatically alias columns when required. I have modified Criteria so that is caches column names, similar to Criteria ::selectColumns except that the table name is removed and the number of times the column name has been used is stored as the value. Criteria::addSelectColumn checks if the column name has been used before and if so adds an alias to the table name. This is a pretty big change to Criteria so you may wish to either ignore my change, suggest another workaround, or call it a “auto-aliasing” feature and milk it for all it’s worth.