SQL generator loosely based on Zend_Db_Select.