我必须在我的 SQLite 数据库 和一些表中插入很多行 必须使用其他表的值将每一行的特定值转换为其他值。 实际上,我有这个功能运行良好:
public void myFunction( String tableName, String attrName, ContentValues currentVal ) {
SQLiteDatabase database = this.getReadableDatabase();
Cursor c = database.rawQuery("SELECT colName FROM "+tableName+" WHERE "+tableName+".otherColName = " + currentVal.getAsString(attrName), null);
Long realValue = null;
if( c.moveToFirst() ) {
realValue = c.getLong(0);
}
if( c != null ) c.close();
currentVal.put( attrName, realValue );
}
但是,因为这部分,这真的很耗时:
if( c.moveToFirst() ) {
realValue = c.getLong(0);
}
所以我想知道是否有一种方法可以像这样直接在 ContantValue 的值中设置查询:
currentVal.put( attrName, "SELECT colName FROM "+tableName+" WHERE "+tableName+".otherColName = " + currentVal.getAsString(attrName));
并且查询将与插入查询同时执行以替换值。
先谢谢你!
最佳答案
不,ContentValues
只是数据 HashMap 的包装器。可以尝试使用索引来加速查询。
关于android - 在 ContentValues 中查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34786833/