<testdata>
  <!-- table not found -->
  <test id="1">
    <sql valid="f">SELECT id, name FROM customer</sql>
  </test>

  <!-- column ambiguity -->
  <test id="2">
    <sql valid="f">SELECT id FROM customers INNER JOIN salesrep</sql>
  </test>

  <test id="3">
    <sql valid="t">SELECT customers.id FROM customers INNER JOIN salesrep</sql>
  </test>

  <test id="3">
    <sql valid="t">SELECT c.id FROM customers as c INNER JOIN salesrep</sql>
  </test>

  <!-- multiple targets with naming conflicts -->
  <test id="10">
    <sql valid="f">SELECT c.id FROM customers as c INNER JOIN salesrep as c</sql>
  </test>
  <test id="11">
    <sql valid="f">SELECT c.id FROM customers INNER JOIN salesrep as customers</sql>
  </test>
  <test id="11">
    <sql valid="f">SELECT version() FROM customers, customers</sql>
  </test>

  <test id="13">
    <sql valid="t">select p.*, ca.categoryname from products p left join categories ca on (ca.id=p.category)</sql>
  </test>
  <test id="14">
    <sql valid="t">select p.*, ca."categoryname" from products p left join categories ca on (ca.id=p.category)</sql>
  </test>
  <test id="14">
    <sql valid="t">select "p".*, ca."categoryname" from products p left join categories ca on (ca.id=p.category)</sql>
  </test>
  
  <!-- computing DML commands from SELECT -->

  <!-- no target table to modify -->
  <test id="pre0">
    <sql valid="t">SELECT 3</sql>
    <insert/>
    <update/>
    <delete/>
  </test>

  <!-- more than 1 target table to modify -->
  <test id="pre1">
    <sql valid="t">SELECT version() FROM customers, salesrep</sql>
    <insert/>
    <update/>
    <delete/>
  </test>

  <!-- target is not a table -->
  <test id="pre2">
    <sql valid="t">SELECT 123 FROM (SELECT name FROM customers) as c</sql>
    <insert/>
    <update/>
    <delete/>
  </test>

  <!-- target has no primary key -->
  <test id="pre3">
    <sql valid="t">SELECT * FROM sales_orga</sql>
    <normalized>{"statement":{"sql":"SELECT * FROM sales_orga","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"id_salesrep"},"field_name":"id_salesrep"},{"expr":{"value":"id_role"},"field_name":"id_role"},{"expr":{"value":"note"},"field_name":"note"}],"from":{"targets":[{"expr":{"value":"sales_orga"},"table_name":"sales_orga"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"sales_orga","fields":["id_salesrep","id_role","note"],"values":[[{"value":null,"param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+2","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update/>
    <delete/>
  </test>

  <test id="0">
    <sql valid="t">SELECT id, name FROM customers</sql>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["id","name"],"values":[[{"value":"AUTO_INCREMENT","param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":"''","param_spec":{"name":"+1","descr":null,"type":"string","is_param":false,"nullok":false}}]]}}}</insert>
    <update>{"statement":{"sql":null,"stmt_type":"UPDATE","contents":{"table":"customers","fields":["id","name"],"expressions":[{"value":"AUTO_INCREMENT","param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":"''","param_spec":{"name":"+1","descr":null,"type":"string","is_param":false,"nullok":false}}],"condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-0","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</update>
    <delete>{"statement":{"sql":null,"stmt_type":"DELETE","contents":{"table":"customers","condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-0","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</delete>
  </test>

  <test id="0.1">
    <sql valid="t">SELECT id, 3.14, name FROM customers</sql>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["id","name"],"values":[[{"value":"AUTO_INCREMENT","param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":"''","param_spec":{"name":"+2","descr":null,"type":"string","is_param":false,"nullok":false}}]]}}}</insert>
  </test>

  <test id="0.2">
    <sql valid="t">SELECT id, 3.14, name, id FROM customers</sql>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["id","name"],"values":[[{"value":"AUTO_INCREMENT","param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":"''","param_spec":{"name":"+2","descr":null,"type":"string","is_param":false,"nullok":false}}]]}}}</insert>
  </test>

  <test id="0.3">
    <sql valid="t">SELECT id || name FROM customers</sql>
    <insert/>
    <update/>
    <delete/>
  </test>

  <!-- normalization test -->
  <test id="N0">
    <sql valid="t">SELECT count (*) FROM sales_orga</sql>
    <normalized>{"statement":{"sql":"SELECT count (*) FROM sales_orga","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"func":{"function_name":"count","function_args":[{"value":"*"}]}}}],"from":{"targets":[{"expr":{"value":"sales_orga"},"table_name":"sales_orga"}]}}}}</normalized>
    <insert/>
    <update/>
    <delete/>
  </test>

  <test id="N1">
    <sql valid="t">SELECT name, *, city FROM customers</sql>
    <normalized>{"statement":{"sql":"SELECT name, *, city FROM customers","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"name"},"field_name":"name"},{"expr":{"value":"id"},"field_name":"id"},{"expr":{"value":"name"},"field_name":"name"},{"expr":{"value":"default_served_by"},"field_name":"default_served_by"},{"expr":{"value":"country"},"field_name":"country"},{"expr":{"value":"city"},"field_name":"city"},{"expr":{"value":"city"},"field_name":"city"}],"from":{"targets":[{"expr":{"value":"customers"},"table_name":"customers"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["name","id","default_served_by","country","city"],"values":[[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update>{"statement":{"sql":null,"stmt_type":"UPDATE","contents":{"table":"customers","fields":["name","id","default_served_by","country","city"],"expressions":[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}],"condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</update>
    <delete>{"statement":{"sql":null,"stmt_type":"DELETE","contents":{"table":"customers","condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</delete>
  </test>

  <test id="N2">
    <sql valid="t">SELECT s.* FROM sales_orga as s</sql>
    <normalized>{"statement":{"sql":"SELECT s.* FROM sales_orga as s","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"s.id_salesrep"},"field_name":"id_salesrep","table_name":"s"},{"expr":{"value":"s.id_role"},"field_name":"id_role","table_name":"s"},{"expr":{"value":"s.note"},"field_name":"note","table_name":"s"}],"from":{"targets":[{"expr":{"value":"sales_orga"},"table_name":"sales_orga","as":"s"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"sales_orga","fields":["id_salesrep","id_role","note"],"values":[[{"value":null,"param_spec":{"name":"+0","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+2","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update></update>
    <delete></delete>
    <update needpk="f"></update>
    <delete needpk="f"></delete>
  </test>

  <test id="N3">
    <sql valid="t">SELECT "name", c.*, "id" FROM customers as c</sql>
    <normalized>{"statement":{"sql":"SELECT \"name\", c.*, \"id\" FROM customers as c","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"\"name\""},"field_name":"\"name\""},{"expr":{"value":"c.id"},"field_name":"id","table_name":"c"},{"expr":{"value":"c.name"},"field_name":"name","table_name":"c"},{"expr":{"value":"c.default_served_by"},"field_name":"default_served_by","table_name":"c"},{"expr":{"value":"c.country"},"field_name":"country","table_name":"c"},{"expr":{"value":"c.city"},"field_name":"city","table_name":"c"},{"expr":{"value":"\"id\""},"field_name":"\"id\""}],"from":{"targets":[{"expr":{"value":"customers"},"table_name":"customers","as":"c"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["\"name\"","id","default_served_by","country","city"],"values":[[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update>{"statement":{"sql":null,"stmt_type":"UPDATE","contents":{"table":"customers","fields":["\"name\"","id","default_served_by","country","city"],"expressions":[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}],"condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</update>
    <delete>{"statement":{"sql":null,"stmt_type":"DELETE","contents":{"table":"customers","condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</delete>
  </test>

  <test id="N4">
    <sql valid="t">SELECT "name", "customers".*, "id" FROM customers as c</sql>
    <normalized>{"statement":{"sql":"SELECT \"name\", \"customers\".*, \"id\" FROM customers as c","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"\"name\""},"field_name":"\"name\""},{"expr":{"value":"\"customers\".id"},"field_name":"id","table_name":"\"customers\""},{"expr":{"value":"\"customers\".name"},"field_name":"name","table_name":"\"customers\""},{"expr":{"value":"\"customers\".default_served_by"},"field_name":"default_served_by","table_name":"\"customers\""},{"expr":{"value":"\"customers\".country"},"field_name":"country","table_name":"\"customers\""},{"expr":{"value":"\"customers\".city"},"field_name":"city","table_name":"\"customers\""},{"expr":{"value":"\"id\""},"field_name":"\"id\""}],"from":{"targets":[{"expr":{"value":"customers"},"table_name":"customers","as":"c"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["\"name\"","id","default_served_by","country","city"],"values":[[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update>{"statement":{"sql":null,"stmt_type":"UPDATE","contents":{"table":"customers","fields":["\"name\"","id","default_served_by","country","city"],"expressions":[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}],"condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</update>
    <delete>{"statement":{"sql":null,"stmt_type":"DELETE","contents":{"table":"customers","condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</delete>
  </test>

  <test id="N5">
    <sql valid="t">SELECT NaMe, c."*", ID FROM customers as c</sql>
    <normalized>{"statement":{"sql":"SELECT NaMe, c.\"*\", ID FROM customers as c","stmt_type":"SELECT","contents":{"distinct":"false","fields":[{"expr":{"value":"NaMe"},"field_name":"NaMe"},{"expr":{"value":"c.id"},"field_name":"id","table_name":"c"},{"expr":{"value":"c.name"},"field_name":"name","table_name":"c"},{"expr":{"value":"c.default_served_by"},"field_name":"default_served_by","table_name":"c"},{"expr":{"value":"c.country"},"field_name":"country","table_name":"c"},{"expr":{"value":"c.city"},"field_name":"city","table_name":"c"},{"expr":{"value":"ID"},"field_name":"ID"}],"from":{"targets":[{"expr":{"value":"customers"},"table_name":"customers","as":"c"}]}}}}</normalized>
    <insert>{"statement":{"sql":null,"stmt_type":"INSERT","contents":{"table":"customers","fields":["NaMe","id","default_served_by","country","city"],"values":[[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}]]}}}</insert>
    <update>{"statement":{"sql":null,"stmt_type":"UPDATE","contents":{"table":"customers","fields":["NaMe","id","default_served_by","country","city"],"expressions":[{"value":"''","param_spec":{"name":"+0","descr":null,"type":"string","is_param":false,"nullok":false}},{"value":"AUTO_INCREMENT","param_spec":{"name":"+1","descr":null,"type":"int","is_param":false,"nullok":false}},{"value":null,"param_spec":{"name":"+3","descr":null,"type":"int","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+4","descr":null,"type":"string","is_param":false,"nullok":true}},{"value":null,"param_spec":{"name":"+5","descr":null,"type":"string","is_param":false,"nullok":true}}],"condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</update>
    <delete>{"statement":{"sql":null,"stmt_type":"DELETE","contents":{"table":"customers","condition":{"operation":{"operator":"=","operand0":{"value":"id"},"operand1":{"value":null,"param_spec":{"name":"-1","descr":null,"type":"int","is_param":false,"nullok":false}}}}}}}</delete>
  </test>

</testdata>
