The error is the SQL that is being sent to the database. Could you print out then SQL that is being generated and post it here.