【发布时间】:2013-04-17 00:49:39
【问题描述】:
我在将多个条目插入 Android SQLite 数据库时遇到问题。我用 db.execQuery() 像这样插入:
String insertString = "INSERT INTO coordinates
SELECT 0 AS _id, 5 AS associated_route_id, 38.88945 AS latidude, -77.034821 AS longitude
UNION SELECT 1, 5, 38.889671, -77.034912
UNION SELECT 2, 5, 38.890041, -77.035316"
database.execSQL(insertString);
我稍后会像这样使用相同的数据库:
String[] columns = new String[] { "latitude", "longitude" };
Cursor cursor = db.query("coordinates", columns,
"associated_route_id=5", null, null, null,
null);
cursor.moveToFirst();
if (cursor.getCount() == 0)
// No rows in cursor
我使用 db.insert(table, null, contentValues) 让它工作,但替换了插入以加快速度。
问题是光标是空的,这使得插入似乎不起作用。为什么它不起作用?
【问题讨论】:
-
你的问题是什么?
-
光标什么也不返回。
-
你能发布你的插入代码吗?您是使用 sql 脚本还是插入内容值?