@Test
public void testWherePlacholder() {
Session session = new SessionImpl(new HashMap<String, String>(), null, null, null);
String query;
QueryStatement st;
// strings
query = "SELECT * FROM cmis:document WHERE abc:string = ?";
st = new QueryStatementImpl(session, query);
st.setString(1, "test");
assertEquals("SELECT * FROM cmis:document WHERE abc:string = 'test'", st.toQueryString());
query = "SELECT * FROM cmis:document WHERE abc:string = ?";
st = new QueryStatementImpl(session, query);
st.setString(1, "te'st");
assertEquals("SELECT * FROM cmis:document WHERE abc:string = 'te\\'st'", st.toQueryString());
// likes
query = "SELECT * FROM cmis:document WHERE abc:string LIKE ?";
st = new QueryStatementImpl(session, query);
st.setStringLike(1, "%test%");
assertEquals("SELECT * FROM cmis:document WHERE abc:string LIKE '%test%'", st.toQueryString());
query = "SELECT * FROM cmis:document WHERE abc:string LIKE ?";
st = new QueryStatementImpl(session, query);
st.setStringLike(1, "\\_test\\%blah\\\\blah");
assertEquals("SELECT * FROM cmis:document WHERE abc:string LIKE '\\_test\\%blah\\\\\\\\blah'",
st.toQueryString());
// ids
query = "SELECT * FROM cmis:document WHERE abc:id = ?";
st = new QueryStatementImpl(session, query);
st.setId(1, new ObjectIdImpl("123"));
assertEquals("SELECT * FROM cmis:document WHERE abc:id = '123'", st.toQueryString());
// booleans
query = "SELECT * FROM cmis:document WHERE abc:bool = ?";
st = new QueryStatementImpl(session, query);
st.setBoolean(1, true);
assertEquals("SELECT * FROM cmis:document WHERE abc:bool = TRUE", st.toQueryString());
// numbers
query = "SELECT * FROM cmis:document WHERE abc:int = ? AND abc:int2 = 123";
st = new QueryStatementImpl(session, query);
st.setNumber(1, 42);
assertEquals("SELECT * FROM cmis:document WHERE abc:int = 42 AND abc:int2 = 123", st.toQueryString());
// dateTime
query = "SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP ?";
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.clear();
cal.set(2012, 1, 2, 3, 4, 5);
st = new QueryStatementImpl(session, query);
st.setDateTime(1, cal);
assertEquals("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'",
st.toQueryString());
st = new QueryStatementImpl(session, query);
st.setDateTime(1, cal.getTimeInMillis());
assertEquals("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'",
st.toQueryString());
}