Reencode utf8

I'm submitting these patches on the 3.3.7 branch to begin with (since that's the version I wrote them for), because I'd like to get some feedback before rebasing them onto master. Is the feature desirable by upstream? We've found it very useful at op5 - especially at larger installations where it is not trivial to track down and/or reconfigure hosts that use nonconforming encodings.

While it works, I'm not sure about the "log from array" function in the first patch. Is there a better way to accomplish something similar using the existing API?

It would be possible to only do reencoding when an insertion has already failed, but that would make the feature dependent on the implementation of the target database. (For instance, PostgreSQL informs us of encoding errors while SQLite does not.) Besides, we have not noticed any performance degradation from using this patch, and the feature should be opt-in regardless.