<!-- 
RSS generated by JIRA (4.4#649-r158309) at Wed Jun 19 04:06:07 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/JDBC-40/JDBC-40.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[JDBC-40] insert nulls using .setNull (e.g. for Teradata)</title>
                <link>http://dev.clojure.org/jira/browse/JDBC-40</link>
                <project id="10021" key="JDBC">java.jdbc</project>
                        <description>&lt;p&gt;Hi, I am using this nice package with a large (government) Teradata machine. I found that I can not insert nil values using &lt;tt&gt;insert-rows&lt;/tt&gt;: the Teradata JDBC driver tells me to use &lt;tt&gt;.setNull&lt;/tt&gt; or the form of &lt;tt&gt;.setObject&lt;/tt&gt; including an SQL type code.&lt;/p&gt;

&lt;p&gt;The following replacement definition of &lt;tt&gt;set-parameters&lt;/tt&gt; was the only change needed to get this to work.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;(defn- set-parameters
  &lt;span class=&quot;code-quote&quot;&gt;&quot;Add the parameters to the given statement.&quot;&lt;/span&gt;
  [^PreparedStatement stmt params]
  (let [pmd (.getParameterMetaData stmt)]
    (dorun
     (map-indexed
      (fn [ix value]
        (let [typ (.getParameterType pmd (inc ix))]
          (&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (nil? value)
            (.setNull stmt (inc ix) typ)
            (.setObject stmt (inc ix) value typ))))
      params))))&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I am not sure whether the use of &lt;tt&gt;.getParameterMetaData&lt;/tt&gt; is a generally appropriate because the docs &lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/java/sql/ParameterMetaData.html&quot;&gt;http://docs.oracle.com/javase/7/docs/api/java/sql/ParameterMetaData.html&lt;/a&gt; say:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For some queries and driver implementations, the data that would be returned by a ParameterMetaData object may not be available until the PreparedStatement has been executed.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Anyway it does work for Teradata. Maybe it could be an option?&lt;/p&gt;


&lt;p&gt;It just occurred to me that it is probably inefficient to retrieve the parameter metadata on every call to &lt;tt&gt;set-parameters&lt;/tt&gt;. It could be done in &lt;tt&gt;insert-rows&lt;/tt&gt; instead. On the other hand, I didn&apos;t actually notice any performance hit when inserting 40,000 rows.&lt;/p&gt;</description>
                <environment>Teradata 14</environment>
            <key id="15746">JDBC-40</key>
            <summary>insert nulls using .setNull (e.g. for Teradata)</summary>
                <type id="4" iconUrl="http://dev.clojure.org/jira/images/icons/improvement.gif">Enhancement</type>
                                <priority id="3" iconUrl="http://dev.clojure.org/jira/images/icons/priority_major.gif">Major</priority>
                    <status id="4" iconUrl="http://dev.clojure.org/jira/images/icons/status_reopened.gif">Reopened</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="seancorfield">Sean Corfield</assignee>
                                <reporter username="floybix">Felix Andrews</reporter>
                        <labels>
                    </labels>
                <created>Fri, 12 Oct 2012 06:07:37 -0500</created>
                <updated>Mon, 22 Apr 2013 04:26:18 -0500</updated>
                                                                            <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="30893" author="seancorfield" created="Sun, 7 Apr 2013 01:07:33 -0500"  >&lt;p&gt;This was a tricky one. Both .getParameterMetadataData and .getParameterType can throw exceptions. On MS SQL Server, if there is a syntax error in the SQL, the former throws an Exception. On MySQL, the latter throws an exception (every time as far as I can tell, even tho&apos; .getParameterMetaData succeeds). That introduces quite a performance penalty for MySQL (about 10% in my tests).&lt;/p&gt;

&lt;p&gt;However, if I treated MySQL as a special case and swallowed all exceptions and had a fallback to the original .setObject call, I could get everything to pass the test suite without a noticeable performance overhead (still measuring the latest MySQL performance as I write this).&lt;/p&gt;

&lt;p&gt;Although it will probably slow everyone down a little, having to make these calls, it should be more robust and may make the .setObject calls faster in some situations?&lt;/p&gt;</comment>
                    <comment id="30894" author="seancorfield" created="Sun, 7 Apr 2013 01:24:32 -0500"  >&lt;p&gt;Fixed in 0.3.0-SNAPSHOT. May need to be revisited for performance tweaks later. Uncomfortable with MySQL being a special case here... &lt;img class=&quot;emoticon&quot; src=&quot;http://dev.clojure.org/jira/images/icons/emoticons/sad.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="30965" author="seancorfield" created="Wed, 17 Apr 2013 18:48:14 -0500"  >&lt;p&gt;This fix breaks PostgreSQL and already has MySQL as an exception so I&apos;m going to roll it back and we&apos;ll have to find another way to support Teradata I&apos;m afraid!).&lt;/p&gt;</comment>
                    <comment id="30981" author="pmoriarty" created="Mon, 22 Apr 2013 04:26:18 -0500"  >&lt;p&gt;PostgreSQL also complains about use of setObject with a null object and no parameter type when using protocolVersion 3. &lt;/p&gt;

&lt;p&gt;Seems to work ok with protocolVersion 2 though.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                            <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                <customfieldname>Patch</customfieldname>
                <customfieldvalues>
                        <customfieldvalue key="10001">Code</customfieldvalue>

                </customfieldvalues>
            </customfield>
                                                                                        </customfields>
    </item>
</channel>
</rss>