Fix prepared insert statement

This fix also allows to use data exchange with custom type.
Fixes #117

(Original commit message amended by Mateusz Loskot)