Improve SQL extension 

Prevent NPE as reported in https://github.com/eXist-db/exist/issues/254
Smaller code improvements