<?xml version="1.0"?>

<sqlgg>
 <stmt name="create_test" sql="CREATE TABLE IF NOT EXISTS `test` (&#x0A;  `id` INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT,&#x0A;  `nullable` TIMESTAMP NULL,&#x0A;  `nullable_too` TIMESTAMP DEFAULT NULL,&#x0A;  `nullable_int` INTEGER NULL&#x0A;)" category="DDL" kind="create" target="test" cardinality="0">
  <in/>
  <out/>
 </stmt>
 <stmt name="insert1" sql="INSERT INTO `test` SET&#x0A;  `nullable` = CASE @maybe WHEN 0 THEN NULL ELSE @maybe END&#x0A;" category="DML" kind="insert" target="test" cardinality="0">
  <in>
   <value name="maybe" type="Int" nullable="true"/>
  </in>
  <out/>
 </stmt>
 <stmt name="insert2" sql="INSERT INTO `test` SET `nullable` = NULLIF(@maybe, 0)" category="DML" kind="insert" target="test" cardinality="0">
  <in>
   <value name="maybe" type="Int"/>
  </in>
  <out/>
 </stmt>
 <stmt name="list" sql="SELECT `id`, IFNULL(`nullable`, 0) `nullable` FROM `test`" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="id" type="Int"/>
   <value name="nullable" type="Int"/>
  </out>
 </stmt>
 <stmt name="insert_nullable" sql="INSERT INTO `test` SET `nullable` = @maybe" category="DML" kind="insert" target="test" cardinality="0">
  <in>
   <value name="maybe" type="Datetime" nullable="true"/>
  </in>
  <out/>
 </stmt>
 <stmt name="insert_all" sql="INSERT INTO test VALUES (@id,@nullable,@nullable_too,@nullable_int)" category="DML" kind="insert" target="test" cardinality="0">
  <in>
   <value name="id" type="Int" nullable="true"/>
   <value name="nullable" type="Datetime" nullable="true"/>
   <value name="nullable_too" type="Datetime" nullable="true"/>
   <value name="nullable_int" type="Int" nullable="true"/>
  </in>
  <out/>
 </stmt>
 <stmt name="list_nullable" sql="SELECT `id`, `nullable` FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="id" type="Int"/>
   <value name="nullable" type="Datetime" nullable="true"/>
  </out>
 </stmt>
 <stmt name="case_BUG" sql="SELECT CASE @x WHEN 0 THEN NULL ELSE @x END" category="DQL" kind="select" cardinality="1">
  <in>
   <value name="x" type="Int" nullable="true"/>
  </in>
  <out>
   <value name="_0" type="Any" nullable="true"/>
  </out>
 </stmt>
 <stmt name="select_nullif_BUG" sql="SELECT NULLIF(@maybe, 0)" category="DQL" kind="select" cardinality="1">
  <in>
   <value name="maybe" type="Int"/>
  </in>
  <out>
   <value name="_0" type="Int"/>
  </out>
 </stmt>
 <stmt name="select_ifnull" sql="SELECT IFNULL(@maybe, 0)" category="DQL" kind="select" cardinality="1">
  <in>
   <value name="maybe" type="Any"/>
  </in>
  <out>
   <value name="_0" type="Int"/>
  </out>
 </stmt>
 <stmt name="select_ifnull_int" sql="SELECT IFNULL(nullable_int, 0) FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="_0" type="Int"/>
  </out>
 </stmt>
 <stmt name="select_plus" sql="SELECT id + IFNULL(nullable_int, 0) FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="_0" type="Int"/>
  </out>
 </stmt>
 <stmt name="select_plus_null" sql="SELECT id + NULL FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="_0" type="Int" nullable="true"/>
  </out>
 </stmt>
 <stmt name="select_plus_nullable_BUG" sql="SELECT id + nullable_int FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="_0" type="Int" nullable="true"/>
  </out>
 </stmt>
 <stmt name="select_func" sql="SELECT nullable, floor(unix_timestamp(nullable)/3600) FROM test" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="nullable" type="Datetime" nullable="true"/>
   <value name="_1" type="Int"/>
  </out>
 </stmt>
 <stmt name="get_max" sql="SELECT&#x0A;  max(nullable),&#x0A;  max(id),&#x0A;  IF(max(nullable) IS NULL, now(), max(nullable)),&#x0A;  IF(max(nullable) IS NULL, NULL, max(nullable))&#x0A;FROM&#x0A;  test&#x0A;WHERE&#x0A;  id = @id&#x0A;LIMIT 1" category="DQL" kind="select" cardinality="1">
  <in>
   <value name="id" type="Int"/>
  </in>
  <out>
   <value name="_0" type="Datetime" nullable="true"/>
   <value name="_1" type="Int" nullable="true"/>
   <value name="_2" type="Datetime" nullable="true"/>
   <value name="_3" type="Datetime" nullable="true"/>
  </out>
 </stmt>
 <stmt name="params_unification" sql="INSERT INTO test (&#x0A;  nullable,&#x0A;  nullable_too&#x0A;) VALUES (&#x0A;  @p,&#x0A;  case when @p = 42 then 100 else NULL end&#x0A;)" category="DML" kind="insert" target="test" cardinality="0">
  <in>
   <value name="p" type="Int" nullable="true"/>
  </in>
  <out/>
 </stmt>
 <stmt name="create_tests" sql="CREATE TABLE tests(test_id INT UNSIGNED, run_id INTEGER UNSIGNED, started_at DATETIME NOT NULL, finished_at DATETIME NOT NULL)" category="DDL" kind="create" target="tests" cardinality="0">
  <in/>
  <out/>
 </stmt>
 <stmt name="select_18" sql="SELECT&#x0A;  test.id,&#x0A;  started_at,&#x0A;  finished_at,&#x0A;  last_test.started_at as started_at_should_be_nullable,&#x0A;  last_test.finished_at as finished_at_should_be_nullable&#x0A;FROM test&#x0A;LEFT JOIN (&#x0A;  SELECT test_id, started_at, finished_at&#x0A;  FROM tests aux&#x0A;  WHERE run_id = (SELECT MAX(run_id) FROM tests WHERE aux.test_id = test_id)&#x0A;) last_test ON last_test.test_id = test.id&#x0A;WHERE&#x0A;  test.nullable_int = @x" category="DQL" kind="select" cardinality="n">
  <in>
   <value name="x" type="Int"/>
  </in>
  <out>
   <value name="id" type="Int"/>
   <value name="started_at" type="Datetime" nullable="true"/>
   <value name="finished_at" type="Datetime" nullable="true"/>
   <value name="started_at_should_be_nullable" type="Datetime" nullable="true"/>
   <value name="finished_at_should_be_nullable" type="Datetime" nullable="true"/>
  </out>
 </stmt>
 <table name="tests">
  <schema>
   <value name="test_id" type="Int" nullable="true"/>
   <value name="run_id" type="Int" nullable="true"/>
   <value name="started_at" type="Datetime"/>
   <value name="finished_at" type="Datetime"/>
  </schema>
 </table>
 <table name="test">
  <schema>
   <value name="id" type="Int"/>
   <value name="nullable" type="Datetime" nullable="true"/>
   <value name="nullable_too" type="Datetime" nullable="true"/>
   <value name="nullable_int" type="Int" nullable="true"/>
  </schema>
 </table>
</sqlgg>
