         (fn[]
           (let [sql (if (empty? (.getSelection @cm))
                       (.getValue @cm) (.getSelection @cm))]
-            (execute-query db sql #(if-let [data (% "data")]
-                                     (.exec-sql sql {:data data})
-                                     (reset! status (str "rows affected :" (% "rowsAffected"))))
-                           #(reset! status (error-text %)))))]
+            (execute-query db {:raw-sql sql}
+                           #(if-let [data (% "data")]
+                              (.exec-sql ops sql data)
+                              (.output ops (str "rows affected :" (% "rowsAffected"))))
+                           #(.output ops (error-text %)))))]
     (fn[db ops]
       (when active?
         (doto js/Mousetrap

      (swap! data-tabs conj {:id tbl :raw-sql (str "select * from " tbl)}))
    (reset! active-tab tbl))

  (exec-sql [_ sql & opts]
    (let [id (str "Query #" (swap! q-id inc))]
      (swap! data-tabs conj (merge opts {:id id :raw-sql sql}))
      (reset! active-tab id)))

  (delete-tab [_ t]

    (let [id (str tbl "*")]
      (when-not (some #(= id (:id %)) @data-tabs)
        (swap! data-tabs conj {:id id :table tbl}))
      (reset! active-tab id)))

  (output [_ text]
    (let [id "output"]
      (reset! out-text text)
      (when-not (some #(= id (:id %)) @data-tabs)
        (swap! data-tabs #(vec (cons {:id id :text @out-text} %))))
      (reset! active-tab id))))

(defn mk-console-control [data-tabs active-tab]
  (let [q-id (atom 0)
        out-text (atom nil)]
    (ConsoleControl. data-tabs active-tab q-id out-text)))

(defn retrieve-db-objects [db resp-atom error-atom & {:keys [refresh]}]
  (GET (str "/ds/" (db "id") "/tables?refresh=" refresh) :response-format :json
