ramblings on PHP, SQL, the web, politics, ultimate frisbee and what else is on in my life
back

SQL function abstraction

While looking at the RoundCube source I stumbled over the use of PEAR::DB. True enough they had added their own wrapper around DB to work around its deficiencies. One of it was getting the last insert ID. Another one was the use of NOW() in their SQL commands.

Fetching the last insert ID is already supported so I went in an hacked up their wrapper and its inclusion to make it possible to use MDB2 optionally as well. But then I went a step further and added a new module to MDB2 for function calling. Right now it has support for now(), substring() and concat(). I also added an age old patch by one Nathan Fredrickson of silverorange to call stored procedures in MSSQL and PostGreSQL. Finally I put in a method that returns the FROM with table name necessary to just query a function (so in the common implementation is just returns an empty string, in the Oracle driver it returns "FROM dual" etc.) Lorenzo was quick to add a unit test for the substring() method and I took it upon me to add tests for the now() and concat() methods.

Enjoy!