4

I'm new to Clojure and building a web app using the Noir framework (very similar to Compojure, in fact I think it's Compojure with a different request handler layer). I'm getting a warning when I import the JDBC library:

WARNING: resultset-seq already refers to: #'clojure.core/resultset-seq in namespace: webapp.models.database, being replaced by: #'clojure.java.jdbc/resultset-seq

Do I have to live with this warning or is there a way around it? I'm importing the JDBC library using:

(use 'clojure.java.jdbc)
animuson
  • 53,861
  • 28
  • 137
  • 147
Adam
  • 3,063
  • 5
  • 35
  • 49

3 Answers3

9

You can avoid the problem by specifying the exact bindings to be imported:

(use '[clojure.java.jdbc :only [insert-values transaction]])
(transaction
  (insert-values ...))

Another option is to :exclude the offending binding:

(use '[clojure.java.jdbc :exclude [resultset-seq]])
(transaction
  (insert-values ...))

You can also just use require instead:

(require '[clojure.java.jdbc :as db])
(db/transaction
  (db/insert-values ...))

With regard to forward compatibility, require is arguably safest. Using :only is just slightly less clean but still a pretty good approach (and easy to fix when it breaks). Excluding the currently offending bindings is probably the least future-proof way of fixing the problem since other conflicting bindings can appear at any time and tracking down what is imported from where can be tricky.

Matthias Benkard
  • 15,497
  • 4
  • 39
  • 47
  • Thanks! I'll try that out. If I end up going with the ":only" approach will it affect the result set returned by queries? – Adam Nov 22 '11 at 21:42
  • 1
    @Adam As long as you don't actually refer to `resultset-seq` explicitly anywhere, it shouldn't matter. In theory, it is conceivable that one of `clojure.java.jdbc`'s macros expands into something that refers to `resultset-seq` in a referentially non-transparent way, but it's unlikely (and even then, I would consider it a bug). – Matthias Benkard Nov 22 '11 at 21:57
3

There are lots of options. What this warning means is, that you are replacing an already defined symbol with a definition from different package. In this case, it looks like this is a variable that you've defined, right? If so the easiest solution might be to just rename it in your code.

Or if you don't need the resultset-seq from clojure.java.jdbc package you can exclude it:

(use '[clojure.java.jdbc :exclude (resultset-seq)])

or better yet,

(use '[clojure.java.jdbc :only (f1 f2 f3)])

where f1, f2, f3 are the things you're actually need.

(use '[clojure.java.jdbc :as jdbc])

and then use jdbc/resultset-seq

Or you can just:

(require 'clojure.java.jdbc)

and then use clojure.java.jdbc/reusltset-seq

ivant
  • 3,909
  • 1
  • 25
  • 39
3

In addition to the other excellent answers, if you want the jdbc resultset-seq instead of the core one, you can exclude the latter from being brought into the current ns:

(ns foo
  (:refer-clojure :exclude [resultset-seq])
  (:use clojure.java.jdbc))
Alex Taggart
  • 7,805
  • 28
  • 31