Refactoring: Add get_first_i() function to sql lib.
Refactoring some sql code.
Escape _ and % in SQL LIKE queries.

Fixes #40.
Fix up-link from database statistics report.