> The fact that the code currently sets the flag when opening the
> connection is an implementation detail. It should not leak into the API

On the contrary – it is important to identify the scope of the connection and 
the scope of when auto-commit is on/off.

> Honestly, I don't care if java.jdbc is reusing an existing connection or
> if it's opening a new connection.

In production code, this is extremely important (and you should care).

And you still haven’t answered my question about whether this code (without 
with-db-connection) works now (with Beta 5):

(into [] (take 2) (jdbc/query db query {:fetch-size 500 :auto-commit? false}))

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

From: Ralf Schmitt
Sent: Thursday, July 6, 2017 2:12 PM
To: Sean Corfield; Clojure Mailing List
Subject: Re: JDBC Connection auto-commit?: [ANN] clojure.java.jdbc 0.7.0 Beta1

Sean Corfield <s...@corfield.org> writes:

> You said:
>
> But when the database is already connected like in
>
>   (jdbc/with-db-connection [db db]
>     (jdbc/query db
>                 query
>                 {:result-set-fn (fn [coll] (doall (take 2 coll)))
>                  :fetch-size 100
>                  :auto-commit? false}))
>
> streaming is not turned on.
>
> Well, of course not: you didn’t tell with-db-connection to do it:
>
>   (jdbc/with-db-connection [db db {:auto-commit? false}]
>     (jdbc/query db
>                 query
>                 {:result-set-fn (fn [coll] (doall (take 2 coll)))
>                  :fetch-size 100 }))

I think the current behaviour is terrible. I'm passing in {:auto-commit?
false}, so please turn off auto commit on the database connection that is
being used. The fact that the code currently sets the flag when opening the
connection is an implementation detail. It should not leak into the API.

Honestly, I don't care if java.jdbc is reusing an existing connection or
if it's opening a new connection. Why should it matter in this case?

I can use jdbc/query with an existing connection or with a map. It
didn't matter until today. Now it surprisingly does.

When using functions that receive a db parameter (which may or may not
have an open connection attached to it), what are you going to do when
you notice that you need streaming? Check if it's using an open
connection and call .setAutoCommit on it, and pass {:auto-commit? false}
if it's a map? Sorry, but then java.jdbc didn't help me in any way
setting up a streaming query.

Instead java.jdbc made things *worse* by ignoring my perfectly fine
looking option (which has been working when I passed in map) and now
tries to burn my laptop with the help from java's garbage collector
before throwing a MemoryError.

> You have to pass the option into the call that would create the connection.

I may not know if (jdbc/query db ...) creates a new connection. I'm not
even sure what db is. But I'm sure I want to run a query with streaming
results. The fact that I have to set an attribute on the connection
object instead of the PreparedStatement is again an implementation
detail. Let me pass the required options for streaming when running the
query, not when opening the connection.

-- 
Cheers
Ralf

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to