插入时出现SQLite错误

Gor*_*nHo 0 sqlite android

我试图将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 (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不知道为什么查询没有通过.还有谁?

干杯,

戈登

Bor*_*jev 5

您提供的不是有效的sqlite语法.SQLite在单指令中对多个插入有一定的支持,但它的工作方式略有不同.看到这里.

如何生成查询以及在您的问题中有时意味着什么 - 对于我来说,每次尝试这样的查询时都会出现错误.

像这样重写您的查询:

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 ?, ?, ?, ?, ?, ?, ?
Run Code Online (Sandbox Code Playgroud)