rewriting SQL queries, adding all sqlite_check_* functions.