用sqlite的感受:
sqlite和mysql很像,如果你对mysql有一定的经验,那么里面的sql写法也类似,比如常见的limit用法,mysql里面主要用limite分页,但是数据多了不建议,很影响效率。
sqlite常用用法函数总结如下:
query:
//need try catch and db.close();
try{
cursor = db.rawQuery("select * from "+MdmDbHelper.TABLE_NAME_AUTHORIZATION+" where apply_id=? and status=? order by id desc");
if (cursor != null) {
// 循环遍历cursor
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("id"));
}
} catch() {
} finally {
if (db != null) {
db.close();
}
}
insert:
ContentValuse valuse = new ContentValues();
values.put("reason",reason);
db.insert(tableName,null,valuse);
update:
ContentValuse valuse = new ContentValues();
values.put("reason",reason);
db.update(tableName,values,"id=?",new String[]{id});
delete:
db.delete("tableName",null,null);
删除最新的多少条数据:
String sql = "delete from "+MdmDbHelper.TABLE_NAME_AUTHORIZATION+" where id <= (select max(id) - "+max+" from authorization)";
db.exesql(sql);
显示最新的多少条数据,但是不删除之前的数据:
cursor = db.rawQuery("select * from "+MdmDbHelper.TABLE_NAME_AUTHORIZATION+" where apply_id=? and status != '0' order by id desc limit "+count,new String[]{id});