Bugfix for encode* functions with vectors.

There was problem with wrong iterator type leading to bugs with prepare query -> execute query. This pull request contains fixes for them.