Search in sources :

Example 6 with SqlExpression

use of org.nutz.dao.util.cri.SqlExpression in project nutz by nutzam.

the class LamdaCndTest method test_like_in.

@Test
public void test_like_in() {
    int[] ages = { 4, 7, 9 };
    SqlExpression e = Cnd.exps(Worker::getAge, ">", 35).and(Worker::getId, "<", 47);
    SqlExpression e2 = Cnd.exps(Worker::getName, "\tLIKE ", "%t%").and(Worker::getAge, "IN  \n\r", ages).or(e);
    Condition c = Cnd.where(Worker::getId, "=", 37).and(e).or(e2).asc(Worker::getAge).desc(Worker::getId);
    String exp = "WHERE wid=37 AND (age>35 AND wid<47) OR (wname LIKE '%t%' AND age IN (4,7,9) OR (age>35 AND wid<47)) ORDER BY age ASC, wid DESC";
    assertEquals(exp, c.toSql(en).trim());
}
Also used : Condition(org.nutz.dao.Condition) SqlExpression(org.nutz.dao.util.cri.SqlExpression) Test(org.junit.Test)

Example 7 with SqlExpression

use of org.nutz.dao.util.cri.SqlExpression in project nutz by nutzam.

the class CndTest method test_not_sql_group.

@Test
public void test_not_sql_group() {
    SqlExpression e2 = Cnd.exps("f2", "=", 1);
    SqlExpression e3 = Cnd.exps("f3", "=", 1);
    Condition c = Cnd.where(e2).andNot(e3);
    assertEquals(" WHERE (f2=1) AND NOT (f3=1)", c.toString());
}
Also used : Condition(org.nutz.dao.Condition) SqlExpression(org.nutz.dao.util.cri.SqlExpression) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 SqlExpression (org.nutz.dao.util.cri.SqlExpression)7 Condition (org.nutz.dao.Condition)4 Cnd (org.nutz.dao.Cnd)2