Home RSS 2.0 ATOM 1.0  CDF  
 
CodeSegment - Carlos Segura Sanz (blog)
 

Continuing with the YACAMLQT, I have finished the first version. Now the "toy" tool supports, "group by" and "order by", and some expression errors are now fixed. In order to not increase the complexity of the lexer part, the clause "group by" must be write like "groupby" and the "order by" clause as "orderby".

To support this new clauses the first expression must begin with a "where" clause. The syntax is:

[WHERE boolean_expression] [GROUPBY field_list] [ORDERBY field_list]

A CAML complex query written in sql mode can look as:

WHERE ((Column1 = "Value1") AND (Column2 = "Value2")) OR ((Column3 = 10)
AND (Column3 <> NULL)) GROUPBY Column1 ORDERBY Column1, Column2 ASC, Column3 DESC

Also, you can use ==  for equal and != for not equal  and && for and, or, || for or (it's a c# goodie)

The CAML result code

<Query>
  <Where>
    <Or>
      <And>
        <Eq>
          <FieldRef Name="Column1" />
          <Value Type="Text">Value1</Value>
        </Eq>
        <Eq>
          <FieldRef Name="Column2" />
          <Value Type="Text">Value2</Value>
        </Eq>
      </And>
      <And>
        <Eq>
          <FieldRef Name="Column3" />
          <Value Type="Integer">10</Value>
        </Eq>
        <IsNotNull>
          <FieldRef Name="Column3" />
        </IsNotNull>
      </And>
    </Or>
  </Where>
  <GroupBy>
    <FieldRef Name="Column1" />
  </GroupBy>
  <OrderBy>
    <FieldRef Name="Column1" />
    <FieldRef Name="Column2" Ascending="True" />
    <FieldRef Name="Column3" Ascending="False" />
  </OrderBy>
</Query>

 

Also you can add the assembly (IdeSeg.SharePoint.Caml.QueryParse) in your projects

using IdeSeg.SharePoint.Caml.ParseQuery;
 
string query = "where Campo1=10 && campo2=\"Test\" and campo3=#01/01/2007# order Campo3";
try
{
    string xmlQuery = CAMLParser.Query(query);        
}
catch (ParserException ex)
{
    statusError = ex.Message;
}       

Internally the code use a Parser to generate an AST and a Lexer to scan the query, they do the hard work you can see the UML class diagrams below: 

Finally in the winforms application there is also a c# generator to do copy and paste. Enjoy!!!!!

 YACAMLQT.zip

(File Updated December 9, 2007)

Thursday, July 12, 2007 1:42:16 PM (Hora de verano romance, UTC+02:00)
Thanks a lot. I was toying with the idea of doing just that.

I even bloged about it:

http://maurosjungle.spaces.live.com/blog/cns!F3CEB0849B03B6CC!299.entry

Mauro Sant'Anna
MVP, RD
Tuesday, August 07, 2007 4:39:18 PM (Hora de verano romance, UTC+02:00)
Hi Carlos

I downloaded the tool and run but with no luck, may be I am missing something. This is the english query I have and I am looking to write CAML query.

((Proj Sts == "1 Const") OR (Proj Sts == "1.5 P-Sale") OR (Proj Sts == "2 BP") OR (Proj Sts == "3 Ent") OR (Proj Sts == "4 Feas")) AND ((Territory == "N") OR (Territory == "S") OR (Territory == "W"))


Any help is greatly appreciated.

Thanks
Kalpana
Kalpana Rajan
Comments are closed.

Copyright © 2008 Carlos Segura. All rights reserved.