assertEquals("select \"TABLE1\".\"ID1\", \"TABLE1\".\"NAME1\", \"TABLE1\".\"DATE1\" from \"TABLE1\" where exists (select \"TABLE2\".\"ID2\" from \"TABLE2\")", r_ref().render(q1));
}
@Test
public void testNamedParams() throws Exception {
Query q1 = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(val(2)));
Query q2 = create.select(param("p1", 1)).from(TABLE1).where(FIELD_ID1.equal(param("p2", 2)));
Query q3 = create.select(param("p1", 1)).from(TABLE1).where(FIELD_ID1.equal(2));
Query q4 = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(param("p2", 2)));
assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q1));
assertEquals("select :1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :2", r_refP().render(q1));
assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q1));
assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q2));
assertEquals("select :p1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :p2", r_refP().render(q2));
assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q2));
assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q3));
assertEquals("select :p1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :2", r_refP().render(q3));
assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q3));
assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q4));
assertEquals("select :1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :p2", r_refP().render(q4));
assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q4));
// Param / Val queries should be equal as toString() doesn't consider params
assertEquals(q1, q2);
assertEquals(q1, q3);
assertEquals(q1, q4);
// Params
Param<?> p11 = q1.getParam("1");
Param<?> p21 = q2.getParam("p1");
Param<?> p31 = q3.getParam("p1");
Param<?> p41 = q4.getParam("1");
Param<?> p12 = q1.getParam("2");
Param<?> p22 = q2.getParam("p2");
Param<?> p32 = q3.getParam("2");
Param<?> p42 = q4.getParam("p2");
assertEquals(Arrays.asList("1", "2"), new ArrayList<String>(q1.getParams().keySet()));
assertEquals(Arrays.asList("p1", "p2"), new ArrayList<String>(q2.getParams().keySet()));
assertEquals(Arrays.asList("p1", "2"), new ArrayList<String>(q3.getParams().keySet()));
assertEquals(Arrays.asList("1", "p2"), new ArrayList<String>(q4.getParams().keySet()));
// Types
assertEquals(Integer.class, p11.getType());
assertEquals(Integer.class, p21.getType());
assertEquals(Integer.class, p31.getType());