Hello all,

I'm attempting to use the SQL library (with the jTDS JDBC driver for
SQL Server) and am running into problem. Specifically, something as
innocuous as

(with-connection db
    (insert-rows :my_table
                 ["foo" "bar" "baz" "16" 0 10 0 "qux" ""]))

throws an exception, java.sql.BatchUpdateException: Parameter #2 has
not been set. (NO_SOURCE_FILE:0).

This is odd, because code that is very similar in the SQL test file
works fine with Derby (I haven't tried with SQL Server). I set some
breakpoints inside the JDBC driver with jswat and looked at calls to
PreparedStatement#setObject and could see that it was getting called
for each position in the prepared statement (internally the SQL
library is generating "insert into my_table values
(?,?,?,?,?,?,?,?,?)"). Then I set a breakpoint in executeBatch and was
surprised to see that the batch about to be executed contained 9
statements (which happens to be the number of parameters)! Looking at
the definition of doPrepared, I looks to me like the body of the doSeq
is calling both #setObject *and* #addBatch --- I think this is a bug.

(defn do-prepared
  "Executes a prepared statement on the open database connection with
  parameter sets"
  [sql & sets]
  (with-open [stmt (.prepareStatement (connection) sql)]
      (doseq [set sets
              [index value] (map vector (iterate inc 1) set)]
          (.setObject stmt index value)
        (.addBatch stmt))
    (.executeBatch stmt)))

The problem, such as it is, is that the Derby embedded driver works
fine. I haven't looked at the Derby code, but I think this is an
accident.

Comments?

Thanks.

    -tree

-- 
Tom Emerson
[EMAIL PROTECTED]
http://www.dreamersrealm.net/~tree

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to