                     callback error, result
 
         cursor_next: (cursor, {error, row, end}) =>
+            if not @connection?
+                end()
             @container.toggle_executing true
             cursor.next (err, row_) =>
                 @container.toggle_executing false

                    return @query_result.results[@query_result.position .. @query_result.position + @parent.container.limit]

        fetch_batch_rows:  =>
            if @query_result.results?.length - @query_result.position < @parent.container.limit
                @query_result.once 'add', (query_result, row) =>
                    @add_row row
                    @fetch_batch_rows()
                @query_result.fetch_next()

        show_next_batch: =>
            @query_result.position += @parent.container.limit
            @fetch_batch_rows()
            @render()

        add_row: =>
            @render()

    # This class represents the results of a query.
    #
    # If there is a profile, `profile` is set. After a 'ready' event,
    # one of `error`, `value` or `cursor` is always set, `type`
    # indicates which. `ended` indicates whether there are any more
    # results to read.
    #
    # It triggers the following events:
    #  * ready: The first response has been received
