建议SQLite操作使用rawQuery方法
2015-07-23 18:47
465 查看
对于Android平台上的数据库而言使用了嵌入式越来越流行的SQLite,为了更好的跨平台我们推荐大家使用原始SQL语句直接操作,在代码和处理效率上都有不小的提高,不过要做好SQL语句异常处理。
下面我们说下rawQuery的好处,可以看到查询的代码直接使用SQL语句,通过性能实测效率比Android封装过的类要快不少,但不能配合一些
Adapter的使用,不过总体上在跨平台上很突出,下面为本地使用方法的伪代码,没有做任何构造和实例化,希望让项目经理知道rawSQL的优势在 Android平台上的使用。
SQLiteDatabase db;
String args[] = {id};
ContentValues cv = new ContentValues();
cv.put("android123", id);
Cursor c = db.rawQuery("SELECT * FROM table WHERE android123=?", args); 执行本地SQL语句查询
if (c.getCount() != 0) {
//dosomething
ContentValues cv = new ContentValues();
cv.put("android123","cwj");
db.insert("table", "android123", cv); //插入数据
String args[] = {id};
ContentValues cv2= new ContentValues();
cv2.put("android123", id);
db.delete("table", "android123=?", args); //删除数据
}
下面我们说下rawQuery的好处,可以看到查询的代码直接使用SQL语句,通过性能实测效率比Android封装过的类要快不少,但不能配合一些
Adapter的使用,不过总体上在跨平台上很突出,下面为本地使用方法的伪代码,没有做任何构造和实例化,希望让项目经理知道rawSQL的优势在 Android平台上的使用。
SQLiteDatabase db;
String args[] = {id};
ContentValues cv = new ContentValues();
cv.put("android123", id);
Cursor c = db.rawQuery("SELECT * FROM table WHERE android123=?", args); 执行本地SQL语句查询
if (c.getCount() != 0) {
//dosomething
ContentValues cv = new ContentValues();
cv.put("android123","cwj");
db.insert("table", "android123", cv); //插入数据
String args[] = {id};
ContentValues cv2= new ContentValues();
cv2.put("android123", id);
db.delete("table", "android123=?", args); //删除数据
}
相关文章推荐
- OC类 之 NSData NSDate NSSet NSNumber NSValue
- 多校2 1002 Buildings
- NSNumber,NSValue
- F - True Liars - poj1417(背包+并查集)
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
- OPEN(SAP) UI5 学习入门系列之一:扫盲与热身(上)
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
- iOS总结控件三(UIView)
- MongoVUE Group分组统计查询
- requireJS
- requireJS
- mongo vue的常用操作
- BUILD_BUG_ON
- 设置UIlabel的行高
- ocp 047-40 User OE, the owner of the ORDERS table, issues the following command:
- ifconfig: ioctl 0x8914 failed: Cannot assign requested address
- xcodebuild 生成ipa包
- android关于AlertDialog.Builder中setMessage不能换行问题的解决方法
- 获得UIView对应 的viewController
- 【RequireJS--API学习笔记】