<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Code based, dynamic CAML query composition</title>
	<atom:link href="http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-composition/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-composition/</link>
	<description>Not anti-anything, just pro-quality</description>
	<lastBuildDate>Tue, 20 Jul 2010 12:45:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Mads Lindstrøm</title>
		<link>http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-composition/comment-page-1/#comment-7728</link>
		<dc:creator>Mads Lindstrøm</dc:creator>
		<pubDate>Sat, 19 Jul 2008 22:51:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-generation/#comment-7728</guid>
		<description>The recursive stuff meant that I could not help myself, I had to try a solution in Haskell:


module Main where

main :: IO()
main = putStrLn (buildWhere [&quot;term1&quot;, &quot;term2&quot;, &quot;term3&quot;, &quot;term4&quot;])

buildWhere :: [String] -&gt; String
buildWhere terms =
    &quot;&lt;Where&gt;&quot; ++ orMany (map eqClause terms) ++ &quot;&lt;/Where&gt;&quot;

type Clause = String

eqClause :: String -&gt; Clause
eqClause term =
    &quot;&lt;Eq&gt;&quot; ++
    &quot;    &lt;FieldRef Name=&#039;MyField&#039; /&gt;&quot; ++
    &quot;    &lt;Value Type=&#039;LookupMulti&#039;&gt;&quot; ++ term ++ &quot;&lt;/Value&gt;&quot; ++
    &quot;&lt;/Eq&gt;&quot;

orClause :: Clause -&gt; Clause -&gt; Clause
orClause left right =
    &quot;&lt;or&gt;&quot; ++ left ++ right ++ &quot;&lt;/or&gt;&quot;

orMany :: [Clause] -&gt; Clause
orMany []     = &quot;&quot;
orMany [x]    = x
orMany (x:xs) = orClause x (orMany xs)

-- More idiomatic Haskell would have replace the last two lines with:
--    orMany (x:xs) = foldl orClause x xs
-- but did not for clarity, as readers may be unfamiliar with Haskell


After pretty printing using another tool I get:


&lt;Where&gt;
  &lt;or&gt;
    &lt;Eq&gt;    &lt;FieldRef Name=&quot;MyField&quot;/&gt;    &lt;Value Type=&quot;LookupMulti&quot;&gt;term1&lt;/Value&gt;&lt;/Eq&gt;
    &lt;or&gt;
      &lt;Eq&gt;    &lt;FieldRef Name=&quot;MyField&quot;/&gt;    &lt;Value Type=&quot;LookupMulti&quot;&gt;term2&lt;/Value&gt;&lt;/Eq&gt;
      &lt;or&gt;
        &lt;Eq&gt;    &lt;FieldRef Name=&quot;MyField&quot;/&gt;    &lt;Value Type=&quot;LookupMulti&quot;&gt;term3&lt;/Value&gt;&lt;/Eq&gt;
        &lt;Eq&gt;    &lt;FieldRef Name=&quot;MyField&quot;/&gt;    &lt;Value Type=&quot;LookupMulti&quot;&gt;term4&lt;/Value&gt;&lt;/Eq&gt;
      &lt;/or&gt;
    &lt;/or&gt;
  &lt;/or&gt;
&lt;/Where&gt;


