DB: enable SQLite type detection

Turn on the SQLite module's detect_types option, with the aim of
receiving date and datetime objects to match those returned by
MySQL.  For expressions such as MAX(datetime) we need to give
the type explicitly, so SQLite queries are now passed through
a function add_types before being executed.