Search in sources :

Example 1 with Condition

use of org.nutz.dao.Condition in project nutz by nutzam.

the class CndTest method test_order.

@Test
public void test_order() {
    Condition c = Cnd.orderBy().asc("id").desc("name").asc("age").desc("workingDay");
    String exp = "ORDER BY wid ASC, wname DESC, age ASC, days DESC";
    assertEquals(exp, c.toSql(en).trim());
}
Also used : Condition(org.nutz.dao.Condition) Test(org.junit.Test)

Example 2 with Condition

use of org.nutz.dao.Condition in project nutz by nutzam.

the class CndTest method test_like_in.

@Test
public void test_like_in() {
    int[] ages = { 4, 7, 9 };
    SqlExpression e = Cnd.exps("age", ">", 35).and("id", "<", 47);
    SqlExpression e2 = Cnd.exps("name", "\tLIKE ", "%t%").and("age", "IN  \n\r", ages).or(e);
    Condition c = Cnd.where("id", "=", 37).and(e).or(e2).asc("age").desc("id");
    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 3 with Condition

use of org.nutz.dao.Condition in project nutz by nutzam.

the class CndTest method test_obj_read_write.

/**
     * 序列化测试
     */
@Test
public void test_obj_read_write() {
    SqlExpression e2 = Cnd.exps("f2", "=", 1);
    SqlExpression e3 = Cnd.exps("f3", "=", 1);
    Condition c = Cnd.where(e2).andNot(e3);
    byte[] buf = Lang.toBytes(c);
    c = Lang.fromBytes(buf, Cnd.class);
    assertEquals(" WHERE (f2=1) AND NOT (f3=1)", c.toString());
}
Also used : Condition(org.nutz.dao.Condition) Cnd(org.nutz.dao.Cnd) SqlExpression(org.nutz.dao.util.cri.SqlExpression) Test(org.junit.Test)

Example 4 with Condition

use of org.nutz.dao.Condition in project nutz by nutzam.

the class CndTest method test_in_by_str_list.

@Test
public void test_in_by_str_list() {
    List<String> list = new ArrayList<String>();
    list.add("'A'");
    list.add("B");
    Condition c = Cnd.where("nm", "iN", list);
    String exp = "WHERE nm IN ('''A''','B')";
    assertEquals(exp, c.toSql(null).trim());
}
Also used : Condition(org.nutz.dao.Condition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Condition

use of org.nutz.dao.Condition in project nutz by nutzam.

the class CndTest method test_in_by_int_list.

@Test
public void test_in_by_int_list() {
    List<Integer> list = new ArrayList<Integer>();
    list.add(3);
    list.add(5);
    list.add(7);
    Condition c = Cnd.where("id", "iN", list);
    String exp = "WHERE id IN (3,5,7)";
    assertEquals(exp, c.toSql(null).trim());
}
Also used : Condition(org.nutz.dao.Condition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Condition (org.nutz.dao.Condition)16 SqlExpression (org.nutz.dao.util.cri.SqlExpression)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Cnd (org.nutz.dao.Cnd)1