Bugfix when checking for dependencies.

State can be NULL, and in some SQL implementations not checking for that
explicitly can lead to unexpected results