tags:

views:

52

answers:

1

I have a SQL SELECT Statement:

SELECT Code, Description
  FROM Table1
 WHERE (Code='a' and Amount>100) or (Code='b' and Amount<100)

I wish to use XML to present the SELECT statement. Here is my initial design:

<select table="Table1">
    <columns>
        <column name="Code"/>
        <column name="Description"/>
    </columns>
    <filters>
    <or>
      <and>
        <filter field="Code" cond="eq" value="a"/>
        <filter field="Amount" cond="gt" value="100"/>
      </and>
      <and>
        <filter field="Code" cond="eq" value="b"/>
        <filter field="Amount" cond="lt" value="100"/>
      </and>
    </or>       
    </filters>
</select>

However, I am not satisfy with it. It is much more complicated to find a XSD for SQL SELECT statement. They are many features in SQL SELECT statement that I haven't included, e.g.: Aggregates, Inner/Outer Join, Between, IN, Sub Select and etc.

It is beyond my capabilities to design such schema. Does anyone know if there is such XSD to for SQL Select statement presentation?

+2  A: 

I wish to use XML to present the SELECT statement.

But do you have to use XML? If you don't then you should not, because using XML as a definition for a programming language is a truly awful idea. Even XML doesn't use XML for implementing it's own query language!

If you need to define a programming language, then you should use a formal grammar. Antlr is a tool that can be used for defining such grammars.

if your job depends on using XML, and your wife and kids will starve if you get fired, then I would reluctantly concede that you should continue down this path, otherwise STOP NOW!

Don
+1 Women and children before Antlr
AJ
I don't think it is an awful idea using xml in programming language. In Delphi, I can generate xml document class from XSD. I am not going to parse SQL but I just looking for XSD that able to present an SQL Select statement. From there, I may use XSLT to generate a SQL statement if I want to query from database. Or I can create a SQL editor that help me form the SQL select statement programmatically.
Chau Chee Yang
@Chau Chee Yang: Maybe you should check out open source projects developing SQL editors ... there might be some using xsd schema.
Filburt