                       (quote-ent table) field-str val-str)]
      (sql-stmt (jdbc/find-connection) stmt-str fields)))
 
+(defn sequence-stmt ^cavm.statement.PStatement [db-seq]
+  (sql-stmt-result (jdbc/find-connection)
+                         (format "SELECT NEXT VALUE FOR %s AS i" db-seq)))
+
 (def batch-size 1000)
 
 (defn- table-writer-default [dir dataset-id matrix-fn]

  (:require [taoensso.timbre :as timbre])
  (:require [clojure.core.cache :as cache])
  (:require [cavm.h2-unpack-rows :as unpack])
  (:require [cavm.statement :refer [sql-stmt cached-statement]])
  (:gen-class))

;

                                                  :valueType :visibility])
              score-stmt (insert-stmt :scores [:id :scores])
              field-stmt (insert-stmt :field [:id :dataset_id :name])
              field-score-stmt (insert-stmt :field_score [:field_id :scores_id :i])
              field-seq-stmt (sequence-stmt "FIELD_IDS")
              scores-seq-stmt (sequence-stmt "SCORES_IDS")
              feature-seq-stmt (sequence-stmt "FEATURE_IDS")]
    (let [feature-seq #(-> (feature-seq-stmt []) first :i)
          field-seq #(-> (field-seq-stmt []) first :i)
          scores-seq #(-> (scores-seq-stmt []) first :i)
          ; XXX try memoization again?
          ;        score-id-fn (memoize-key (comp ahashable first) scores-seq)

