gpt4 book ai didi

Android 游标列

转载 作者:行者123 更新时间:2023-11-29 20:53:16 29 4
gpt4 key购买 nike

可以安全地假设 Android 游标仅包含我请求的列,并以与它们在 select 语句中相同的顺序返回它们,即。 e.下面的代码会一直有效吗?

Cursor cursor = db.query("NAMES",
new String[] {"FIRSTNAME", "LASTNAME", "MOBILE"},
"ID = " + requestedId, null, null, null, null, null);

if (cursor.moveToFirst()) {
firstname = cursor.getString(0);
lastname = cursor.getString(1);
mobile = cursor.getString(2);
}

或者我应该坚持像下面那样显式获取列索引,因为 Android SQLite 可能会在 query() 返回的游标中添加一些辅助数据或更改列的顺序?

firstname = cursor.getString(cursor.getColumnIndex("FIRSTNAME"));
lastname = cursor.getString(cursor.getColumnIndex("LASTNAME"));
mobile = cursor.getString(cursor.getColumnIndex("MOBILE"));

最佳答案

Is is safe to assume that Android cursor only has the columns I requested and returns them in the same order as they are in the select statement, i. e. will the following code always work?

是的,它很安全。

在幕后,它只是 SQLiteQueryBuilder 进行愚蠢的字符串连接。您可以检查 source了解更多。

关于Android 游标列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28514035/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com