Corrected and fixed DAO for using common SQL functions.