SQlite的数据库查询
来源:互联网 发布:北方医疗大数据 编辑:程序博客网 时间:2024/04/30 08:04
多表查询 + 数据字典查询点击打开链接
数据字典
1 select b.codedesc,a.[branum],d.codedesc,c.codedesc 2 from BI_VEHICLE a 3 join T_PF_DATADICT b on b.fieldname = 'BRAPREFIX' and a.braprefix = b.code 4 join T_PF_DATADICT c on c.fieldname = 'VECTYPE' and a.vectype = c.code 5 join T_PF_DATADICT d on d.fieldname = 'TRASTATE' and a.trastate = d.code
把多个字段结果合成一个字段
1 select b.codedesc as _id ,2 a.[casecarnum], 3 a.[credate]||" "||a.[cretime] as credate,4 a.[edidate]||" "||a.[editime] as edidate ,5 a.[pecdate]||" "||a.[pectime] as pecdate,6 a.[casereason], a.[client_status], c.[codedesc] as status7 from cp_casinfo a 8 join T_PF_DATADICT b on b.fieldname = 'BRAPREFIX' and a.casecarprefix = b.code 9 join T_PF_DATADICT c on c.[fieldname] = 'STATUS' and a.[status] = c.[code] and c.tablename = 'CP_CASEINFO'
原字段
合并后的字段
----------------------------------------------------------------------------------------------------------------------------------------------
分页查询数据
1 /** 2 * 分页获取记录 3 * @param offset 跳过前面多少条记录 4 * @param maxResult 每页获取多少条记录 5 * @return 6 */ 7 public List<Person> getScrollData(int offset, int maxResult) 8 { 9 10 List<Person> persons = new ArrayList<Person>();11 SQLiteDatabase db = dbOpenHelper.getReadableDatabase();12 Cursor cursor = db.rawQuery("select * from person order by personid asc limit ?,?",13 new String[]{String.valueOf(offset), String.valueOf(maxResult)});14 15 while(cursor.moveToNext())16 {17 int personid = cursor.getInt(cursor.getColumnIndex("personid"));18 int amount = cursor.getInt(cursor.getColumnIndex("amount"));19 String name = cursor.getString(cursor.getColumnIndex("name"));20 String phone = cursor.getString(cursor.getColumnIndex("phone"));21 persons.add(new Person(personid, name, phone, amount));22 }23 cursor.close();24 return persons;25 }
数据库的增删改查
1 //方法一 2 ContentValues cv = new ContentValues(); 3 cv.put("CLASS_CODE", clazz.getClassCode()); 4 cv.put("CLASS_NAME", clazz.getClassName()); 5 //返回自增列的 ID 值 6 long lResult = sdb.insert("tableName", null, cv); 7 8 9 //方法二10 //11 SQLiteDatabase db = dbOpenHelper.getWritableDatabase();12 db.execSQL("insert into person(name, phone, amount) values(?,?,?)",13 new Object[]{person.getName(), person.getPhone(), person.getAmount()});
1 //方法一 2 int iResult = sdb.delete(DBConstant.TN_CLASS, "ID=?", new String[]{String.valueOf(clazz.getId())}); 3 4 //方法二 5 /** 6 * 删除记录 7 * @param id 记录ID 8 */ 9 public void delete(Integer id){10 SQLiteDatabase db = dbOpenHelper.getWritableDatabase();11 db.execSQL("delete from person where personid=?", new Object[]{id});12 }
1 //方法一 2 ContentValues cv = new ContentValues(); 3 cv.put("CLASS_CODE", clazz.getClassCode()); 4 cv.put("CLASS_NAME", clazz.getClassName()); 5 int iResult = sdb.update(DBConstant.TN_CLASS, cv, "ID=?", new String[]{String.valueOf(clazz.getId())}); 6 7 /** 8 * 更新记录 9 * @param person10 */11 public void update(Person person){12 SQLiteDatabase db = dbOpenHelper.getWritableDatabase();13 db.execSQL("update person set name=?,phone=?,amount=? where personid=?",14 new Object[]{person.getName(), person.getPhone(), person.getAmount(), person.getId()});15 }
1 /** 2 * 查询记录 3 * @param id 记录ID 4 * @return 5 */ 6 public Person find(Integer id){ 7 SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); 8 Cursor cursor = db.rawQuery("select * from person where personid=?", new String[]{id.toString()}); 9 if(cursor.moveToFirst()){10 int personid = cursor.getInt(cursor.getColumnIndex("personid"));11 int amount = cursor.getInt(cursor.getColumnIndex("amount"));12 String name = cursor.getString(cursor.getColumnIndex("name"));13 String phone = cursor.getString(cursor.getColumnIndex("phone"));14 return new Person(personid, name, phone, amount);15 }16 cursor.close();17 return null;18 }
0 0
- SQlite的数据库查询
- SQLite数据库的分页查询
- Android SQLite数据库查询 cursor的使用
- android sqlite 查询数据库的总条数
- SQLite数据库查询优化
- SQLite数据库查询优化
- SQLite数据库查询优化
- python查询sqlite数据库
- SQLite数据库查询优化
- sqlite查询数据库
- SQLite 跨数据库查询
- 数据库查询命令sqlite
- 通讯录-数据库SQLite的存储 数据库语言的模糊查询
- SQLite数据库查询优化方案
- sqlite数据库简单查询命令
- sqlite数据库查询表名
- SQLite数据库 android 查询语句
- ionic2数据库SQLite查询操作
- 数据结构 前言
- C++基础---面向对象建模方法
- 2015.9.13
- 操作系统内核Hack:(一)实验环境搭建
- 彩票系统 35选7
- SQlite的数据库查询
- Android sendevent/getevent 用法
- 话说Mac终端下 遇到的千奇百怪的报错及解决方法
- 分布式缓存GemFire架构介绍
- poj 3318 随机(矩阵相乘判断)
- Gradle User Guide(1)
- 安装mysql
- 多巴胺对于情绪的影响 理智与感性
- iOS的AssetsLibrary框架解读与应用