Merge pull request #274 from digitalcircuit/fix-sql-inconsistencies