Bugfix when checking for dependencies.

State can be NULL, and in some SQL implementations not checking for that
explicitly can lead to unexpected results
Merge pull request #130 from guidow/dependency_bugfix

Bugfix when checking for dependencies.