Fixed getEvents bug caused by sql query