mysql adapter cleanup

now with:
 * js and sql neatly separated
 * better error messages
 * fixes