                              acc)
                            (doto request-factory (.setOptions ro))
                            options)]
-    (.submitRequest session request)))
-
-(defn execute-request
-  "Execute the given request to the database connection defined by the
-  given session. Apply request options or variables if given. Iterate
-  over results before returning them. NB: this iterating makes some
-  Java objects unusable, e.g. those used internal database reporting."
-  ;; FIXME don't make java objects unusable
-  [request-factory session query options variables]
-  (loop [rs (submit-request request-factory session query options variables)
-         data []]
-    (if (.hasNext rs)
-      (let [rsItem (.next rs)
-            item (.getItem rsItem)]
-        (recur rs (conj data (str item))))
-      (do (when-not (.isClosed rs)
-            (.close rs))
-          data))))
-;; FIXME Maybe make the request result adhere to the sequence protocol?  Can with-open be used, as
-;; rs seems to be closable?  The function is hard to understand as it is.
+    (cond (= :raw types) (.submitRequest session request)
+          :else (convert-types (.submitRequest session request) types))))
 
 (defn execute-xquery
   "Execute the given xquery query as a request to the database
   connection defined by the given session. Apply request options or
-  variables if given."
-  ([session query]
-   (submit-request (.newAdhocQuery session query) session query {} {}))
-  ([session query options]
-   (submit-request (.newAdhocQuery session query) session query options {}))
-  ([session query options variables]
-   (submit-request (.newAdhocQuery session query) session query options variables)))
+  variables if given. Applies default type conversion, overridden by
+  `types` map if given."
+  [session query & {:keys [options variables types]}]
+  (submit-request (.newAdhocQuery session query) session query options variables types))
 
 (defn execute-module
   "Execute the named module as a request to the database connection
   defined by the given session. Apply request options or variables if
+  given. Applies default type conversion, overridden by `types` map if
   given."
-  ([session module]
-   (submit-request (.newModuleInvoke session module) session module {} {}))
-  ([session module options]
-   (submit-request (.newModuleInvoke session module) session module options {}))
-  ([session module options variables]
-   (submit-request (.newModuleInvoke session module) session module options variables)))
+  [session module & {:keys [options variables types]}]
+  (submit-request (.newModuleInvoke session module) session module options variables types))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   ;; FIXME XDM keys have only been mocked; unknown if it matches getValueType

   ;; XdmAtomic TODO
   "attribute()" #(.asString %) ;; XdmAttribute TODO
   "binary()" #(.asString %) ;; XdmBinary -- XXX unknown if the key used matches getValueType
   "comment()" #(.asString %) ;; XdmComment
   "document-node()" #(.asString %) ;; XdmDocument

   "xs:untypedAtomic" str ;; NB: also referred to as "xdt:untypedAtomic" in type listing
   "xs:yearMonthDuration" str})

;; FIXME this is not currently usable if convert-types is part of execute-xquery
(defn result-type
  "Returns type string of the given query Result object. Currently
  assumes result is homogenous."
