Fixed sqlite queries.