One problem I seeIs that you do all this in the view controller, whereas you should do this in the model layer. Depending on how the view criteria is build (ignore nulls, required bind variables) the sql builder omits posts of the where clause.
What might happen is that one of your bind variables are set to null without your knowledge. To be sure that your variables are set correctly you need to log the message from the executeQuery method. a sample on how to do this can be found here http://wp.me/pcBZk-2d
Third method dumps the query and it's parameters.
Looks like the bind variable was being fed a null value (selectedPhaseId in the code above), which was causing the error.
Ahhh the joys of working on someone else's code...