Fix mysql-specific errors

I've tried to use this bundle with Postgresql, and it failed in several places, due to incorrect types and MySQL (I think) specific assumptions.