fix plain sql queries