Fixes in sql.cpp