                (<= post-time (.getTime (java.util.Date.)))
                edit-time
                (<= edit-time (.getTime (java.util.Date.))))
-      (jdbc/with-connection
+      (update-or-insert!
         @spec
-        (jdbc/update-or-insert-values
-          :post
-          ["userhash = ? AND time = ?" user-hash post-time]
-          {:realuserhash user-hash 
-           :userhash user-hash
-           :body (f/b-decode-string (get args "body"))
-           :time post-time
-           :mtime edit-time
-           :pichash (f/b-decode-bytes (get pics 0))
-           :count (count pics)
-           :ptrhash (f/b-decode-bytes (get args "ptrhash"))
-           :ptrtime (f/b-decode-long (get args "ptrtime"))
-           :status (f/b-decode-long (get args "status"))})))))
+        :post
+        {:realuserhash user-hash 
+         :userhash user-hash
+         :body (f/b-decode-string (get args "body"))
+         :time post-time
+         :mtime edit-time
+         :pichash (f/b-decode-bytes (get pics 0))
+         :count (count pics)
+         :ptrhash (f/b-decode-bytes (get args "ptrhash"))
+         :ptrtime (f/b-decode-long (get args "ptrtime"))
+         :status (f/b-decode-long (get args "status"))}
+        ["userhash = ? AND time = ?" user-hash post-time]))))
 
 (defn insert-fav
   [user-hash fav-time args]

                           LIMIT 1" tag]
                    nil)]
    (when statement
      (jdbc/with-connection
        @spec
        (jdbc/with-query-results
          rs
          statement
          (first (prepare-results rs :tag)))))))

(defn get-pic-data
  ([params]
   (let [user-hash (:userhash params)
         pic-hash (:pichash params)]
     (jdbc/with-connection
       @spec
       (jdbc/with-query-results
         rs
         ["SELECT * FROM pic WHERE userhash = ? AND pichash = ?"
          user-hash pic-hash]
         (prepare-results rs :pic)))))
  ([params ptr-time paginate?]
   (let [user-hash (:userhash params)
         page (:page params)]
     (jdbc/with-connection
       @spec
       (jdbc/with-query-results
         rs
         [(let [sql "SELECT * FROM pic WHERE userhash = ? AND ptrtime IS ?"]
            (if paginate? (paginate page sql) sql))
          user-hash ptr-time]
         (prepare-results rs :pic))))))

; insertion / removal


    [:ptrtime "BIGINT"]
    [:status "BIGINT"]))

(defn create-index
  [table-name columns]
  ["CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\";"
   "CALL FT_INIT();"
   (format "CALL FT_CREATE_INDEX('PUBLIC', '%s', '%s');"
           table-name (clojure.string/join "," columns))])

(defn create-tables
  []
  (when-not (check-table :user)
    (apply jdbc/db-do-commands
           (concat [@spec true (create-generic-table :user)]
                   (create-index "USER" ["ID" "TITLE" "BODY"]))))
  (when-not (check-table :post)
    (apply jdbc/db-do-commands
           (concat [@spec true (create-generic-table :post)]
                   (create-index "POST" ["ID" "TITLE" "BODY"]))))
  (when-not (check-table :pic)
    (jdbc/db-do-commands
      @spec
      true
      (create-generic-table :pic)))
  (when-not (check-table :fav)
    (jdbc/db-do-commands
      @spec
      true
      (create-generic-table :fav)))
  (when-not (check-table :tag)
    (jdbc/db-do-commands
      @spec
      true
      (create-generic-table :tag))))

(defn init-db
