Revised proposal for QUERY DTD



Hi all.

In April 2000 Vivien Malerba sent a proposal to use XML to manipulate queries to this list.
After asking for her agreement, I made some changes and extensions to the DTD. 
I added support for joins, unions and ordering and changed the names of the comparison
operators and some child elements to attributes.
I made this last change because I don't like constructions like <CONST>123</CONST>.
IMO it's more natural to make it an empty tag with an attribute <CONST value="123"/>.

Of course the DTD is not finished now. There should be support for creating, dropping
(changing)? tables, views, sequences, (triggers, stored procedures)?, more support for
subqueries etc. 

Vivien asked me to send the revised DTD to this list for discussion.

Gerhard



<!ELEMENT QUERY (TARGET?, SOURCES?, JOINS*, VALUES, QUALIFICATION?, UNION*, SORT?)>
<!ATTLIST QUERY 
          op (SELECT|INSERT|UPDATE|DELETE) #REQUIRED>

<!ELEMENT TARGET (TABLE|VIEW)*>

<!ELEMENT SOURCES (TABLE|VIEW)*>

<!ELEMENT JOINS (AND|OR|NOT|EQ|NE|LT|LE|GT|GE)*>
<!ATTLIST JOINS
          type (inner|left|right) "inner"
          left IDREF #REQUIRED
          right IDREF #REQUIRED>

<!ELEMENT VALUES (CONST|QUERY|FIELD|FUNC)+>

<!ELEMENT QUALIFICATION (AND|OR|NOT|EQ|NE|LT|LE|GT|GE|NULL|LIKE|
                         BETWEEN|IN|EXISTS)*>

<!ELEMENT UNION (SOURCES, JOINS*, VALUES, QUALIFICATION?)>
<!ATTLIST UNION all (yes|no) #IMPLIED>

<!ELEMENT SORT (COLUMN)+>

<!ELEMENT TABLE EMPTY>
<!ATTLIST TABLE
          id ID #IMPLIED
          name NMTOKEN #REQUIRED
          temp (yes|no) #IMPLIED
          alias NMTOKEN  #IMPLIED>

<!ELEMENT VIEW EMPTY>
<!ATTLIST VIEW
          id ID #IMPLIED
          name NMTOKEN #REQUIRED
          alias NMTOKEN #IMPLIED>

<!ELEMENT CONST EMPTY>
<!ATTLIST CONST
          value CDATA  #REQUIRED
          alias NMTOKEN #IMPLIED>

<!ELEMENT FIELD EMPTY>
<!ATTLIST FIELD
          source IDREF #REQUIRED
          name NMTOKEN #REQUIRED
          alias NMTOKEN  #IMPLIED
          group (yes|no) #IMPLIED>

<!ELEMENT FUNC (FIELD|CONST|FUNC)*>
<!ATTLIST FUNC 
          name NMTOKEN #REQUIRED
          alias NMTOKEN  #IMPLIED>

<!ELEMENT AND (AND|OR|NOT|EQ|NE|LT|LE|GT|GE|NULL|LIKE|BETWEEN|IN|EXISTS)+>

<!ELEMENT OR (AND|OR|NOT|EQ|NE|LT|LE|GT|GE|NULL|LIKE|BETWEEN|IN|EXISTS)+>

<!ELEMENT NOT (AND|OR|NOT|EQ|NE|LT|LE|GT|GE|NULL|LIKE|BETWEEN|IN|EXISTS)>

<!ELEMENT EQ ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT NE ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT LT ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT LE ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT GT ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT GE ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT NULL (CONST|FIELD|FUNC)>

<!ELEMENT LIKE ((CONST|FIELD|FUNC),(CONST|QUERY|FIELD|FUNC))>

<!ELEMENT BETWEEN ((CONST|FIELD|FUNC),(CONST|FIELD|FUNC),(CONST|FIELD|FUNC))>

<!ELEMENT IN (FIELD,QUERY)>

<!ELEMENT EXISTS (QUERY)>

<!ELEMENT COLUMN EMPTY>
<!ATTLIST COLUMN num  CDATA #REQUIRED
                 order (asc|desc) #IMPLIED>

<?xml version="1.0"?>
<!DOCTYPE QUERY SYSTEM "/home/gmd/gnome-db/query.dtd">

<!--
  SELECT t1.a AS aa, v2.b AS bb
    FROM table_t1 t1 INNER JOIN view_v1 v2 ON t1.c < v2.c
   WHERE t1.x BETWEEN 2 AND 4;
  UNION
  SELECT t3.f, v4.g
    FROM table_t2 t3 LEFT JOIN view_v2 v4 ON t3.k = v4.k
   WHERE t3.y = 5
     AND v4.z LIKE 'abc%'
  ORDER BY 2 ASC, 1 DESC;
-->

<QUERY op="SELECT">
  <SOURCES>
    <TABLE id="t1" name="table_t1"/>
    <VIEW  id="v2" name="view_v1"/>
  </SOURCES>
  <JOINS type="inner" left="t1" right="v2">
    <LT>
      <FIELD source="t1" namen="c"/>
      <FIELD source="v2" name="c"/>
    </LT>
  </JOINS>
  <VALUES>
    <FIELD source="t1" name="a" alias="aa"/>
    <FIELD source="v2" name="b" alias="bb"/>
  </VALUES>
  <QUALIFICATION>
    <BETWEEN>
      <FIELD source="t1" name="x"/>
      <CONST value="2"/>
      <CONST value="4"/>
    </BETWEEN>
  </QUALIFICATION>
  <UNION>
    <SOURCES>
      <TABLE id="t3" name="table_t2"/>
      <VIEW  id="v4" name="view_v2"/>
    </SOURCES>
    <JOINS type="left" left="t3" right="v4">
      <EQ>
        <FIELD source="t3" name="k"/>
        <FIELD source="v4" name="k"/>
      </EQ>
    </JOINS>
    <VALUES>
      <FIELD source="t3" name="f"/>
      <FIELD source="v4" name="g"/>
    </VALUES>
    <QUALIFICATION>
      <EQ>
        <FIELD source="t3" name="y"/>
        <CONST value="5"/>
      </EQ>
      <LIKE>
        <FIELD source="v4" name="z"/>
        <CONST value="abc%"/>
      </LIKE>
    </QUALIFICATION>
  </UNION> 
  <SORT>
    <COLUMN num="2" order="asc"/>
    <COLUMN num="1" order="desc"/>
  </SORT>
</QUERY> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]