So who wins? Haskell or C#. It is properly a matter of taste and what you are used to. But to me, the Haskell solution is a lot clearer. It also seperates concerns better. The or-ing together of terms are seperated from building equal-terms. However, C# do shine when it comes to multi-line strings. It do seem strange to me that not all general purpose language has a construct similar to C# multiline stirngs.</description>
		<content:encoded><![CDATA[<p>The recursive stuff meant that I could not help myself, I had to try a solution in Haskell:</p>
<p>module Main where</p>
<p>main :: IO()<br />
main = putStrLn (buildWhere ["term1", "term2", "term3", "term4"])</p>
<p>buildWhere :: [String] -&gt; String<br />
buildWhere terms =<br />
    &#8220;&lt;Where&gt;&#8221; ++ orMany (map eqClause terms) ++ &#8220;&lt;/Where&gt;&#8221;</p>
<p>type Clause = String</p>
<p>eqClause :: String -&gt; Clause<br />
eqClause term =<br />
    &#8220;&lt;Eq&gt;&#8221; ++<br />
    &#8221;    &lt;FieldRef Name=&#8217;MyField&#8217; /&gt;&#8221; ++<br />
    &#8221;    &lt;Value Type=&#8217;LookupMulti&#8217;&gt;&#8221; ++ term ++ &#8220;&lt;/Value&gt;&#8221; ++<br />
    &#8220;&lt;/Eq&gt;&#8221;</p>
<p>orClause :: Clause -&gt; Clause -&gt; Clause<br />
orClause left right =<br />
    &#8220;&lt;or&gt;&#8221; ++ left ++ right ++ &#8220;&lt;/or&gt;&#8221;</p>
<p>orMany :: [Clause] -&gt; Clause<br />
orMany []     = &#8220;&#8221;<br />
orMany [x]    = x<br />
orMany (x:xs) = orClause x (orMany xs)</p>
<p>&#8211; More idiomatic Haskell would have replace the last two lines with:<br />
&#8211;    orMany (x:xs) = foldl orClause x xs<br />
&#8211; but did not for clarity, as readers may be unfamiliar with Haskell</p>
<p>After pretty printing using another tool I get:</p>
<p>&lt;Where&gt;<br />
  &lt;or&gt;<br />
    &lt;Eq&gt;    &lt;FieldRef Name=&#8221;MyField&#8221;/&gt;    &lt;Value Type=&#8221;LookupMulti&#8221;&gt;term1&lt;/Value&gt;&lt;/Eq&gt;<br />
    &lt;or&gt;<br />
      &lt;Eq&gt;    &lt;FieldRef Name=&#8221;MyField&#8221;/&gt;    &lt;Value Type=&#8221;LookupMulti&#8221;&gt;term2&lt;/Value&gt;&lt;/Eq&gt;<br />
      &lt;or&gt;<br />
        &lt;Eq&gt;    &lt;FieldRef Name=&#8221;MyField&#8221;/&gt;    &lt;Value Type=&#8221;LookupMulti&#8221;&gt;term3&lt;/Value&gt;&lt;/Eq&gt;<br />
        &lt;Eq&gt;    &lt;FieldRef Name=&#8221;MyField&#8221;/&gt;    &lt;Value Type=&#8221;LookupMulti&#8221;&gt;term4&lt;/Value&gt;&lt;/Eq&gt;<br />
      &lt;/or&gt;<br />
    &lt;/or&gt;<br />
  &lt;/or&gt;<br />
&lt;/Where&gt;</p>
<p>So who wins? Haskell or C#. It is properly a matter of taste and what you are used to. But to me, the Haskell solution is a lot clearer. It also seperates concerns better. The or-ing together of terms are seperated from building equal-terms. However, C# do shine when it comes to multi-line strings. It do seem strange to me that not all general purpose language has a construct similar to C# multiline stirngs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karine Bosch</title>
		<link>http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-composition/comment-page-1/#comment-7317</link>
		<dc:creator>Karine Bosch</dc:creator>
		<pubDate>Tue, 08 Jul 2008 07:23:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.bugfree.dk/blog/2008/07/03/code-based-dynamic-caml-query-generation/#comment-7317</guid>
		<description>Hi,
I know the documentation on using the CAML Builder dlls are sparse. But can you try to use:
b.AddWhereField(&quot;MyField&quot;, term, &quot;LookupMulti&quot;,
                         &quot;Eq&quot;, out addCombinerNode); 
Normally this should build a correct Where clause.
Kind regards,
Karine Bosch</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I know the documentation on using the CAML Builder dlls are sparse. But can you try to use:<br />
b.AddWhereField(&#8220;MyField&#8221;, term, &#8220;LookupMulti&#8221;,<br />
                         &#8220;Eq&#8221;, out addCombinerNode);<br />
Normally this should build a correct Where clause.<br />
Kind regards,<br />
Karine Bosch</p>
]]></content:encoded>
	</item>
</channel>
</rss>
