Fix duplicated code in db_virtual