虚拟查询(无实体类查询)

默认情况下,QuickDAO会扫描用户指定的实体类包然后映射实体类信息到数据表再来进行查询.

但是QuickDAO也实现了无需扫描实体类实现对数据库的增删查改.

假设数据库里存在如下表person表

idusernamepasswordtype
1tom1234561
2jack1234562

简单查询

  1. JSONObject person = dao.fetch("person","username","tom");
  2. JSONArray person = dao.fetchList("person","password","123456");

复杂查询

  1. //select id,username,password,type from person where username = 'tom'
  2. JSONArray array = dao.query("person")
  3. .addQuery("username","tom")
  4. .addColumn("id","username","password","type")
  5. .execute()
  6. .getArray();

使用无实体类进行查询操作时必须调用addColumn方法指定要返回的列信息

插入

  1. //insert into person(username,password) value('tony','123456')
  2. int effect = dao.query("person")
  3. .addInsert("username","tony")
  4. .addInsert("password","123456")
  5. .execute()
  6. .insert();

更新

  1. //update person set password = '654321' where username = 'tony'
  2. int effect = dao.query("person")
  3. .addUpdate("password","654321")
  4. .addQuery("username","tony")
  5. .execute()
  6. .update();

删除

  1. //delete from person where username = 'tony'
  2. int effect = dao.query("person")
  3. .addQuery("username","tony")
  4. .execute()
  5. .delete();

dual查询

dual表在许多数据库产品里面作为虚表存在,QuickDAO也支持使用dual表.

  1. //select '1' id from dual
  2. JSONArray array = dao.query("dual")
  3. .addColumn("'1' id")
  4. .execute()
  5. .getArray();