Just so you don't think I'm ignoring these posts, I'm a bit tied up with work for the next week or so but will dig into your questions when I get a chance and I'd certainly like to make it easier for you to work with Oracle than it appears to be right now (although it would help me a lot if you could explain exactly what _doesn't_ work with c.j.jdbc as-is with Oracle, and why)...
On Tue, Apr 24, 2012 at 8:04 PM, Michael <michael-a...@db.com> wrote: > Would be convenient to have set-parameters public. I'm experimenting with a > couple of fns to insert into oracle and oracle's sequences for generated > keys are a headache. What's below is not fully tested but should give you an > idea of the sql I'm dealing with. Any pointers on how to leaverage java.jdbc > more with less custom code would be appreciated. > > (defn- oracle-insert-sql [table pk-col-name pk-seq-name ks] > (let [cols (apply str (interpose \, (map jdbc/as-identifier ks))) > n (count ks) > qmarks (apply str (interpose \, (repeat n \?)))] > (str "insert into " (jdbc/as-identifier table) > \( (jdbc/as-identifier pk-col-name) \, cols ") values (" > (jdbc/as-identifier pk-seq-name) ".nextval," qmarks \)))) > > (defn oracle-insert-record [table pk-col-name pk-seq-name record] > (let [sql (oracle-insert-sql table pk-col-name pk-seq-name (keys record))] > (with-open [^PreparedStatement pstmt (.prepareStatement > (jdbc/connection) sql, > (into-array > [(jdbc/as-identifier pk-col-name)]))] > (set-parameters pstmt (vals record)) > (jdbc/transaction > (.executeUpdate pstmt) > (vec (ijdbc/resultset-seq* (.getGeneratedKeys pstmt))))))) > > (defn oracle-insert-records [table pk-col-name pk-seq-name & records] > (when-let [record (first records)] > (let [ks (keys record) > sql (oracle-insert-sql table pk-col-name pk-seq-name (keys > record)) > value-groups (map #(map (partial get %) ks) records)] > (apply jdbc/do-prepared sql value-groups)))) > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en