This was yoinked from sql_legacy, clearly this needs going over slowly :s

I guess I need to rebase/merge this branch after 2to3, once I get these tests passing