Fix code writing to the database to work in any locale as well.

This is similar to #238 but completes it by

 1. Doing the same thing in the other direction, i.e. when writing doubles to the database and not reading them.
 1. Doing the same changes in mysql and sqlite3 backends in addition to the postgresql one.