DF Some fixes in sql.
Merge branch 'hotfix/sql'