在Android飞速的发展中,就版本的一些语句逐渐被替代。在数据库语句中出现的占位符有可能会飘红,于是就有新的代替,如下:
旧版本(查询): Cursor cursor = db.rawQuery("select threadid,position from filedown where downpath=?", new String[]{path});
改进:
Cursor cursor = db.rawQuery("select threadid,position from filedown where downpath='"+path+"'",null);
旧版本(插入):
db.execSQL("insert into filedown(downpath,threadid,position)values(?, ?, ?)", new Object[]{path,entry.getKey(),entry.getValue()});
改进:
db.execSQL("insert into filedown(downpath,threadid,position)values('"+path+"', '"+entry.getKey()+"', '"+entry.getValue()+"')");
旧版本(更新):
db.execSQL(" update filedown set position = ? where downpath = ? and threadid = ?", new Object[]{entry.getValue(),path,entry.getKey()} );
改进:
db.execSQL(" update filedown set position = '"+entry.getValue()+"' where downpath = '"+path+"' and threadid = '"+entry.getKey()+"'");
旧版本(删除):
db.execSQL("delete from filedown where downpath=?", new Object[]{path});
改进:
db.execSQL("delete from filedown where downpath=' "+path+" '");