      (dispatch [:update db-id [:resultsets (:id q)] assoc :loading true]))
    (let [offset (or offset 0)
          limit (or limit 40)
+         qid (inc (state :query-count 0))
          sql (if (string? q) q (sql-select (:query q)))]
      (POST (str "/ds/" db-id "/exec-sql")
            :params {:sql sql :offset offset :limit limit}

           :error-handler #(dispatch-all [:update db-id :in-queue empty]
                                         [:update db-id :dbout str "\n" sql "\n" (error-text %) "\n"]
                                         [:activate-table db-id :out])))
   state))

(register-handler
 :update-result

 (fn [state [db-id q data offset]]
   (if (string? q)
     (let [qnum (inc (or (state :query-count) 0))
           q {:id (str "Result #" qnum) :data data
              :query (query-from-sql q)}]
       (dispatch [:activate-table db-id (:id q)])
       (-> state (update :resultsets assoc (:id q) q)
