split typecast method into two

one method for fetching data and one for sending to db.

fixes #2287
How about we keep the name `typecast()` and rename `typecastToDatabase()` to `dbTypecast()`? 
The former is the most used case and keeping the same name will not break BC.