IMPALA-897: shell does not close queries after completion when running from a script

The problem was that we were setting a flag marking the last_query_handle as closed, but
were not resetting the flag before the next query. This caused the first query to
be closed properly, but subsequent queries would not be closed. The fix is to change
where the flag is reset to the same place as where we assign last_query_handle.

Added a test case.

Change-Id: I870a96789489bfe4f388910b808409cd0584af8a
Reviewed-on: http://gerrit.ent.cloudera.com:8080/1966
Reviewed-by: Ishaan Joshi <ishaan@cloudera.com>
Tested-by: jenkins