我正在尝试将android设备上的值插入到sqlite数据库中。
但是,有时会抛出以下错误:
android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO sensor_event (created_at, updated_at, type, x, y, z, time) VALUES (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)
不幸的是,我不知道为什么查询不能通过。还有其他人吗?
干杯,
戈登
发布于 2012-09-20 18:36:49
您提供的不是有效的sqlite语法。SQLite在某种程度上支持单指令中的多个插入,但它的实现方式略有不同。参见here。
你如何生成你的查询,以及你的问题有时意味着什么-对于我来说,每当你尝试这样的查询时,都会发生错误。
像这样重写你的查询:
INSERT INTO sensor_event
SELECT ? as created_at, ? as updated_at, ? as type, ? as x, ? as y, ? as z, ? as time
UNION SELECT ?, ?, ?, ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?, ?, ?, ?
发布于 2012-09-21 19:37:53
从版本3.7.11开始,SQLite允许复合insert语句
正如Boris Strandjev提到的那样,Android使用3.7.11,因为4.1版的早期版本将失败。
安卓版本中的SQLite版本:Version of SQLite used in Android?
https://stackoverflow.com/questions/12518653
复制