<!-- 
RSS generated by JIRA (4.4#649-r158309) at Wed Jun 19 09:51:47 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-38/JDBC-38.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-38] There is no way to execute a raw statement outside a transaction</title>
                <link>http://dev.clojure.org/jira/browse/JDBC-38</link>
                <project id="10021" key="JDBC">java.jdbc</project>
                        <description>&lt;p&gt;To be able to enforce foreign key constraints in SQLite you need to execute the following statement:&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;PRAGMA foreign_keys = ON;&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, this statement can&apos;t be used from within a transaction. From the SQLite docs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is not possible to enable or disable foreign key constraints in the middle of a multi-statement transaction (when SQLite is not in autocommit mode). Attempting to do so does not return an error; it simply has no effect. &lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;In &lt;tt&gt;clojure.java.jdbc&lt;/tt&gt; both &lt;tt&gt;do-commands&lt;/tt&gt; and &lt;tt&gt;do-prepared&lt;/tt&gt; unconditionally run the supplied statements in a transaction. To me it seems like these two functions are the only ones that provide a way to execute an arbitrary SQL statement.&lt;/p&gt;

&lt;p&gt;Example using &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;org.clojure/java.jdbc &amp;quot;0.2.3&amp;quot;&amp;#93;&lt;/span&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;org.xerial/sqlite-jdbc &amp;quot;3.7.2&amp;quot;&amp;#93;&lt;/span&gt;&lt;/tt&gt;:&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;(sql/with-connection {:classname   &lt;span class=&quot;code-quote&quot;&gt;&quot;org.sqlite.JDBC&quot;&lt;/span&gt;
                      :subprotocol &lt;span class=&quot;code-quote&quot;&gt;&quot;sqlite&quot;&lt;/span&gt;
                      :subname     &lt;span class=&quot;code-quote&quot;&gt;&quot;foo.db&quot;&lt;/span&gt;}
  (sql/&lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt;-commands &lt;span class=&quot;code-quote&quot;&gt;&quot;PRAGMA foreign_keys = ON;&quot;&lt;/span&gt;)
  (sql/with-query-results res [&lt;span class=&quot;code-quote&quot;&gt;&quot;PRAGMA foreign_keys;&quot;&lt;/span&gt;]
    (doall res)))
; =&amp;gt; ({:foreign_keys 0})&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When using this function instead of &lt;tt&gt;do-commands&lt;/tt&gt; foreign keys work as expected:&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 &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt;-raw  [&amp;amp; commands]
  (with-open [^java.sql.Statement stmt (let [^java.sql.Connection con (sql/connection)] (.createStatement con))]
    (doseq [^&lt;span class=&quot;code-object&quot;&gt;String&lt;/span&gt; cmd commands]
      (.addBatch stmt cmd))
    (let [result (.executeBatch stmt)]
      (&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (and (= 1 (count result)) (= -2 (first result)))
        (list (.getUpdateCount stmt))
        (seq result)))))&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This function is simply &lt;tt&gt;do-commands&lt;/tt&gt; with &lt;tt&gt;execute-batch&lt;/tt&gt; inlined and the wrapping &lt;tt&gt;transaction&lt;/tt&gt; form removed.&lt;/p&gt;</description>
                <environment>Dependencies used:&lt;br/&gt;
&lt;br/&gt;
[org.clojure/clojure &amp;quot;1.4.0&amp;quot;]&lt;br/&gt;
[org.clojure/java.jdbc &amp;quot;0.2.3&amp;quot;]&lt;br/&gt;
[org.xerial/sqlite-jdbc &amp;quot;3.7.2&amp;quot;]</environment>
            <key id="15627">JDBC-38</key>
            <summary>There is no way to execute a raw statement outside a transaction</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="4" iconUrl="http://dev.clojure.org/jira/images/icons/priority_minor.gif">Minor</priority>
                    <status id="5" iconUrl="http://dev.clojure.org/jira/images/icons/status_resolved.gif">Resolved</status>
                    <resolution id="1">Completed</resolution>
                                <assignee username="seancorfield">Sean Corfield</assignee>
                                <reporter username="raek">Rasmus Svensson</reporter>
                        <labels>
                    </labels>
                <created>Sun, 12 Aug 2012 16:27:56 -0500</created>
                <updated>Thu, 27 Dec 2012 07:03:44 -0600</updated>
                    <resolved>Wed, 26 Dec 2012 16:11:35 -0600</resolved>
                                                                    <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="29121" author="seancorfield" created="Sun, 12 Aug 2012 21:33:41 -0500"  >&lt;p&gt;It seems like the more flexible thing to do would be to allow users to specify that a transaction not be used on the existing operations. I&apos;m reworking the API substantially soon so I&apos;ll bear that in mind. I might not make it possible with the existing API but I&apos;ll make sure that&apos;s an option in the new API that I&apos;m adding.&lt;/p&gt;</comment>
                    <comment id="30327" author="seancorfield" created="Wed, 26 Dec 2012 16:11:35 -0600"  >&lt;p&gt;0.2.4-SNAPSHOT contains db-do-commands which allows bare execution of commands against a specific database connection with or without a transaction wrapping the commands.&lt;/p&gt;</comment>
                    <comment id="30331" author="raek" created="Thu, 27 Dec 2012 07:03:44 -0600"  >&lt;p&gt;Neat! &lt;img class=&quot;emoticon&quot; src=&quot;http://dev.clojure.org/jira/images/icons/emoticons/smile.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>
                </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>
                                                                                                            </customfields>
    </item>
</channel>
</rss>