Update SQL library; many bugfixes