Use a type object for type casting behavior on SQLite3

Note: I'm not sure we actually need to be logging when this happens.
This code would be a fair bit cleaner if we didn't need to log it.

/cc @matthewd