   ;;===========
   (get-sql    [m] (:sql m))
   (set-params [m ^PreparedStatement prepared-statement params]
-    (if-let [param-keys (:param-keys m)]
-      (let [param-types (or (:param-types m) (no-param-type-vec (count param-keys)))]
-        (set-params! prepared-statement param-keys param-types :vector params))
-      (set-params! prepared-statement params)))
+    (cond
+      (map? params)    (if-let [param-keys (:param-keys m)]
+                         (let [param-types (or (:param-types m) (no-param-type-vec (count param-keys)))]
+                           (set-params-map! prepared-statement param-keys param-types params))
+                         (expected "key :param-keys to be present" m))
+      (vector? params) (if-let [param-types (or (:param-types m) (when-let [param-keys (:param-keys m)]
+                                                                   (no-param-type-vec (count param-keys))))]
+                         (set-params-vec! prepared-statement param-types params)
+                         (set-params-vec! prepared-statement params))
+      (nil? params)    nil
+      :otherwise       (expected "map, vector or nil" params)))
   (read-col   [m ^ResultSet result-set ^long column-index]
     (if-let [types (:result-types m)]
       (let [column-type (get types (unchecked-dec column-index))]

      (unexpected supported-sql-types param-type))))


(defn set-params!
  ([^PreparedStatement prepared-statement params]
    (cond
      (vector? params) (let [param-count (count params)]
                         (loop [i (int 0)]
                           (when (< i param-count)
                             (let [j (unchecked-inc i)]
                               (set-param-value! prepared-statement j (get params i))
                               (recur j)))))
      (nil? params)    nil
      :otherwise       (unexpected "params vector" params)))
  ([^PreparedStatement prepared-statement ^objects param-keys ^bytes param-types params]
    (cond
      (map? params)    (let [param-count (alength param-keys)]
                         (loop [i (int 0)]
                           (when (< i param-count)
                             (let [param-key  (aget param-keys i)
                                   param-type (aget param-types i)
                                   j (unchecked-inc i)]
                               (if (contains? params param-key)
                                 (try
                                   (set-param-value! prepared-statement j param-type (get params param-key))
                                   (catch RuntimeException e
                                     (throw (ex-info (str "Error setting parameter #" j " (" param-key "): "
                                                       (.getMessage e))
                                              {:param-index j :param-key param-key} e))))
                                 (illegal-arg "No value found for key:" param-key "in" (pr-str params)))
                               (recur j)))))
      (vector? params) (let [types-count (alength param-keys)
                             param-count (count params)]
                         (loop [i (int 0)]
                           (when (< i param-count)
                             (let [j (unchecked-inc i)]
                               (if (< i types-count)
                                 (let [param-key  (aget param-keys i)
                                       param-type (aget param-types i)]
                                   (try
                                     (set-param-value! prepared-statement j param-type (get params i))
                                     (catch RuntimeException e
                                       (throw (ex-info (str "Error setting parameter #" j " (" param-key "): "
                                                         (.getMessage e))
                                                {:param-index j :param-key param-key} e)))))
                                 (try
                                   (set-param-value! prepared-statement j t/sql-nil (get params i))
                                   (catch RuntimeException e
                                     (throw (ex-info (str "Error setting parameter #" j ": " (.getMessage e))
                                              {:param-index j} e)))))
                               (recur j)))))
      (nil? params)    nil
      :otherwise       (unexpected "map or vector" params)))
  ([^PreparedStatement prepared-statement #_vector param-keys #_vector param-types _ params]
    (cond
      (map? params)    (let [param-count (count param-keys)]
                         (loop [i (int 0)]
                           (when (< i param-count)
                             (let [param-key  (get param-keys i)
                                   param-type (get param-types i)
                                   j (unchecked-inc i)]
                               (if (contains? params param-key)
                                 (try
                                   (set-param-value! prepared-statement j param-type (get params param-key))
                                   (catch RuntimeException e
                                     (throw (ex-info (str "Error setting parameter #" j " (" param-key "): "
                                                       (.getMessage e))
                                              {:param-index j :param-key param-key} e))))
                                 (illegal-arg "No value found for key:" param-key "in" (pr-str params)))
                               (recur j)))))
      (vector? params) (let [types-count (count param-keys)
                             param-count (count params)]
                         (loop [i (int 0)]
                           (when (< i param-count)
                             (let [j (unchecked-inc i)]
                               (if (< i types-count)
                                 (let [param-key  (get param-keys i)
                                       param-type (get param-types i)]
                                   (try
                                     (set-param-value! prepared-statement j param-type (get params i))
                                     (catch RuntimeException e
                                       (throw (ex-info (str "Error setting parameter #" j " (" param-key "): "
                                                         (.getMessage e))
                                                {:param-index j :param-key param-key} e))))
                                   (try
                                     (set-param-value! prepared-statement j t/sql-nil (get params i))
                                     (catch RuntimeException e
                                       (throw (ex-info (str "Error setting parameter #" j ": " (.getMessage e))
                                                {:param-index j} e))))))
                               (recur j)))))
      (nil? params)    nil
      :otherwise       (unexpected "map or vector" params))))


;; ----- result-set stuff -----

  String
  ;;====
  (get-sql    [sql] sql)
  (set-params [sql ^PreparedStatement prepared-statement params] (if (vector? params)
                                                                   (set-params-vec! prepared-statement params)
                                                                   (when-not (nil? params)
                                                                     (expected "a params vector" params))))
  (read-col   [sql ^ResultSet result-set ^long column-index]     (read-column-value result-set column-index))
  (read-row   [sql ^ResultSet result-set ^long column-count]     (read-columns result-set column-count)))

