LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
284 stars 39 forks source link

possible bug with open-global #105

Closed kevinludwig closed 12 years ago

kevinludwig commented 13 years ago

I've documented my problem here: http://stackoverflow.com/questions/7178295/clojureql-open-global-and-with-results

To briefly repeat, open-global behavior is different when I use deref vs when I use with-results. It seems that open-global works as expected for with-results but does not work when using deref. Sample code:

My project.clj for dependency info:

(defproject test-project "0.1" :description "Noob clojure project" :dependencies [ [org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"] [compojure "0.6.4"] [hiccup "0.3.4"] [clojureql "1.0.0"] ; [sqlitejdbc "0.5.6"] [com.h2database/h2 "1.2.147"] [ring/ring "0.2.5"] ] :dev-dependencies [ [lein-ring "0.4.5"] ] :ring {:handler routes/start})

The unit test file:

(ns test_db (:require [clojureql.core :as cql]) (:require [clojure.contrib.sql :as sql]) (:use clojure.test))

(def cxn {:classname "org.h2.Driver" :subprotocol "h2" :subname "tmp/testdb" :user "sa" :pass ""})

(cql/open-global cxn)

(use-fixtures :each with-db)

; remove either sq/with-connection OR open-global and this fails (defn get-rec [id](sql/with-connection db/cxn %28first @%28-> %28cql/table :posts%29 %28cql/select %28= :id id%29%29 %28cql/project [:id :title :content]%29%29%29))

; assumes some test content present (deftest test-record-1234 (is (= 1234 (:id (get-rec 1234)))) (is (= "test content" (:content (get-rec 1234)))) (is (= "test title" (:title (get-rec 1234)))))

; this works without sql/with-connection (deftest test-with-results (is (= 1234 (cql/with-results [rs (cql/table :posts)](reduce + 0 %28map %28fn [r] %28:id r%29%29 rs%29)))))

bendlas commented 13 years ago

Can you reproduce this problem on the latest master? That connection code got reworked and I think we haven't had a release in the meantime.

kevinludwig commented 13 years ago

I can try it, but I'm pretty new to clojure...is there a particular version I should drop into the lein dependency?

On Thu, Aug 25, 2011 at 11:38 AM, bendlas < reply@reply.github.com>wrote:

Can you reproduce this problem on the latest master? That connection code got reworked and I think we haven't had a release in the meantime.

Reply to this email directly or view it on GitHub: https://github.com/LauJensen/clojureql/issues/105#issuecomment-1902606

Kevin

bendlas commented 13 years ago

Check out the current master somewhere and install it to your local maven repo

git clone git://github.com/LauJensen/clojureql.git
cd clojureql
lein install

Then use the version number it prints in your project.clj. In this case, it's 1.1.0-SNAPSHOT

bendlas commented 13 years ago

Oh, and the latest released version is 1.0.1, not 1.0.0 btw. There are some important fixes in it, but I think not the new connection code.

LauJensen commented 12 years ago

Assumed fixed