Even more SQL fixes