bugfixes in sqlconstructor.sql; tests added