Untested MySQL. Needs refactoring.