fixing sql bugs

hopefully got them all